linux任務計劃, chkconfig工具,systemd管理服務, unit介紹,target介紹

linux任務計劃:

一.  Crontab 介紹html

crontab命令的功能是在必定的時間間隔調度一些命令的執行。linux

二.查看/etc/crontab文件ssh

vi  /etc/crontab工具

三.文件/etc/crontab中每行任務的描述格式以下:spa

minute hour day month dayofweek command.net

  minute - 從0到59的整數 
    hour - 從0到23的整數 
    day - 從1到31的整數 (必須是指定月份的有效日期)
    month - 從1到12的整數 (或如Jan或Feb簡寫的月份)
    dayofweek - 從0到7的整數,0或7用來描述週日 (或用Sun或Mon簡寫來表示)
    command - 須要執行的命令(可用as ls /proc >> /tmp/proc或 執行自定義腳本的命令)rest

    root表示以root用戶身份來運行
    run-parts表示後面跟着的是一個文件夾,要執行的是該文件夾下的全部腳本htm

    對於以上各語句,星號(*)表示全部可用的值。例如*在指代month時表示每個月執行(須要符合其餘限制條件)該命令。 
    整數間的連字號(-)表示整數列,例如1-4意思是整數1,2,3,4  (範圍)blog

指定數值由逗號分開。如:3,4,6,8表示這四個指定整數。(指定某幾個數字)crontab

符號「/」指定步進設置。「/<interger>」表示步進值。如0-59/2定義每兩分鐘執行一次。步進值也可用星號表示。如*/3用來運行每三個月份運行指定任務。

以「#」開頭的爲註釋行,不會被執行。

4.範圍

可用格式1-5表示一個範圍1到5
可用格式1,2,3表示1或者2或者3
可用格式*/2表示被2整除的數字,好比小時,那就是每隔2小時

crontab -u、-e、-l、-r    編輯須要配置的文件  -l=查詢任務計劃   -r=刪除計劃    -u=指定用戶     -e=進入編輯模式

5.啓動服務

sbin/service crond start //啓動服務       =    systemctl start crond 
/sbin/service crond stop //關閉服務      =    systemctl stop crond
/sbin/service crond restart //重啓服務   =    systemctl  restart crond
/sbin/service crond reload //從新載入配置

 

 chkconfig工具:

chkconfig --list    查看系統服務

chkconfig --level 3network off    指定某個服務在開機系統關閉或者開啓  off=關閉 on=開啓

chkconfig --add 123   把腳本添加到系統服務裏面去

首先,把腳本添加到 /etc/init.d/ 目錄裏面去,而後就能夠添加服務了。(被添加的服務必須是一個腳本)

chkconfig --del    刪除系統服務

 

 

systemd系統服務管理:

systemctl list-units --all --type=service    列出系統全部服務

systemctl enable crond.service //讓服務開機啓動     crond =服務的名稱
systemctl disable crond //不讓開機啓動
systemctl status crond //查看狀態
systemctl stop crond //中止服務
systemctl start crond //啓動服務
systemctl restart crond //重啓服務
systemctl is-enabled crond //檢查服務是否開機啓動

 

unit介紹:

unit相關的命令
 systemctl list-units //列出正在運行的unit
 systemctl list-units --all //列出全部,包括失敗的或者inactive的
 systemctl list-units --all --state=inactive //列出inactive的unit    (指定狀態)
 systemctl list-units --type=service//列出狀態爲active的service
 systemctl is-active crond.service //查看某個服務是否爲active

 

 

target介紹:

系統爲了方便管理用target來管理unit
 systemctl list-unit-files --type=target    列出系統下的target
 systemctl list-dependencies multi-user.target //查看指定target下面有哪些unit
 systemctl get-default //查看系統默認的target
 systemctl set-default multi-user.target
 一個service屬於一種類型的unit
 多個unit組成了一個target
 一個target裏面包含了多個service
 cat /usr/lib/systemd/system/sshd.service //看[install]部分

 

 

擴展


1. anacron  http://blog.csdn.net/strikers1982/article/details/4787226

2. xinetd服(默認機器沒有安裝這個服務,須要yum install xinetd安裝)   http://blog.sina.com.cn/s/blog_465bbe6b010000vi.html

3. systemd自定義啓動腳本  http://www.jb51.net/article/100457.htm

相關文章
相關標籤/搜索