crontab、chkconfig、systemd、unit、targ

10.23 linux任務計劃cron

  1. # cat /etc/crontab liunx下的任務計劃配置文件
  2. crontab -u、-e、-l、-r
  3. 格式:分 時 日 月 周 user command
  4. 分範圍0-59,時範圍0-23,日範文:1-31,月範圍:1-12,星期分爲:0-6(sunday=0 or 7)
  5. # crontab -e進入到任務計劃編輯界面
  6. 0 3 * * * /bin/bash /usr/local/sbin/123.sh >>/tmp/123.log 2>>/tmp/123.log //每一個星期,每一個月的天天的3點執行命令
  7. 0 3 1-10 */2 2,5 /bin/bash /usr/local/sbin/123.sh >>/tmp/123.log 2>>/tmp/123.log //每週二週五,雙數月份的前10天的3點,執行任務
  8. # sytemctl start crond 啓動服務# systemctl stop crond //關閉服務
  9. # ps aux | grep cron 查看是否有此進程
  10. # systemctl status crond查看狀態,Actice綠色啓動該
  11. 計劃在/var/spool/cron/root(最後是以用戶名命名的文件)
  12. # cront -l //列出信息
  13. # cront -e //編輯
  14. # cront -r //刪除
  15. # cront -u root -l //查看指定用戶的計劃

10.24 Linux系統服務管理-chkconfig工具

  1. # chkconfig --list //當前系統中全部服務
    1. # ls /etc/init.d/
    2. # chkconfig network off
  2. # chkconfig --level 3 network off //指定某個級別的服務關閉
  3. # chkconfig --level 345 network off //指定多個級別的某個服務關閉
  4. # chkconfig --del network
  5. # chkconfig --add network
  6. 將腳本放到/etc/init.d/下再將服務add就能夠將腳本在某幾個級別運行的時候執行了

10.25 systemd管理服務

  1. # systemctl list-units --all--type=service
  2. 幾個經常使用的服務相關的命令
    1. #systemctl enable crond.service //讓服務開機啓動
    2. # systemctl disable crond //讓服務開機不啓動
    3. # systemctl status crod //查看狀態
    4. # systemctl stop crond //中止服務
    5. # systemctl start crond //啓動服務
    6. # systemctl restart crond //重啓服務
    7. # systemctl is-enabled crond //檢查服務是否開機啓動

10.26 unit介紹

  1. ls /usr/lib/systemd/system //系統全部unit,分爲如下類型:
  2. service 系統服務
  3. target 多個unit組成的組
  4. device 硬件設備
  5. mount 文件系統掛載點
  6. automount 自動掛載點
  7. path 文件或路徑
  8. scope 不是有systemd啓動的外部進程
  9. slice進程組
  10. snapshot systemd快照
  11. socket 進程間通訊套接字
  12. swap swap文件
  13. timer 定時器

10.27 target介紹

  1. 系統爲了方便管理用target來管理unit
  2. systemctl list-unit-files --type=target
  3. systemctl list-dependencies multi-user.target //查看指定target下面有哪些unit
  4. systemctl get-default //查看系統默認的target
  5. systemctl set-default multi-user.target
  6. 一個service屬於一種類型的unit
  7. 多個unit組成了一個target
  8. 一個target裏面包含了多個service
  9. 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
相關文章
相關標籤/搜索