Linux:使用systemd管理进程
概述
systemd是目前Linux系统上主要的系统守护进程管理工具,由于init一方面对于进程的管理是串行化的,容易出现阻塞情况,另一方面init也仅仅是执行启动脚本,并不能对服务本身进行更多的管理。所以从CentOS 7 开始也由systemd取代了init作为默认的系统进程管理工具。
systemd所管理的所有系统资源都称作Unit,通过systemd命令集可以方便的对这些Unit进行管理。比如systemctl、hostnamectl、timedatectl、localctl等命令,这些命令虽然改写了init时代用户的命令使用习惯(不再使用chkconfig、service等命令),但确实也提供了很大的便捷性。
特点
- CentOS 7 支持开机并行启动服务,显著提高开机启动效率
- CentOS7使用systemd解决原有模式缺陷,比如原有service不会关闭程序产生的子进程
语法
systemctl [OPTIONS...] {COMMAND} ...
command:
- start:启动指定的unit,例如
systemctl start nginx - stop:关闭指定的unit,例如
systemctl stop nginx - restart:重启指定unit,例如
systemctl restart nginx - reload:重载指定unit,例如
systemctl reload nginx - enable:系统开机时自动启动指定unit,前提是配置文件中有相关配置,例如
systemctl enable nginx - disable:开机时不自动运行指定unit,例如
systemctl disable nginx - status:查看指定unit当前运行状态,例如
systemctl status nginx
配置说明
- 每一个Unit都需要有一个配置文件用于告知systemd对于服务的管理方式
- 配置文件存放于/usr/lib/systemd/system/,设置开机启动后会在/etc/systemd/system目录建立软链接文件
- 每个Unit的配置文件配置默认后缀名为
.service - 在/usr/lib/systemd/system/目录中分为system和user两个目录,一般将开机不登陆就能运行的程序存在系统服务里,也就是/usr/lib/systemd/system
- 配置文件使用方括号分成了多个部分,并且区分大小写
相关文件说明:
| 相关文件 | 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 |
常见中间件配置
Nginx
[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true
[Install]
WantedBy=multi-user.target
MySQL
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
Type=forking
PIDFile=/var/run/mysqld/mysqld.pid
# Disable service start and stop timeout logic of systemd for mysqld service.
TimeoutSec=0
# Execute pre and post scripts as root
PermissionsStartOnly=true
# Needed to create system tables
ExecStartPre=/usr/bin/mysqld_pre_systemd
# Start main service
ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS
# Use this to switch malloc implementation
EnvironmentFile=-/etc/sysconfig/mysql
# Sets open_files_limit
LimitNOFILE = 5000
Restart=on-failure
RestartPreventExitStatus=1
PrivateTmp=false
Linux:使用systemd管理进程的更多相关文章
- Linux 使用 Systemd 管理进程服务
转载自:https://mp.weixin.qq.com/s/e-_PUNolUm22-Uy_ZjpuEA systemd 介绍 systemd是目前Linux系统上主要的系统守护进程管理工具,由于i ...
- systemd管理进程
systemd很强大的管理工具,这里简单用来管理一个进程: [Unit]Description=Imges Compress Server [Service]Type=simpleExecStart= ...
- linux系统日常管理
笔者在前面介绍的内容都为linux系统基础类的,如果你现在把前面的内容全部很好的掌握了,那最好了.不过笔者要说的是,即使你完全掌握了,你现在还是不能作为一名合格的linux系统管理员的,毕竟系统管理员 ...
- lesson - 12 Linux系统日常管理1
监控系统状态 – w, vmstat命令w, uptimesystem load averages 单位时间段内活动的进程数 查看cpu的个数和核数vmstat 1vmstat 1 10vmstat各 ...
- linux内核线程,进程,线程
http://blog.csdn.net/dyllove98/article/details/8917197 Linux对于内存的管理涉及到非常多的方面,这篇文章首先从对进程虚拟地址空间的管理说起.( ...
- centos Linux系统日常管理1 cpuinfo cpu核数 命令 w, vmstat, uptime ,top ,kill ,ps ,free,netstat ,sar, ulimit ,lsof ,pidof 第十四节课
centos Linux系统日常管理1 cpuinfo cpu核数 命令 w, vmstat, uptime ,top ,kill ,ps ,free,netstat ,sar, ulimit ...
- linux 内存地址空间管理 mm_struct
http://blog.csdn.net/yusiguyuan/article/details/39520933 Linux对于内存的管理涉及到非常多的方面,这篇文章首先从对进程虚拟地址空间的管理说起 ...
- linux中 systemd相关配置
systemd相关配置 推荐使用systemd管理进程,相比使用supervisord systemd提供系统级别的支援. 一.系统管理 Systemd 并不是一个命令,而是一组命令,涉及到系统管理的 ...
- Linux网络技术管理及进程管理(week2_day4)--技术流ken
OSI七层模型和TCP/IP四层模型 OSI七层模型:OSI(Open System Interconnection)开放系统互连参考模型是国际标准化组织(ISO)制定的一个用于计算机或通信系统间互联 ...
随机推荐
- XHXJ's LIS HDU - 4352 最长递增序列&数位dp
代码+题解: 1 //题意: 2 //输出在区间[li,ri]中有多少个数是满足这个要求的:这个数的最长递增序列长度等于k 3 //注意是最长序列,可不是子串.子序列是不用紧挨着的 4 // 5 // ...
- 一文带你认识Docker
Docker是一个容器技术的应用,而底层是由于Linux容器实现的,Docker只是实现层. 一.Linux容器 1.隔离与共享 一台服务器运行着多个逻辑隔离的服务器进程,谁的运行环境都不希望影响到谁 ...
- 在kubernetes集群里集成Apollo配置中心(1)之交付Apollo-adminservice至Kubernetes集群
1.部署apollo-adminservice软件包 apollo-adminservice软件包链接地址:https://github.com/ctripcorp/apollo/releases/d ...
- μC/OS-III---I笔记4---软件定时器
软件定时器是在硬件定时器的基础上开发的,通过将一个硬件定时器进行分频及管理就可以的到多个软件定时器.他和时间管理共同组成了系统的时间管理大部分的内容.系统一开始的系统初始化函数OSInit函数内调用了 ...
- 【Alpaca】.Net版开源配置中心 - 技术选型 Vue 3.0
是否可以用 Vue 3.0 现有的Vue 2.* 不推荐,坐等Vue 3.0出迁移工具吧,手动改的话工作量还是不小的 新项目 考虑下团队内对Vue + TS + VS Code的熟练程度.过程中你会遇 ...
- random array & shuffle 洗牌算法 / 随机算法
random array & shuffle shuffle 洗牌算法 / 随机算法 https://en.wikipedia.org/wiki/Fisher–Yates_shuffle ES ...
- free useful skills videos courses & tutorials
free useful skills videos courses & tutorials website video courses https://realpython.com/ http ...
- javascript IIFE in depth
javascript IIFE in depth function type 函数表达式 x = function (){ console.log(x); } ƒ (){ console.log(x) ...
- axios upload excel file
axios upload excel file https://github.com/axios/axios/issues/1660 https://stackoverflow.com/questio ...
- 【C#】反射的用法及效率对比
反射实例化类 public class Person { public string Name { get; set; } public Person(string name) { this.Name ...