一、 systemd
序号 | 指令 | centos6 | centos7 | 备注 |
---|---|---|---|---|
1 | 启动 | service name start | systemctl start name.service | |
2 | 停止 | service name stop | systemctl stop name.service | |
3 | 重启 | service name restart | systemctl restart name.service | |
4 | 状态 | service name status | systemctl status name.service | |
5 | 条件重启 | service name crondrestart | systemctl try-restart name.service | |
6 | 重载或重启 | – | systemctl reload-or-restart name.service | – |
7 | 重载或条件式重启 | – | systemctl reload-or-try-restart name.service | |
8 | 查看 | – | systemctl is-active name.service | 查看某服务当前状态激活与否 |
9 | 查看 | – | systemctl list-units --type service | 查看所有已激活的服务 |
10 | 查看 | chkconfig --list | systemctl list-units --type service --all | 查看所有服务,包括已激活和未激活 |
11 | 设置自启 | chkconfig name on | systemctl enable name.service | 允许开机自启动 |
12 | 禁止自启 | chkconfig name off | systemctl disable name.service | 禁止开机自启动 |
13 | 查看 | chkconfig --list name | systemctl is-enable name.service | 查看某服务是否能开机自启 |
14 | 禁止某服务设置开机自启 | systemctl mask name.service | ||
15 | 取消某服务设置开机自启限制 | systemctl unmask name.service | ||
16 | 查看服务依赖关系 | systemctl list-dependencies name.service |
二、自定义systemd
1.查看/usr/lib/systemd/system目录下nginx.service
[Unit]
Description:描述
After:定义当前unit启动次序,表示当前unti应晚于那些unit启动;与before功能相反
requires:依赖到的其它units,强依赖;被依赖的unit无法激活时,当前units无法激活
wants:依赖到的其它units,弱依赖
conflicts:定义units间的冲突关系
[Service]
Type:定义影响ExecStart及相关参数的功能units进程启动类型
forking
simple
oneshot
dbus
notify
idle
EnvironmentFile:环境配置文件
ExecStart:指明启动unit要运行的命令或脚本,ExecStartPre(预检测)ExecStartPost
ExecStop:指明停止unit要运行的命令或脚本
PIDFile=/usr/local/openresty/nginx/logs/nginx.pid
ExecStartPre=/usr/local/openresty/nginx/sbin/nginx -t
ExecStart=/usr/local/openresty/nginx/sbin/nginx
ExecStartPost=/bin/sleep 1
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
alias:
RequiredBy:被哪些units所依赖
WantedBy:被哪些units所依赖
WantedBy=multi-user.target
注意:对应在新建或者修改的unit文件,需要通知systemd重载此配置文件。
命令:systemctl daemon-reload
2.编译安装zabbix 后手动添加到systemd.