八週一次課(5月11日)

linux任務計劃cron:

任務計劃配置文件:html

/etc/crontablinux

crontab -u、-e、-l、-r:nginx

crontab -e 編輯任務計劃centos

crontab -l 查看任務計劃ssh

crontab -r 刪除全部的任務計劃socket

crontab -u 指定一個用戶工具

例如:crontab -u root -l 列出root用戶的任務計劃spa

格式:分 時 日 月 周 user command.net

分:範圍0-59rest

時:範圍0-23

日:範圍1-31

月:範圍1-12

周:範圍0-6,0表示週日,也能夠用7表示週日

可用格式1,2,3表示1或者2或者3

可用格式*/2表示被2整除數字,好比小時,那就是每隔2小時

可用格式1-5表示一個範圍1到5

文件/var/spool/cron/username

命令crontab -e實際上打開了 /va/spool/cron/username文件(若是是root則打開了/var/spool/cron/root文件)

要保證服務是啓動狀態

systemctl start crond.service

ps aux | grep crond

查看服務狀態:

systemctl status crond.service

chkconfig工具:

CentOS 6上的服務管理工具爲chkconfig,linux系統全部的預設服務均可以經過查看/etc/init.d/目錄獲得。CentOS 7中已經再也不延續CentOS 6版本的服務管理方案了,可是咱們依然能夠繼續使用chkconfig這個命令。系統預設服務均可以經過這樣的命令實現:service 服務名 start | stop | restart。這裏的服務名就是/etc/init.d/目錄下的這些文件了。啓動crond除了可使用service crond start外,還可使用/etc/initd.d/crond start。

chkconfig --list

列出全部服務以及每一個級別的開啓狀態

chkconfig --level 3 network off

--level 指定啓動的級別,後面跟服務名,而後是off或則on

在3級別時network服務關掉

chkconfig --level 345 network off

--level後面能夠指定多個級別

chkconfig nginx off | on

nginx在全部級別上都是關| 開的,其中0 1 6 這些級別服務都是關的。

chkconfig --del network

chkconfig能夠把某個服務從系統服務中刪除

chkconfig --add network

把可執行的腳本文件放到/etc/init.d/目錄下後,可使用此命令加入到系統服務

systemd管理服務:

列出系統全部的服務:

systemctl list-units --all --type=service

幾個經常使用的服務相關的命令:

systemctl enable crond.service //讓服務開機啓動

crond服務的路徑是/usr/lib/systemd/system/crond.service,開啓時會在/etc/systemd/system/multi-user.target.wants/目錄下生成一個軟連接

systemctl disable crond //不讓開機啓動

會刪掉開啓服務時生成的軟連接

systemctl status crond //查看狀態

systemctl stop crond //中止服務

systemctl start crond //啓動服務

systemctl restart crond //重啓服務

systemctl is-enabled crond //檢查服務是否開機啓動

 

unit介紹:

ls /usr/lib/systemd/system //系統全部unit、分爲如下類型

• service 系統服務

• target 多個unit組成的組

• device 硬件設備

• mount 文件系統掛載點

• automount 自動掛載點

• path 文件或路徑

• scope 不是由systemd啓動的外部進程

• slice 進程組

• snapshot systemd快照

• socket 進程間通訊套接字

• swap  swap文件

• timer 定時器

以上每種類型的文件都爲一個unit,正是這些unit才組成了系統的各個資源(各個服務,各個設備等)

unit相關的命令:

systemctl list-units //列出正在運行的unit

systemctl list-units --all //列出全部,包括失敗的或者inactive的

systemctl list-units --all --state=inactive //列出inactive的unit

systemctl list-units --type=service//列出狀態爲active的service

systemctl is-active crond.service //查看某個服務是否爲active

target介紹:

系統爲了方便管理用target來管理unit

systemctl list-unit-files --type=target

列出系統的全部target

systemctl list-dependencies multi-user.target //查看指定target下面有哪些unit

systemctl get-default //查看系統默認的target

systemctl set-default multi-user.target //設置默認的target

ls -l /etc/systemd/system/default.target

查看系統支持的target啓動級別:

centos 7中系統啓動級別的定義已經和centos 6中不同了

一個service屬於一種類型的unit

多個unit組成了一個target

一個target裏面包含了多個service

cat /usr/lib/systemd/system/sshd.service //看[install]部分

查看sshd.service屬於哪一個target

擴展

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

相關文章
相關標籤/搜索