Centos7 systemed管理命令
从CentOS7开始,系统开始使用systemed管理机制,它不仅可以完成系统的初始化工作,还可以实现对系统和服务的管理工作。当然,虽然使用了新的管理机制,但CentOS7依然兼容sysvinit和Linux标准组的启动脚本。
启动、停止、重启一个服务
例如以apache的httpd.service为例
启动httpd.service systemctl start httpd.seriver
停止httpd.service systemctl stop httpd.service
重启httpd.service systemctl restart httpd.service
重新加载配置文件启动httpd.service systemctl reload httpd.service
确保服务启动(如已经启动不重启,如未启动,则启动),可使用try-start选项,如systemctl try-start httpd.service
查看、禁用、启用服务
使用enable ,disable,status分别来操作或获取服务是否开机自启动。
使能开机启动 :systemctl enable httpd.service
禁止开机启动:systemctl eisable httpd.service
是否开机启动:systemctl status httpd.service
系统电源的管理
systemd命令 | 含 义 |
---|---|
systemctl power off | 关机 |
systemctl reboot | 重启 |
systemctl suspend | 待机 |
systemctl hibernate | 休眠 |
systemctl hybrid-sleep | 进入混合休眠 |
systemd命令和sysvinit命令对照表
Sysvinit 命令 | Systemd 命令 | 备注 |
---|---|---|
service foo start | systemctl start foo.service | 用来启动一个服务 (并不会重启现有的) |
service foo stop | systemctl stop foo.service | 用来停止一个服务 (并不会重启现有的)。 |
service foo restart | systemctl restart foo.service | 用来停止并启动一个服务。 |
service foo reload | systemctl reload foo.service | 当支持时,重新装载配置文件而不中断等待操作。 |
service foo condrestart | systemctl condrestart foo.service | 如果服务正在运行那么重启它。 |
service foo status | systemctl status foo.service | 汇报服务是否正在运行。 |
ls /etc/rc.d/init.d/ | systemctl list-unit-files —type=service | 用来列出可以启动或停止的服务列表。 |
chkconfig foo on | systemctl enable foo.service | 在下次启动时或满足其他触发条件时设置服务为启用 |
chkconfig foo off | systemctl disable foo.service | 在下次启动时或满足其他触发条件时设置服务为禁用 |
chkconfig foo | systemctl is-enabled foo.service | 用来检查一个服务在当前环境下被配置为启用还是禁用。 |
chkconfig –list | systemctl list-unit-files —type=service | 输出在各个运行级别下服务的启用和禁用情况 |
chkconfig foo –list | ls /etc/systemd/system/*.wants/foo.service | 用来列出该服务在哪些运行级别下启用和禁用。 |
chkconfig foo –add | systemctl daemon-reload | 当您创建新服务文件或者变更设置时使用。 |
telinit 3 | systemctl isolate multi-user.target (systemctl isolate runlevel3.target OR telinit 3) | 改变至多用户运行级别。 |