Systemd程序及相关命令

Systemd是一款用于Linux操作系统系统管理和服务管理的工具。它向后兼容SysV init脚本,并且支持许多类似于startup系统服务的功能,比如系统快照(snapshots)。在RHEL 7中,systemd替代了Upstarts。

主要特性

基于socket的激活机制

基于bus的激活机制

基于device的激活机制

基于path的激活机制

支持系统状态快照

支持挂载和自动挂载点

支持并行化

开闭单元逻辑事务化

向后兼容SysV init

Systemd单元类型

单元类型        文件后缀      描述

Service unit       .service         单个系统服务
Target unit      .target         一组systemd单元

Automount unit      .automount     一个文件系统挂载点

Device unit       .device        内核识别的设备文件

Path unit        .path           文件或目录

Scope unit         .scope         由外部创建的进程

Slice unit       .slice           一组具有层级结构、管理系统进程的单元

Snapshot unit        .snapshot       systemd 管理器保存的一种状态

Socket unit            .socket         一种进程间通信socket

Swap unit          .swap          交换设备或者交换文件

TImer unit                .timer        systemd计时器

相关文件

/usr/lib/systemd/system/     安装时的配置文件

/run/systemd/system       相关单元在运行时产生的文件

/etc/systemd/system/        systemctl enable  命令产生的文件

使用systemd管理服务

systemctl start  name.service       

systemctl status name.service

systemctl stop name.service

systemctl restart name.service

systemctl try-restart name.service

systemctl reload name.service

systemctl is-active name.service

systemctl list-units [--type service --all ]

systemctl enable name.service

systemctl disable name.service

systemctl is-enabled  name.service

systemctl list-unit-files --type service

使用systemd管理target

CentOS 7中的运行target与CentOS6中的运行等级类似,并且兼容命令init和runlevel

0   runlevel0.target, poweroff.target      Shut down and power off the system.
1   runlevel1.target, rescue.target            Set up a rescue shell.
2      runlevel2.target, multi-user. target       Set up a non-graphical multi-user system.
3      runlevel3.target, multi-user.target    Set up a non-graphical multi-user system.
4   runlevel4.target,multi-user. target   Set up a non-graphical multi-user system.
5   runlevel5.target,graphical.target      Set up a graphical multi-user system.

6   runlevel6.target,reboot.target      Shut down and reboot the system.

查看运行等级

  systemctl get-default

设置运行等级

  systemctl set-default  name.target

改变当前运行等级

  systemctl isolate name.target

  systemctl  [rescue | halt | reboot | poweroff | hibernate | suspend]

Systemd 单元文件

组成

[Unit] 

  包含通用的选项,包括描述、依赖的单元等

[unit type] 

  单元类型

[Install]

  包含单元安装信息

常用选项

Description

Documentation

After

Requires

Wants

Conflicts

Type

ExecStart

ExecStop

ExecReload

Restart

RemainAfterExit

Alias

  

  示例

[root@host ~]#cat /usr/lib/systemd/system/httpd.service
[Unit]
Description=The Apache HTTP Server
After=network.target remote-fs.target nss-lookup.target
Documentation=man:httpd()
Documentation=man:apachectl() [Service]
Type=notify
EnvironmentFile=/etc/sysconfig/httpd
ExecStart=/usr/sbin/httpd $OPTIONS -DFOREGROUND
ExecReload=/usr/sbin/httpd $OPTIONS -k graceful
ExecStop=/bin/kill -WINCH ${MAINPID}
# We want systemd to give httpd some time to finish gracefully, but still want
# it to kill httpd after TimeoutStopSec if something went wrong during the
# graceful stop. Normally, Systemd sends SIGTERM signal right after the
# ExecStop, which would kill httpd. We are sending useless SIGCONT here to give
# httpd time to finish.
KillSignal=SIGCONT
PrivateTmp=true [Install]
WantedBy=multi-user.target

