學習三十二
阿新 • • 發佈:2018-03-27
linux學習八周一次課(3月26日)
10.23 linux任務計劃cron
10.24 chkconfig工具
10.25 systemd管理服務
10.26 unit介紹
10.27 target介紹
擴展
10.23 linux任務計劃cron
10.24 chkconfig工具
10.25 systemd管理服務
10.26 unit介紹
10.27 target介紹
擴展
- 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
linux任務計劃cron
我們在此處查看一下 crontab
腳本的格式為
0 3 /bin/bash /usr/local/bin/123.sh >>/tmp/123.log 2>>/tmp/123.log
此處的意思為每天淩晨三點把去執行 下面這個命令
bin/bash 加上腳本名字 輸出到123.log裏 2後面表示錯誤的也記錄進該文件>直接添加 >>追加重定向
0 3 時間1 -10(一到十月) /2(被2整除的月份) 2,5(指定星期)
systemctl start crond.service (啟動服務才能生效)
檢查服務是否生效 ps aux |grep crond
systemctl status crond 也可以查看命令狀態
systemctl stop crond 關閉命令,systemctl status crond查看命令狀態
有時候寫任務計劃沒有執行 有可能是因為腳本裏面使用的命令 沒有使用絕對路徑,或者是把命令加入到PATH裏面去
crontab -l 查看當前任務
ls /var/spool/cron/root 任務目錄 可以把任務目錄直接備份,
-u指定用戶
chkconfig工具
chkconfig --list列出當前的服務
此處可以看出7之前都是用sysv的管理模式,7用的是systemd服務
chkconfig 只能看到兩個了
在 init.d裏面可以看到別的服務
此處的 0 - 6分別表示的是 0.是關機狀態 1.是單用戶模式 2.比3少了nfs(一種網絡服務)服務 3.是多用戶模式,不帶圖形 4.是保留狀態5.是多用戶帶圖形模式 6.重啟
chkconfig --level 35 network off
關閉網絡35服務
add 可以添加服務
chkconfig --add 123
添加的條件是只有服務存在於init.d目錄下的時候才能添加到服務列表裏面去
del是刪除
systemd管理服務
在centos7裏面之後是使用的systemd服務
首先根據系統的提示要使用systemctl list-units -files查看服務 太復雜
systemctl list-units --all --type=service此處會查看service的比較詳細
unit介紹
什麽是unit
unit的相關命令
target介紹
systemctl list-unit-files --type=target查看系統的target
systemctl list-dependencies multi-user.target //查看指定target下面有哪些unit
學習三十二