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. HDU 1564 Play a game && HDU 2147 kiki's game

    HDU 1564 Play a game题意: 棋盘的大小是n*n.一块石头被放在一个角落的广场上.他们交替进行,8600人先走.每次,玩家可以将石头水平或垂直移动到一个未访问的邻居广场.谁不采取行动 ...

  2. Linux命令之find命令中的-mtime参数

    有关find -mtime的参数解释 mtime参数的理解应该如下: -mtime n 按照文件的更改时间来找文件,n为整数. n表示文件更改时间距离为n天, -n表示文件更改时间距离在n天以内,+n ...

  3. 一些简单的SQL语句

    简单的SQL入门 一,简介 1,  一个数据库包含一个或多个表,表包含带有数据的记录(行) 2,  SQL对大小写不敏感,语句的分号看具体情况 二,语法 1,  数据操作语言:DML a)       ...

  4. TCP之“3次握手,4次挥手”问题——实例分析

    上一篇我们分析了三次握手和四次握手的过程,但是理论分析难免枯燥难懂,下面这篇我们来看一个例子,就能更好地理解tcp链接了. 我们可以通过网络抓包的查看具体的流程: 比如我们服务器开启9502的端口.使 ...

  5. H.264视频压缩标准

    H.264 这部分一直在讲,但是却没有系统的来说.接下来要详细. 参看:H.264视频压缩标准 一.简介 H.264是最新的视频压缩标准,它也称为MPEG-4 Part 10或AVC(高级视频编码). ...

  6. 康托展开:对全排列的HASH和还原,判断搜索中的某个排列是否出现过

    题目:http://acm.hrbust.edu.cn/index.php?m=ProblemSet&a=showProblem&problem_id=2297 前置技能:(千万注意是 ...

  7. vue watcher errors

    vue watcher errors Error in callback for watcher TypeError: Cannot set property of undefined" n ...

  8. 全球最好 css3 website

    http://www.awwwards.com/ http://www.revolution.pn/ http://www.bestcss.in/ http://www.csswinner.com/ ...

  9. Get your site working on Google Search Console , 在 Google Search Console中运行您的网站, Google Search Console

    1 1 https://support.google.com/webmasters/topic/4564315? Search Console Help SEARCH CONSOLEHELP FORU ...

  10. Chrome console & Command Line API

    Chrome console & Command Line API $ && $$ querySelector querySelectorAll Command Line AP ...