Blog:博客园 个人

概述

systemd是目前Linux系统上主要的系统守护进程管理工具,由于init一方面对于进程的管理是串行化的,容易出现阻塞情况,另一方面init也仅仅是执行启动脚本,并不能对服务本身进行更多的管理。所以从CentOS 7 开始也由systemd取代了init作为默认的系统进程管理工具。

systemd所管理的所有系统资源都称作Unit,通过systemd命令集可以方便的对这些Unit进行管理。比如systemctlhostnamectltimedatectllocalctl等命令,这些命令虽然改写了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管理进程的更多相关文章

  1. Linux 使用 Systemd 管理进程服务

    转载自:https://mp.weixin.qq.com/s/e-_PUNolUm22-Uy_ZjpuEA systemd 介绍 systemd是目前Linux系统上主要的系统守护进程管理工具,由于i ...

  2. systemd管理进程

    systemd很强大的管理工具,这里简单用来管理一个进程: [Unit]Description=Imges Compress Server [Service]Type=simpleExecStart= ...

  3. linux系统日常管理

    笔者在前面介绍的内容都为linux系统基础类的,如果你现在把前面的内容全部很好的掌握了,那最好了.不过笔者要说的是,即使你完全掌握了,你现在还是不能作为一名合格的linux系统管理员的,毕竟系统管理员 ...

  4. lesson - 12 Linux系统日常管理1

    监控系统状态 – w, vmstat命令w, uptimesystem load averages 单位时间段内活动的进程数 查看cpu的个数和核数vmstat 1vmstat 1 10vmstat各 ...

  5. linux内核线程,进程,线程

    http://blog.csdn.net/dyllove98/article/details/8917197 Linux对于内存的管理涉及到非常多的方面,这篇文章首先从对进程虚拟地址空间的管理说起.( ...

  6. 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 ...

  7. linux 内存地址空间管理 mm_struct

    http://blog.csdn.net/yusiguyuan/article/details/39520933 Linux对于内存的管理涉及到非常多的方面,这篇文章首先从对进程虚拟地址空间的管理说起 ...

  8. linux中 systemd相关配置

    systemd相关配置 推荐使用systemd管理进程,相比使用supervisord systemd提供系统级别的支援. 一.系统管理 Systemd 并不是一个命令,而是一组命令,涉及到系统管理的 ...

  9. Linux网络技术管理及进程管理(week2_day4)--技术流ken

    OSI七层模型和TCP/IP四层模型 OSI七层模型:OSI(Open System Interconnection)开放系统互连参考模型是国际标准化组织(ISO)制定的一个用于计算机或通信系统间互联 ...

随机推荐

  1. hdu3461 Code Lock

    Problem Description A lock you use has a code system to be opened instead of a key. The lock contain ...

  2. EGADS介绍(二)--时序模型和异常检测模型算法的核心思想

    EDADS系统包含了众多的时序模型和异常检测模型,这些模型的处理会输入很多参数,若仅使用默认的参数,那么时序模型预测的准确率将无法提高,异常检测模型的误报率也无法降低,甚至针对某些时间序列这些模型将无 ...

  3. anaconda + pyqt5 + pycharm 安装,测试

    1. 安装sip pip install sip 2.安装pyqt5 pip install PyQt5 pip install PyQt5-tools -i http://pypi.douban.c ...

  4. 牛客网多校第3场 C-shuffle card 【splay伸展树】

    题目链接:戳这里 转自:戳这里 关于splay入门:戳这里 题意:给n个数,进行m次操作,每次都从n个数中取出连续的数放在最前面. 解题思路:splay的区间操作. 附代码: 1 #include&l ...

  5. POJ - 3280 Cheapest Palindrome 【区间dp】【非原创】

    Keeping track of all the cows can be a tricky task so Farmer John has installed a system to automate ...

  6. C++ part7

    1.C++ 继承和组合 类的组合和继承一样,是复用的重要方式. 要优先使用组合而不是继承. 原因: 组合是黑箱复用,对局部类的内部细节不可见:继承是白箱复用,父类的内部细节可见,破坏封装性. 继承在编 ...

  7. React Testing All in One

    React Testing All in One React 测试 https://reactjs.org/docs/testing.html jest 26.4 https://jestjs.io/ ...

  8. Beacon API All In One

    Beacon API All In One Beacon API https://developer.mozilla.org/en-US/docs/Web/API/Beacon_API https:/ ...

  9. AMP ⚡

    AMP https://amp.dev/zh_cn/ PWA AMP Playground https://playground.amp.dev/?runtime=amp4email <!doc ...

  10. 「NGK每日快讯」11.18日NGK公链第15期官方快讯