crontab、chkconfig、systemd、unit、targ
10.23 linux任務計劃cron
# cat /etc/crontab
liunx下的任務計劃配置文件
- crontab -u、-e、-l、-r
- 格式:分 時 日 月 周 user command
- 分範圍0-59,時範圍0-23,日範文:1-31,月範圍:1-12,星期分爲:0-6(sunday=0 or 7)
# crontab -e
進入到任務計劃編輯界面
- 0 3 * * * /bin/bash /usr/local/sbin/123.sh >>/tmp/123.log 2>>/tmp/123.log //每一個星期,每一個月的天天的3點執行命令
- 0 3 1-10 */2 2,5 /bin/bash /usr/local/sbin/123.sh >>/tmp/123.log 2>>/tmp/123.log //每週二週五,雙數月份的前10天的3點,執行任務
# sytemctl start crond
啓動服務# systemctl stop crond
//關閉服務
# ps aux | grep cron
查看是否有此進程
# systemctl status crond
查看狀態,Actice綠色啓動該
- 計劃在/var/spool/cron/root(最後是以用戶名命名的文件)
# cront -l
//列出信息
# cront -e
//編輯
# cront -r
//刪除
# cront -u root -l
//查看指定用戶的計劃
10.24 Linux系統服務管理-chkconfig工具
# chkconfig --list
//當前系統中全部服務
# ls /etc/init.d/
# chkconfig network off
# chkconfig --level 3 network off
//指定某個級別的服務關閉
# chkconfig --level 345 network off
//指定多個級別的某個服務關閉
# chkconfig --del network
# chkconfig --add network
- 將腳本放到/etc/init.d/下再將服務add就能夠將腳本在某幾個級別運行的時候執行了
10.25 systemd管理服務
# systemctl list-units --all--type=service
- 幾個經常使用的服務相關的命令
#systemctl enable crond.service
//讓服務開機啓動
# systemctl disable crond
//讓服務開機不啓動
# systemctl status crod
//查看狀態
# systemctl stop crond
//中止服務
# systemctl start crond
//啓動服務
# systemctl restart crond
//重啓服務
# systemctl is-enabled crond
//檢查服務是否開機啓動
10.26 unit介紹
- ls /usr/lib/systemd/system //系統全部unit,分爲如下類型:
- service 系統服務
- target 多個unit組成的組
- device 硬件設備
- mount 文件系統掛載點
- automount 自動掛載點
- path 文件或路徑
- scope 不是有systemd啓動的外部進程
- slice進程組
- snapshot systemd快照
- socket 進程間通訊套接字
- swap swap文件
- timer 定時器
10.27 target介紹
- 系統爲了方便管理用target來管理unit
- systemctl list-unit-files --type=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】部分
擴展
- anacron http://blog.csdn.net/strikers1982/article/details/4787226
- xinetd服(默認機器沒有安裝這個服務,須要yum install xinetd安裝) http://blog.sina.com.cn/s/blog_465bbe6b010000vi.html
- systemd自定義啓動腳本http://www.jb51.net/article/100457.htm
歡迎關注本站公眾號,獲取更多信息