擴充:
1. anacron:
<a href="http://blog.csdn.net/strikers1982/article/details/4787226">http://blog.csdn.net/strikers1982/article/details/4787226</a>
2. xinetd服(預設沒安裝這個服務,需要yum install xinetd安裝):
<a href="http://blog.sina.com.cn/s/blog_465bbe6b010000vi.html">http://blog.sina.com.cn/s/blog_465bbe6b010000vi.html</a>
3. systemd自定義啟動腳本:
<a href="http://www.jb51.net/article/100457.htm">http://www.jb51.net/article/100457.htm</a>
10.23 linux任務計劃cron
任務計劃:我們可能淩晨備份資料,重新開機服務等等,這樣在某個時間自動的執行腳本或指令,
1. 檢視 任務計劃配置檔案 (寫入格式) :
[root@hao-001 ~]# cat /etc/crontab
2. 編寫 任務計劃 :
[root@hao-001 ~]# crontab -e
i 進入編輯模式
*表示全部,
每天的淩晨三點都執行,不限定日月周 執行12.sh腳本, 正确輸出日志12.log 錯誤輸出日志21.log
0分 3時 * * * /bin/bash /usr/local/sbin/12.sh >>/tmp/12.log 2>>/tmp/21.log
例1:
12分 14時 1号-20号 每隔2個月 星期1-星期6 執行指令 執行的腳本 >>正确輸出日志路徑 2>>錯誤輸出日志路徑
12 14 1-20 */2 1-6 /bin/bash /usr/local/sbin/123.sh >>/tmp/123.log 2>>/tmp/321.log
例2:
格式: 分 時 日 月 周 執行指令 執行的腳本 >>正确輸出日志路徑 2>>錯誤輸出日志路徑
格式: 分 時 日 月 周 /bin/bash /usr/local/sbin/123.sh >>/tmp/1234.log 2>>/tmp/4321.log
詳解:
* 表示(分/時/日/月/周)全部範圍 注意: 執行指令要填寫絕對路徑!!!
分範圍:0-59,
時範圍:0-23,
日範圍:1-31,
月範圍:1-12,
周範圍:0-6(0表示星期天,7也表示星期天)
可用格式: 1-5(表示一個範圍1到5)
可用格式: 1,2,3(表示1或2或3) 比如:星期一,星期二,星期三
可用格式: */2(表示被2整除的數字)比如小時,每隔2小時; 比如月,雙月,被2整除的月,每隔兩個月
3. 啟動 crond程序 :
[root@hao-001 ~]# systemctl start crond
4. 搜尋 crond程序是否啟動 ?
[root@hao-001 ~]# ps aux |grep crond
5. 檢視 crond程序狀态(判斷是否啟動?圖中綠色表示啟動了) :
[root@hao-001 ~]# systemctl status crond
6. 關閉 crond程序 :
[root@hao-001 ~]# systemctl stop crond
7. 列出 任務計劃 :
[root@hao-001 ~]# crontab -l
8. 列出 指定使用者任務計劃 :
[root@hao-001 ~]# crontab -u root -l
9. 檢視 任務計劃存放目錄(檔案是使用者名命名檔案) :
(備份使用者的任務計劃,直接備份這個cron目錄即可!!!)
[root@hao-001 ~]# ls /var/spool/cron/
10. 删除 任務計劃 :
[root@hao-001 ~]# crontab -r
10.24 chkconfig工具(服務)
1. 列出 目前系統使用chkconfig工具的服務有哪些?運作級 是什麼?
[root@hao-001 ~]# chkconfig --list
注意:2級别 3級别 4級别 5級别 根據自己需求,可開/可關
注意:0級别 1級别 6級别 必須關
0級别 關機狀态
1級别 單使用者模式
2級别 多使用者模式(帶nfs服務)
3級别 多使用者模式(不帶圖形,沒有nff服務)
4級别 保留狀态(暫時沒用)
5級别 多使用者模式(帶圖形)
6級别 重新開機
2. 檢視 啟動腳本的服務(檔案腳本) :
[root@hao-001 ~]# ls /etc/init.d
3. 關閉 network服務 3級别 :
[root@hao-001 ~]# chkconfig --level 3 network off
4. 關閉 network服務 2級别3級别4級别5級别 :
[root@hao-001 ~]# chkconfig --level 2345 network off
5. 開啟 network服務 2級别3級别4級别5級别 :
[root@hao-001 ~]# chkconfig --level 2345 network on
6. 檢視 指定的network服務 運作級别 :
[root@hao-001 ~]# chkconfig --list network
7.0 進入 cd /etc/init.d目錄下:
[root@hao-001 ~]# cd /etc/init.d
7.1 建立 123腳本(自定義),到/etc/init.d目錄下:
[root@hao-001 ~]# cp network 123
7.2 新增 自定義服務 到 chkconfig服務清單下 :
[root@hao-001 ~]# chkconfig --add 123
8. 删除 自定義服務 :
[root@hao-001 ~]# chkconfig --del network
注意:新增加的自定義服務腳本,按格式,添加到/etc/init.d/目錄下
10.25 systemd管理服務
1. systemd列出所有units服務,類型為servie :
[root@hao-001 ~]# systemctl list-units --all --type=service
2. 未激活狀态的active不再列出 :
[root@hao-001 ~]# systemctl list-units --type=service
3. crond服務 開機不啟動 :
[root@hao-001 ~]# systemctl disable crond
4. crond服務 開機啟動 :
[root@hao-001 ~]# systemctl enable crond.service
5. 檢查 crond服務 是否開機啟動 ?
[root@hao-001 ~]# systemctl is-enabled crond
6. 檢視 crond服務狀态 :
[root@hao-001 ~]# systemctl status crond.service
7. 停止 crond服務 :
8. 啟動 crond服務 :
9. 重新開機 crond服務 :
[root@hao-001 ~]# systemctl restart crond
10.26 unit介紹
1. 列出 系統所有unit :
[root@hao-001 ~]# ls /usr/lib/systemd/system
unit分為以下類型:
service 系統服務
target 多個unit組成的組
device 硬體裝置
mount 檔案系統挂載點
automount 自動挂載點
path 檔案或路徑
scope 不是由systemd啟動的外部程序
slice 程序組
snapshot systemd快照
socket 程序間通信套接字
swap swap檔案
timer 定時器
unit相關的指令
1. 列出 正在運作的unit :
[root@hao-001 ~]# systemctl list-units
2. 列出 所有的(包括失敗的或者inactive的) :
[root@hao-001 ~]# systemctl list-units --all
3. 指定列出 狀态為inactive的unit :
[root@hao-001 ~]# systemctl list-units --all --state=inactive
4. 指定列出 狀态為active的service :
[root@hao-001 ~]# systemctl list-units --type=service
5. 指定檢視 crond.service服務,是否為active ?
[root@hao-001 ~]# systemctl is-active crond.service
6. 指定檢視 crond.service服務,是否為enabled ?
[root@hao-001 ~]# systemctl is-enabled crond.service
10.27 target介紹
•系統為了友善管理,用target管理unit
1. 列出 系統所有target :
[root@hao-001 ~]# systemctl list-unit-files --type=target
2. 檢視 指定target下面有哪些unit :
[root@hao-001 ~]# systemctl list-dependencies multi-user.target
3. 檢視 系統預設的target :
[root@hao-001 ~]# systemctl get-default

4. 設定(更改) 預設的target:
[root@hao-001 ~]# systemctl set-default multi-user.target
•一個service 是一種類型的unit
• target是多個unit組成的
• 一個target裡面,包含了多個(若幹)service
5. 檢視 sshd.service的service,屬于哪個target ?
[root@hao-001 ~]# cat /usr/lib/systemd/system/sshd.service

本文轉自 主内安詳 51CTO部落格,原文連結:http://blog.51cto.com/zhuneianxiang/2066488,如需轉載請自行聯系原作者