背景
1、service命令
service命令其实是去/etc/init.d目录下,去执行相关程序
service redis start
/etc/init.d/redis start
update-rc.d redis defaults
其中脚本需要我们自己编写
2、systemctl命令
systemd是Linux系统最新的初始化系统(init),作用是提高系统的启动速度,尽可能启动较少的进程,尽可能更多进程并发启动。
systemd对应的进程管理命令是systemctl
systemctl命令兼容了service
即systemctl也会去/etc/init.d目录下,查看,执行相关程序
systemctl redis start
systemctl redis stop
systemctl enable redis
Systemctl命令常见用法
检查某个单元是否启动:
systemctl is-enabled httpd.service
检查某个服务的运行状态
systemctl status httpd.service
列出所有服务
systemctl list-unit-files --type=service
启动,停止,重启服务等
systemctl restart httpd.service
systemctl stop httpd.service
systemctl reload httpd.service
systemctl status httpd.service
查询服务是否激活,和配置是否开机启动
[root@localhost ~]
active
[root@localhost ~]
Removed symlink /etc/systemd/system/multi-user.target.wants/httpd.service.
[root@localhost ~]
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
使用systemctl命令杀死服务
systemctl kill httpd
重启、停止,挂起、休眠系统
systemctl reboot
systemctl halt
systemctl suspend
systemctl hibernate
systemctl hybrid-sleep
Service命令用法
开启关闭一个服务
service httpd start
service httpd stop
查看系统服务的状态
service --status-all