Linux—服务管理三种方式(chkconfig和service和systemctl)

一、chkconfig 介绍

二、service 介绍

1、常见 service 命令

[root@localhost ~]# service supervisord stop
[root@localhost ~]# service supervisord start
[root@localhost ~]# service supervisord status
[root@localhost ~]# service --status-all            # 查看Linux所有服务的运行状态

三、systemctl 介绍

1、常见 systemctl 命令

[root@localhost ~]# systemctl stop supervisord
[root@localhost ~]# systemctl start supervisord
[root@localhost ~]# systemctl status supervisord
[root@localhost ~]# systemctl restart supervisord
[root@localhost ~]# systemctl is-active supervisord         # 查看服务是否运行
 
[root@localhost ~]# systemctl enable supervisord            # 设置服务允许开机启动
[root@localhost ~]# systemctl disable supervisord           # 设置服务禁止开机启动
[root@localhost ~]# systemctl is-enabled supervisord        # 查看服务是否设置为开机启动,得到的值可以是enable、disable或static,这里的 static 它是指对应的 Unit 文件中没有定义[Install]区域,因此无法配置为开机启动服务。
[root@localhost ~]# systemctl daemon-reload                 # 添加.service文件后,或者变更.service文件设置后,需要执行一下这个
  
[root@localhost ~]# systemctl list-unit-files                      # 查看开机启动项
[root@localhost ~]# systemctl list-unit-files | grep 程序名称       # 查看某些服务开机启动状态
[root@localhost ~]# systemctl list-unit-files | grep enable        # 查看哪些为开机启动服务
[root@localhost ~]# systemctl list-units --type=service            # 查看所有已启动的服务
[root@localhost ~]# systemctl --failed                             # 查看启动失败的服务列表
 
[root@localhost ~]# systemctl mask supervisord                     # 注销supervisord服务
[root@localhost ~]# systemctl unmask supervisord                   # 取消注销supervisord服务

[root@localhost ~]# systemctl get-default                      # 获得当前的运行级别
[root@localhost ~]# systemctl set-default multi-user.target    # 设置默认的运行级别为mulit-user,即开机不开启图形
[root@localhost ~]# systemctl set-default graphical.target     # 设置默认的运行级别为mulit-user,即开机启动图形
[root@localhost ~]# systemctl isolate multi-user.target	       # 在不重启的情况下,切换到运行级别mulit-user下
[root@localhost ~]# systemctl isolate graphical.target	       # 在不重启的情况下,切换到图形界面下

2、常见 systemctl 命令

  

借鉴:https://www.cnblogs.com/shijingjing07/p/9301590.html

https://blog.csdn.net/u012486840/article/details/53161574

原文地址:https://www.cnblogs.com/liuhaidon/p/11452072.html