|
service + chkconfig命令组合 |
|
比较 |
较新,克服service缺点 |
较旧,需要自己写脚本 |
目录(Centos)系统 |
/usr/lib/systemd/system |
/etc/init.d |
目录(Centos)用户 |
/usr/lib/systemd/user |
/etc/init.d |
目录(Ubuntu) |
/etc/systemd/system |
|
读取配置文件大部分文件都是符号链接 |
/etc/systemd/system/ |
|
真正的配置文件 |
/usr/lib/systemd/system/ |
|
来源 |
CentOS 7.x 开始代替 daemon |
Redhat控制系统服务的实用工具 |
显示所服务的状态 |
|
service -status |
启动服务 |
systemctl start [unit type] |
service [服务] start |
停止服务 |
systemctl stop [unit type] |
service [服务] stop |
重启服务 |
systemctl restart [unit type] |
service [服务] restart |
重载服务 |
systemctl reload [unit type] |
service [服务] reload |
帮助信息 |
|
service -h |
查看所有服务的状态 |
systemctl list-unit-files --type=service |
service --status-all |
重启系统 |
sudo systemctl reboot |
|
关闭系统,切断电源 |
sudo systemctl poweroff |
|
CPU停止工作 |
sudo systemctl halt |
|
暂停系统 |
sudo systemctl suspend |
|
让系统进入休眠状态 |
sudo systemctl hibernate |
|
让系统进入交互式休眠状态 |
sudo systemctl hybrid-sleep |
|
启动进入救援状态(单用户状态) |
sudo systemctl rescue |
|
显示当前主机的信息 |
hostnamectl |
|
设置主机名 |
sudo hostnamectl set-hostname rhel7 |
|
显示当前主机的信息 |
hostnamectl |
|
设置开机自启动 |
systemctl enable nfs-server.service |
|
停止开机自启动 |
systemctl disable nfs-server.service |
|
是否开机自启动 |
systemctl is-enable nfs-server.service |
|
杀死一个服务的所有子进程 |
sudo systemctl kill apache.service |
|
重新加载一个服务的配置文件 |
sudo systemctl reload apache.service |
|
重载所有修改过的配置文件 |
sudo systemctl daemon-reload |
|
显示某个 Unit 的所有底层参数 |
systemctl show httpd.service |
|
显示某个 Unit 的指定属性的值 |
systemctl show -p CPUShares httpd.service |
|
设置某个 Unit 的指定属性 |
sudo systemctl set-property httpd.service CPUShares=500 |
|
管理远程系统 |
systemctl status httpd -H root@192.168.0.01 |
|
服务名,即 /etc/init.d 目录下的脚本文件名 |
|
service service_name |
重启所有服务 |
|
service --full-restart |
优点 |
多进程并发启动 |
|
缺点 |
|
启动时间长 |
缺点 |
|
脚本复杂 |