systemd进程管理


systemd管理的优势

1.最新系统都采用systemd管理(RedHat7,CentOS7,Ubuntu15...)

2.CentOS7 支持开机并行启动服务,显著提高开机启动效率

3.CentOS7关机只关闭正在运行的服务,而CentOS6,全部都关闭一次。

4.CentOS7服务的启动与停止不再使用脚本进行管理,也就是/etc/init.d下不在有脚本。

5.CentOS7使用systemd解决原有模式缺陷,比如原有service不会关闭程序产生的子进程。

systemd相关文件


systemd控制的相关文件 CentOS6 CentOS7
服务启动的脚本启动路径 /etc/init.d /usr/lib/systemd/system
开机自启服务存放路径 /etc/rcN.d /etc/systemd/system/multi-user.target.wants/
默认运行级别配置文件 /etc/inittab /etc/systemd/system/default.target

CentOS7安装yum安装nginx的默认脚本启动路径

[root@gong ~]# ll /usr/lib/systemd/system/nginx.service
-rw-r--r-- 1 root root 618 Oct 3 2019 /usr/lib/systemd/system/nginx.service

CentOS7开机自启动所在的目录,该目录包含在该级别启动时自启动的服务

[root@gong ~]# ll /etc/systemd/system/multi-user.target.wants/

CentOS7默认运行级别的控制,把它链接到/usr/lib/systemd/system/下面的不同级别,可以实现对不同默认级别的更改

[root@gong ~]# ll /etc/systemd/system/default.target
lrwxrwxrwx 1 root root 41 Apr 23 15:56 /etc/systemd/system/default.target -> /usr/lib/systemd/system/multi-user.target

systemd相关命令


CentOS6 systemd CentOS7 作用
/etc/init.d/nginx start systemctl start nginx 启动nginx服务
/etc/init.d/nginx stop systemctl stop nginx 停止nginx服务
/etc/init.d/nginx status systemctl status nginx 查看nginx的状态
/etc/init.d/nginx restart systemctl restart nginx 重启nginx服务
/etc/init.d/nginx reload systemctl reload nginx 不停止nginx服务,重新加载配置文件
systemctl is-active nginx 判断nginx服务是否存活
systemctl mask nginx 禁止运行服务
systemctl unmask nginx 取消禁止运行服务

CentOS7启动服务

[root@gong ~]# systemctl start nginx

CentOS7关闭服务

[root@gong ~]# systemctl stop nginx

CentOS7查看服务状态

[root@gong ~]# systemctl status nginx
● nginx.service - The nginx HTTP and reverse proxy server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
Active: inactive (dead) since Sat 2020-04-25 08:55:55 CST; 12s ago
Process: 7063 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
Process: 7060 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
Process: 7056 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)
Main PID: 7064 (code=exited, status=0/SUCCESS) Apr 25 08:55:44 gong systemd[1]: Starting The nginx HTTP and reverse proxy server...
Apr 25 08:55:45 gong nginx[7060]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
Apr 25 08:55:45 gong nginx[7060]: nginx: configuration file /etc/nginx/nginx.conf test is successful
Apr 25 08:55:45 gong systemd[1]: Started The nginx HTTP and reverse proxy server.
Apr 25 08:55:55 gong systemd[1]: Stopping The nginx HTTP and reverse proxy server...
Apr 25 08:55:55 gong systemd[1]: Stopped The nginx HTTP and reverse proxy server.

Centos7重启服务

[root@gong ~]# systemctl restart nginx

CentOS7不重启服务重新加载配置文件

[root@gong ~]# systemctl reload nginx

CentOS7检查服务是否启动

[root@gong ~]# systemctl is-active nginx
active

禁止取消服务运行

[root@gong ~]# systemctl mask nginx
Created symlink from /etc/systemd/system/nginx.service to /dev/null.
[root@gong ~]# systemctl unmask nginx
Removed symlink /etc/systemd/system/nginx.service.

systemd开机自启动相关命令


CentOS6 CentOS7 作用
chkconfig --list systemctl list-unit-files 查看开机自启的服务
chkconfig nginx on systemctl enable nginx 开机自启
chkconfig nginx off systemctl disable nginx 关闭开机自启
chkconfig --list nginx systemctl is-enabled nginx 查看指定的服务是否被开启
chkconfig --add nginx systemctl daemon-reload 当手写脚本的时候让系统认识

CentOS7查看开机自启动

[root@gong ~]# systemctl list-unit-files

CentOS7设置开机自启,实质上实在创建软链接

[root@gong ~]# systemctl  enable nginx
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.

CentOS7关闭开机自启

[root@gong ~]# systemctl disable nginx
Removed symlink /etc/systemd/system/multi-user.target.wants/nginx.service.

CentOS7查看指定的服务是否被开启

[root@gong ~]# systemctl is-enabled nginx
disabled

systemd服务状态


服务状态 状态说明
loaded 服务单元的配置文件已经被处理
active(running) 服务的一个或多个进程在运行中
active(exited) 一次性运行的服务成功被执行并退出(服务运行后完成任务,相关进程会自动退出)
active(waiting) 服务已经运行但在等待某个事件
inactive 服务没有在运行
enable 服务设定为开机运行
disabled 服务设定为开机不运行
static 服务不能被设定开机启动,但可以由其他服务启动该服务

最新文章

  1. 未来的 Web:九个不可思议的 WebGL 应用试验
  2. maven简单配置
  3. linux 给文件夹权限
  4. Selenium2+python自动化12-操作元素(键盘和鼠标事件)
  5. 【转】【Android测试技巧】01. root后adb shell默认不是root用户时,如何将文件放入手机系统中
  6. 【项目经验】如何用TexturePacker & Physicseditor开发游戏
  7. dom的element类型
  8. C#重写Equals方法步骤
  9. iOS 中国排序
  10. 浅谈 MVC中的ViewData、ViewBag和TempData
  11. keepalived实现nginx高可用
  12. maximun-depth-of-binary-tree
  13. [Swift]LeetCode508. 出现次数最多的子树元素和 | Most Frequent Subtree Sum
  14. Cannot uninstall 'pyserial'. It is a distutils installed project and thus we cannot a ccurately determine which files belong to it which would lead to only a partial uninstall. 解决方法
  15. 高德地图API(流程法)整理分析
  16. 在Windows下为PHP5.6安装redis扩展和memcached扩展
  17. Python之模块二
  18. java获取mysql数据库表、字段、字段类型、字段注释
  19. swift c++ oc 混编
  20. MySQL InnoDB与MyISAM存储引擎差异

热门文章

  1. JAVAEE_Servlet_06_ServletContext接口
  2. 基于MATLAB的手写公式识别(5)
  3. Linux内核软中断
  4. 使用Windows全局钩子打造键盘记录器
  5. [CTF]ACSII码
  6. SQL注入注释符(#、-- 、/**/)使用条件及其他注释方式的探索
  7. .NET并发编程-TPL Dataflow并行工作流
  8. 初学Golang的笔记
  9. ATK&CK红队评估实战靶场 (一)的搭建和模拟攻击过程全过程
  10. Docker安装ElasticSearch和Kibana