Systemd程序及相关命令的更多相关文章

  1. Linux进程相关命令使用场景

    Linux进程相关命令使用场景 在Linux系统上工作时,我们常常会碰到很多和进程相关的查询场景,今天在这里进行详细的讲解,进程相关的对象包括以下几个: 端口:Port 进程号:PId 执行文件所在路 ...

  2. Linux网络——配置防火墙的相关命令

    Linux网络——配置防火墙的相关命令 摘要:本文主要学习了如何在Linux系统中配置防火墙. iptables命令 iptables准确来讲并不是防火墙,真正的防火墙是运行于系统内核中的netfil ...

  3. Shell编程基础教程5--文本过滤、正则表达式、相关命令

    5.文本过滤.正则表达式.相关命令    5.1.正则表达式(什么是正则表达式?正则表达式怎么进行匹配?常用命令)        简介:            一种用来描述文本模式的特殊语法      ...

  4. Linux文件管理相关命令

    Linux文件管理相关命令   作者:Vamei 出处:http://www.cnblogs.com/vamei 欢迎转载,也请保留这段声明.谢谢! 在了解了Linux文件管理背景知识之后, 我们可以 ...

  5. sqlplus 配置方法及相关命令

    sqlplus 配置方法及相关命令 1.配置文件 1.1 全局模式什么叫全局模式呢:当我们配置完sqlplus工具加载配置文件后,无论在哪个目录下登陆数据库,您设置[sqlplus提示符样子,在任何目 ...

  6. Systemd入门教程:命令篇

    导读 传统的Linux系统启动过程主要由著名的init进程(也被称为SysV init启动系统)来处理,而基于init的启动系统被认为有效率不足的问题,systemd是Linux系统机器的另一种启动方 ...

  7. Linux中mod相关的命令 内核模块化 mod相关命令都是用来动态加载内核模块/驱动程序模块

    Linux中mod相关的命令 内核模块化   mod相关命令都是用来动态加载内核模块/驱动程序模块 http://baike.baidu.com/link?url=lxiKxFvYm-UfJIxMjz ...

  8. Linux基本命令之用户系统相关命令

    1.格式说明 [simon@localhost simon]$ [simon@localhost ~]$ 这两种方式表示相同.simon是指定用户,localhost是计算机名字,如果不设置默认为lo ...

  9. redis-key相关命令

    本篇主要介绍和redis的key进行操作的相关命令. 命令 描述 复杂度 返回值 DEL key [key ...] 删除给定的一个或多个 key .不存在的 key 会被忽略.删除单个列表.集合.有 ...

随机推荐

  1. python->读写excel

    from openpyxl import load_workbook#将一个excel文档中的数据存放内存中,即变量wb保存了该excel的所有信息wb = load_workbook(r" ...

  2. python的var_dump,打印对象内容

    from __future__ import print_function from types import NoneType __author__ = "Shamim Hasnath&q ...

  3. 图像分类(二)GoogLenet Inception_v2:Batch Normalization: Accelerating Deep Network Training by Reducing Internal Covariate Shift

    Inception V2网络中的代表是加入了BN(Batch Normalization)层,并且使用 2个 3*3卷积替代 1个5*5卷积的改进版,如下图所示: 其特点如下: 学习VGG用2个 3* ...

  4. Unable to convert MySQL date/time value to System.DateTime问题解决方案

    原因:可能是该字段(date/datetime)的值默认缺省值为:0000-00-00/0000-00-00 00:00:00,这样的数据读出来转换成System.DateTime时就会有问题: 解决 ...

  5. PyQt5简介及demo

    PyQt5说明 pyqt5是一套Python绑定Digia QT5应用的框架.它可用于Python 2和3.本教程使用Python 3.Qt库是最强大的GUI库之一.pyqt5的官方网站http:// ...

  6. Python时间、日期、时间戳之间的转换

    一.字符串与为时间字符串之间的互相转换 方法:time模块下的strptime方法 a = "2012-11-11 23:40:00" # 字符串转换为时间字符串 import t ...

  7. pandas处理时间序列(1):pd.Timestamp()、pd.Timedelta()、pd.datetime( )、 pd.Period()、pd.to_timestamp()、datetime.strftime()、pd.to_datetime( )、pd.to_period()

      Pandas库是处理时间序列的利器,pandas有着强大的日期数据处理功能,可以按日期筛选数据.按日期显示数据.按日期统计数据.   pandas的实际类型主要分为: timestamp(时间戳) ...

  8. Mybatis经常被问到的面试题

    1. #{}和${}的区别是什么? #{}是预编译处理,${}是字符串替换. Mybatis在处理#{}时,会将sql中的#{}替换为?号,调用PreparedStatement的set方法来赋值: ...

  9. Git 在 windows 上面的安装

    参考博客: https://blog.csdn.net/xiezhongyuan07/article/details/79411299 将该作者的文章搬过来, 大家可以直接看上面的原文章. 下面是拷贝 ...

  10. python扩展包的升级

    检查更新:pip list --outdated 更新: pip install --upgrade xxxx