systemd 进程管理详解
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 | 服务不能被设定开机启动,但可以由其他服务启动该服务 |
systemd 进程管理详解的更多相关文章
- Linux进程管理详解
何谓进程?进程,就是正在执行的一个程序或命令,每一个进程都是一个运行实体,有自己的地址空间,并占用一定的系统资源.简而言之,进程就是运行中的程序.在Linux中,诸如ls等命令都是进程,只不过某些命令 ...
- linux之进程管理详解
|-进程管理 进程常用命令 |- w查看当前系统信息 |- ps进程查看命令 |- kill终止进程 |- 一个存放内存中的特殊目 ...
- IIS:连接数、并发连接数、最大并发工作线程数、应用程序池的队列长度、应用程序池的最大工作进程数详解
Internet Information Services(IIS,互联网信息服务),是由微软公司提供的基于运行Microsoft Windows的互联网基本服务.最初是Windows NT版本的可选 ...
- IIS连接数、并发连接数、最大并发工作线程数、应用程序池的队列长度、应用程序池的最大工作进程数详解
IIS:连接数.并发连接数.最大并发工作线程数.应用程序池的队列长度.应用程序池的最大工作进程数详解 iis性能指标的各种概念:连接数.并发连接数.最大并发工作线程数.应用程序池的队列长度.应用程序池 ...
- Oracle权限管理详解
Oracle权限管理详解 转载--CzmMiao的博客生活 Oracle 权限 权限允许用户访问属于其它用户的对象或执行程序,ORACLE系统提供三种权限:Object 对象级.System 系统级. ...
- linux进程地址空间详解(转载)
linux进程地址空间详解(转载) 在前面的<对一个程序在内存中的分析 >中很好的描述了程序在内存中的布局,这里对这个结果做些总结和实验验证.下面以Linux为例(实验结果显示window ...
- (转)Spring事务管理详解
背景:之前一直在学习数据库中的相关事务,而忽略了spring中的事务配置,在阿里面试时候基本是惨败,这里做一个总结. 可能是最漂亮的Spring事务管理详解 https://github.com/Sn ...
- 可能是最漂亮的Spring事务管理详解
Java面试通关手册(Java学习指南):https://github.com/Snailclimb/Java_Guide 微信阅读地址链接:可能是最漂亮的Spring事务管理详解 事务概念回顾 什么 ...
- 项目log4j日志管理详解
项目log4j日志管理详解 log4j日志系统在项目中重要性在这里就不再累述,我们在平时使用时如果没有特定要求,只需在log4j.properties文件中顶入输出级别就行了.如果要自定义输出文件,对 ...
随机推荐
- linux系统调用号查询(pwn)
做pwn题时遇到程序使用了64位系统调用号:59和15,这里做一下记录 在线查询链接:https://syscalls.w3challs.com/ 分为32位和64位,链接中还有arm.mips等架构 ...
- DevOps之Jenkins相关知识
目录 认识Jenkins 持续集成 持续交付 Jenkins简介 为什么需要Jenkins Jenkins的目标 Jenkins安装 初次使用Jenkins 加速插件安装 Jenkins-CI Jen ...
- Hyperledger Fabric2.3环境搭建
采用Ubuntu系统下搭建 HyperledgerFabric2.3 环境 安装GoLang 下载golang安装包 https://studygolang.com/dl 下载完成后解压,移到/usr ...
- Python3解决棋盘覆盖问题的方法示例
本文实例讲述了Python3解决棋盘覆盖问题的方法.分享给大家供大家参考,具体如下: 问题描述: 在2^k*2^k个方格组成的棋盘中,有一个方格被占用,用下图的4种L型骨牌覆盖所有棋盘上的其余所有方格 ...
- hdu4585 STL水题
题意: 成立少林寺,刚开始有一个大师,id是1,攻击力是10E,现在陆续来人,每个人有自己的id,和自己的攻击力,但是每一个新来的要和之前的和尚pk,他必须选择和他攻击力差值最小的那个,如 ...
- dex文件格式学习
一.dex文件的生成 我们可以通过java文件来生成一个简单的dex文件 编译过程: 首先编写java代码如下: (1) 编译成 java class 文件 执行命令 : javac Hello.ja ...
- hdu3756 三分求最小圆锥
题意: 让你找到一个最小的圆柱去覆盖所有的竖直的线段.. 思路: 三分,直接去三分他的半径,因为想下,如果某个半径是最优值,那么 从R(MAX->now->MIN) ...
- DVWA之Command injection(命令执行漏洞)
目录 Low Medium Middle Impossible 命令执行漏洞的原理:在操作系统中, & .&& .| . || 都可以作为命令连接符使用,用户通过浏览器 ...
- 利用ICMP进行命令控制和隧道传输
目录 使用ICMP进行命令控制 使用ICMP搭建隧道 使用ICMP进行命令控制 攻击机:Kali 192.168.10.11 靶机:Windows 192.168.10.1 使用的工具:icmpsh ...
- Portswigger web security academy:Server-side template injection(SSTI)
Portswigger web security academy:Server-side template injection(SSTI) 目录 Portswigger web security ac ...