linux:service和systemctl两种linux服务管理方式

背景

1、service命令
service命令其实是去/etc/init.d目录下,去执行相关程序

# service命令启动redis脚本
service redis start
# 直接启动redis脚本
/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 ~]# systemctl is-active httpd
active
[root@localhost ~]# systemctl disable httpd
Removed symlink /etc/systemd/system/multi-user.target.wants/httpd.service.
[root@localhost ~]# systemctl enable httpd 
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

你可能感兴趣的:(运维)