10.23cron10.24chkconfig工具10.25systemd管理服务10.26unit
擴展:
1.?anacron:
http://blog.csdn.net/strikers1982/article/details/4787226
2. xinetd服(默認沒安裝這個服務(wù),需要yum?install?xinetd安裝):
http://blog.sina.com.cn/s/blog_465bbe6b010000vi.html
3.?systemd自定義啟動腳本:??
http://www.jb51.net/article/100457.htm
10.23?linux任務(wù)計劃cron
任務(wù)計劃:我們可能凌晨備份數(shù)據(jù),重啟服務(wù)等等,這樣在某個時間自動的執(zhí)行腳本或命令,
1.?查看?任務(wù)計劃配置文件?(寫入格式)?:
[root@hao-001 ~]#?cat /etc/crontab
2.?編寫?任務(wù)計劃?:
[root@hao-001 ~]#?crontab -e
i?進入編輯模式
*表示全部,
每天的凌晨三點都執(zhí)行,不限定日月周 ?執(zhí)行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 ??執(zhí)行命令??執(zhí)行的腳本 ?>>正確輸出日志路徑 ?2>>錯誤輸出日志路徑
12 ?14 ?1-20 ?*/2 ? 1-6 ?/bin/bash?/usr/local/sbin/123.sh?>>/tmp/123.log?2>>/tmp/321.log
例2:
格式:?分 時 日 月 周?執(zhí)行命令??執(zhí)行的腳本 ?>>正確輸出日志路徑 ?2>>錯誤輸出日志路徑
格式:?分 時 日 月 周?/bin/bash??/usr/local/sbin/123.sh?>>/tmp/1234.log??2>>/tmp/4321.log
詳解:
* ?表示(分/時/日/月/周)全部范圍 ? 注意: 執(zhí)行命令要填寫絕對路徑!!!
分范圍:0-59,
時范圍:0-23,
日范圍:1-31,
月范圍:1-12,
周范圍:0-6(0表示星期天,7也表示星期天)
可用格式: ?1-5(表示一個范圍1到5)
可用格式: ?1,2,3(表示1或2或3) ?比如:星期一,星期二,星期三
可用格式: ?*/2(表示被2整除的數(shù)字)比如小時,每隔2小時;?比如月,雙月,被2整除的月,每隔兩個月
3.?啟動?crond進程 :
[root@hao-001 ~]#?systemctl start?crond
4.?搜索?crond進程是否啟動??
[root@hao-001 ~]#?ps aux |grep?crond
5.?查看?crond進程狀態(tài)(判斷是否啟動?圖中綠色表示啟動了) :
[root@hao-001 ~]#?systemctl status?crond
6.?關(guān)閉?crond進程 :
[root@hao-001 ~]#?systemctl stop?crond
7.?列出?任務(wù)計劃?:
[root@hao-001 ~]#?crontab -l
8.?列出?指定用戶任務(wù)計劃?:
[root@hao-001 ~]#?crontab -u?root?-l
9.?查看?任務(wù)計劃存放目錄(文件是用戶名命名文件) :
(備份用戶的任務(wù)計劃,直接備份這個cron目錄即可!!!)
[root@hao-001 ~]#?ls /var/spool/cron/
10.?刪除?任務(wù)計劃?:
[root@hao-001 ~]#?crontab -r
10.24?chkconfig工具(服務(wù))
1.?列出?當(dāng)前系統(tǒng)使用chkconfig工具的服務(wù)有哪些?運行級?是什么?
[root@hao-001 ~]#?chkconfig --list
注意:2級別??3級別??4級別??5級別 根據(jù)自己需求,可開/可關(guān)
注意:0級別?1級別?6級別??必須關(guān)
0級別 ? 關(guān)機狀態(tài)
1級別 ? 單用戶模式
2級別 ? 多用戶模式(帶nfs服務(wù))
3級別 ? 多用戶模式(不帶圖形,沒有nff服務(wù))
4級別 ? 保留狀態(tài)(暫時沒用)
5級別 ? 多用戶模式(帶圖形)
6級別 ? 重啟
2.?查看?啟動腳本的服務(wù)(文件腳本) :
[root@hao-001 ~]#?ls /etc/init.d
3.?關(guān)閉?network服務(wù)?3級別 :
[root@hao-001 ~]#?chkconfig --level?3?network?off
4.?關(guān)閉?network服務(wù)?2級別3級別4級別5級別 :
[root@hao-001 ~]#?chkconfig --level?2345?network?off
5.?開啟?network服務(wù)?2級別3級別4級別5級別 :
[root@hao-001 ~]#?chkconfig --level?2345?network?on
6.?查看?指定的network服務(wù) 運行級別 :
[root@hao-001 ~]#?chkconfig --list?network
7.0?進入?cd /etc/init.d目錄下:
[root@hao-001 ~]#?cd /etc/init.d
7.1?創(chuàng)建?123腳本(自定義),到/etc/init.d目錄下:
[root@hao-001 ~]#?cp?network?123
[root@hao-001 ~]#?chkconfig --list
7.2?新增?自定義服務(wù)?到?chkconfig服務(wù)列表下 :
[root@hao-001 ~]#?chkconfig --add?123
[root@hao-001 ~]#?chkconfig --list
8.?刪除?自定義服務(wù)?:
[root@hao-001 ~]#?chkconfig --del?network
注意:新增加的自定義服務(wù)腳本,按格式,添加到/etc/init.d/目錄下
10.25?systemd管理服務(wù)
1.?systemd列出所有units服務(wù),類型為servie?:
[root@hao-001 ~]#?systemctl list-units --all --type=service
2.?未激活狀態(tài)的active不再列出?:
[root@hao-001 ~]#?systemctl list-units ?--type=service
3.?crond服務(wù)?開機不啟動?:
[root@hao-001 ~]#?systemctl disable?crond
4.?crond服務(wù)?開機啟動?:
[root@hao-001 ~]#?systemctl enable?crond.service
5.?檢查?crond服務(wù)?是否開機啟動??
[root@hao-001 ~]#?systemctl is-enabled?crond
6.?查看?crond服務(wù)狀態(tài) :
[root@hao-001 ~]#?systemctl status?crond.service
7.?停止?crond服務(wù) :
[root@hao-001 ~]#?systemctl stop?crond
8.?啟動?crond服務(wù) :
[root@hao-001 ~]#?systemctl start?crond
9.?重啟?crond服務(wù) :
[root@hao-001 ~]#?systemctl restart?crond
10.26?unit介紹
1.?列出?系統(tǒng)所有unit?:
[root@hao-001 ~]#?ls /usr/lib/systemd/system
unit分為以下類型:
service ?系統(tǒng)服務(wù)
target?? ?多個unit組成的組
device ??硬件設(shè)備
mount ??文件系統(tǒng)掛載點
automount ??自動掛載點
path ??文件或路徑
scope ??不是由systemd啟動的外部進程
slice ??進程組
snapshot?? systemd快照
socket ??進程間通信套接字
swap? ?swap文件
timer?? ?定時器
unit相關(guān)的命令
1.?列出?正在運行的unit?:
[root@hao-001 ~]#?systemctl list-units ?
2.?列出?所有的(包括失敗的或者inactive的) :
[root@hao-001 ~]#?systemctl list-units --all ?
3.?指定列出?狀態(tài)為inactive的unit?:
[root@hao-001 ~]#?systemctl list-units --all --state=inactive ?
4.?指定列出?狀態(tài)為active的service?:
[root@hao-001 ~]#?systemctl list-units --type=service ???
5.?指定查看?crond.service服務(wù),是否為active??
[root@hao-001 ~]#?systemctl is-active?crond.service ?
6.?指定查看?crond.service服務(wù),是否為enabled??
[root@hao-001 ~]#?systemctl is-enabled?crond.service ?
10.27?target介紹
?系統(tǒng)為了方便管理,用target管理unit
1.?列出?系統(tǒng)所有target?:
[root@hao-001 ~]#?systemctl list-unit-files --type=target
2.?查看?指定target下面有哪些unit?:
[root@hao-001 ~]#?systemctl list-dependencies multi-user.target
3.?查看?系統(tǒng)默認的target?:
[root@hao-001 ~]#?systemctl get-default
4.?設(shè)置(更改)?默認的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
本文轉(zhuǎn)自 主內(nèi)安詳 51CTO博客,原文鏈接:http://blog.51cto.com/zhuneianxiang/2066488,如需轉(zhuǎn)載請自行聯(lián)系原作者
總結(jié)
以上是生活随笔為你收集整理的10.23cron10.24chkconfig工具10.25systemd管理服务10.26unit的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: JMM和happens-before原则
- 下一篇: Python3 django2.0 字段