配置文件:

  /usr/lib/systemd/system:每个服务最主要的启动脚本设置,类似于之前的/etc/init.d/

  /run/systemd/system:系统执行过程中所产生的服务脚本,比上面目录优先运行

  /etc/systemd/system:管理员建立的执行脚本,类似于/etc/rd.d/rcN.d/Sxx类的功能,比上面的目录优先级高

不兼容:

  systemctl命令固定不变,不可扩展

  非由systemd启动的服务,systemctl无法与之通信和控制

管理服务

  命令: systemctl COMMAND name.service

  启动:service name start   -->   systemctl start name.service

  停止:service name stop   -->   systemctl stop name.service

  重启:service name restart  -->   systemctl restart name.service

  状态:service name status   -->   systemctl status name.service

  条件式重启:已启动才重启,否则不做操作

  service name condrestart   -->   systemctl try-restart name.service

  重载或重启服务:先加载,再启动

    systemctl reload-or-restart name.service

  重载或条件式重启服务:

    systemctl reload-or-try-restart name.service

  重载服务

    systemctl reload name.service

  禁止自动和手动启动:

    systemctl mask name.service

  取消禁止:

    systemctl unmask name.service

服务查看:

  查看某服务当前激活与否的状态

    systemctl is-active name.service             脚本中可以根据返回值判断

  查看所有已经激活的服务

    systemctl list-units  [--type | -t]  service

  查看所有服务  

    systemctl list-units  [--type|-t]  service [--all | -a]

  列出失败的服务

    systemctl --failed [--type=service|-t service]

chkconfig命令的对应关系

  设定某服务开机自启

    chkconfig name on --> systemctl enable name.service

  设定某服务开机禁止启动

    chkconfig name off --> systemctl disable name.service

  查看是否开机启动

    systemctl is-enabled name.service       脚本中可以根据返回值判断是否启用

  查看所有服务的开机自启状态  

    chkconfig --list --> systemctl list-unit-files  [--type|-t]  service

  用来列出该服务在哪些运行级别下启用和禁用  

    chkconfig name -list -->  ls /etc/systemd/system/*.wants/name.service

  其他命令

    查看服务的依赖关系

      systemctl list-dependencies | name .service

    杀掉进程

      systemctl kill unitname

服务状态

  systemctl list-unit-files -t service -a    显示状态

  loaded                 Unit 配置文件已处理

  active(running)            一次或多次持续处理的运行

  active(exited)            成功完成一次性的配置

  active(waiting)             运行中,等待一个事件

  inactive                不运行

  enabled               开机启动

  disabled               开机不启动

  static                 开机不启动,但可被另一个启动的服务激活

  

service unit文件格式

  /etc/systemd/system:系统管理员和用户使用/usr/lib/systemd/system:发行版打包者使用

  以 “#” 开头的行后面的内容会被认为是注释

  相关布尔值,1、yes、on、true 都是开启,0、no、off、false 都是关闭

  时间单位默认是秒,所以要用毫秒(ms)分钟(m)等须显式说明

  service unit file文件通常由三部分组成:

    [Unit]:定义与Unit类型无关的通用选项;用于提供unit的描述信息、unit行为及依赖关系等

    [Service]:与特定类型相关的专用选项;此处为Service类型

    [Install]:定义由“systemctl enable”以及"systemctl disable“命令在实现服务启用或禁用时用到的一些选项

 

    Unit段的常用选项:

      Description:描述信息

      After:定义unit的启动次序,表示当前unit应该晚于哪些unit启动,其功能与Before相反

      Requires:依赖到的其它units,强依赖,被依赖的units无法激活时,当前unit也无法激活

      Wants:依赖到的其它units,弱依赖

      Conflicts:定义units间的冲突关系

  

    Service段的常用选项:

      Type:定义影响ExecStart及相关参数的功能的unit进程启动类型

      simple:默认值,这个daemon主要由ExecStart接的指令串来启动,启动后常驻于内存中

      forking:由ExecStart启动的程序透过spawns延伸出其他子程序来作为此daemon的主要服务。原生父程序在启动结束后就会终止

      oneshot:与simple类似,不过这个程序在工作完毕后就结束了,不会常驻在内存中

      dbus:与simple类似,但这个daemon必须要在取得一个D-Bus的名称后,才会继续运作.因此通常也要同时设定BusNname= 才行

      notify:在启动完成后会发送一个通知消息。还需要配合 NotifyAccess 来让 Systemd 接收消息

      idle:与simple类似,要执行这个daemon必须要所有的工作都顺利执行完毕后才会执行。这类的daemon通常是开机到最后才执行即可的服务

      EnvironmentFile:环境配置文件

      ExecStart:指明启动unit要运行命令或脚本的绝对路径

      ExecStartPre: ExecStart前运行

      ExecStartPost: ExecStart后运行

      ExecStop:指明停止unit要运行的命令或脚本

      Restart:当设定Restart=1 时,则当次daemon服务意外终止后,会再次自动启动此服务

    Install段的常用选项:

      Alias:别名,可使用systemctl command Alias.service

      RequiredBy:被哪些units所依赖,强依赖

      WantedBy:被哪些units所依赖,弱依赖

      Also:安装本服务的时候还要安装别的相关服务

  注意:对于新创建的unit文件,或者修改了的unit文件,要通知systemd重载此配置文件,而后可以选择重启

    systemctl daemon-reload

运行级别

  target units:

    unit配置文件:.target 

    ls /usr/lib/systemd/system/*.target

    systemctl list-unit-files --type target --all

  运行级别:

    0 ==> runlevel0.target, poweroff.target

    1 ==> runlevel1.target, rescue.target

    2 ==> runlevel2.target, multi-user.target

    3 ==> runlevel3.target, multi-user.target

    4 ==> runlevel4.target, multi-user.target

    5 ==> runlevel5.target, graphical.target

    6 ==> runlevel6.target, reboot.target

  查看依赖性:

    systemctl list-dependencies graphical.target

  级别切换:init N ==> systemctl isolate name.target

    注:只有/lib/systemd/system/*.target文件中AllowIsolate=yes 才能切换(修改文件需执行systemctl daemon-reload才能生效)

  查看target:

    runlevel ; who -r

    systemctl list-units --type target

  查看默认运行级别:

    /etc/inittab ==> systemctl get-default

  修改默认级别:

    /etc/inittab ==> systemctl set-default name.target

      systemctl set-default multi-user.target

      ls –l /etc/systemd/system/default.target

  切换至紧急救援模式:

    systemctl rescue

  切换至emergency模式:

    systemctl emergency

  其他常用命令:

    传统命令init,poweroff,halt,reboot都成为systemctl的软链接

    关机:systemctl halt、systemctl poweroff

    重启:systemctl reboot

    挂起:systemctl suspend

    休眠:systemctl hibernate

    休眠并挂起:systemctl hybrid-sleep

CentOS7下systemd的更多相关文章

  1. CentOs7下systemd管理知识要点

    centOs7的一个巨大的变动就是用systemd取代了原来的System V init.systemd是一个完整的软件包,安装完成后有很多物理文件组成,大致分布为,配置文件位于/etc/system ...

  2. centOS7下安装GUI图形界面

    1.如何在centOS7下安装GUI图形界面 当你安装centOS7服务器版本的时候,系统默认是不会安装GUI的图形界面程序,这个需要手动安装CentOS7 Gnome GUI包. 2.在系统下使用命 ...

  3. docker(一) Centos7下安装docker

    docker(一) Centos7下安装dockerdocker(二) windows10下安装dockerdocker(三) 镜像和容器常用命令 docker(四) 使用Dockerfile构建镜像 ...

  4. centos7的systemd命令对比

    centos7的systemd命令对比 http://www.linuxidc.com/Linux/2014-09/106490p2.htmhttp://www.linuxidc.com/Linux/ ...

  5. Centos7 下的SVN安装与配置

    Centos7 下的SVN安装与配置 1.关闭防火墙 临时关闭防火墙 systemctl stop firewalld 永久防火墙开机自关闭 systemctl disable firewalld 临 ...

  6. MariaDB Centos7 下安装MariaDB

    Centos7 下安装MariaDB by:授客 QQ:1033553122 1.下载安装文件 rpm包为例,对于标准服务器安装,至少需要下载client,shared,serve文件(安装时如果少了 ...

  7. centos7上systemd详解

    centos7上systemd详解  发表于 2016-06-07 |  分类于 linux CentOS 7继承了RHEL 7的新的特性,例如强大的systemd, 而systemd的使用也使得以往 ...

  8. Centos7 下安装以及使用mssql

    Centos7下安装以及使用Mssql,在这下面玩,主要是发现linux环境下的mysql非常的小,小到只有169M,这在windows上面,动撤几个G的安装文件,会让你直接打消使用MSSQL的勇气, ...

  9. CentOS7下利用init.d启动脚本实现tomcat开机自启动

    在之前的博文中已经对CentOS7下通过tomcat进行WEB系统的发布进行了介绍,今天将利用init.d启动脚本,将服务脚本加入到开机启动服务队列,实现tomcat服务的开机启动. 1. 环境准备 ...

随机推荐

  1. PHP命名大小写敏感规则

    一直觉得PHP中各种大小写规则理不清,就连工作多年的老手们也不一定能对PHP大小写敏感问题足够了解.在PHP中,大小写敏感问题的处理比较乱,大家一定要注意.即使某些地方大小写不敏感,但在编程过程中能始 ...

  2. Linux下FTP用户的使用配置

    1.创建本地账户,用户名为自己的姓名拼音,使用本地用户测试,从以下几个方面来观察,账户 .密码.访问目录(可否查看上级目录) .上传下载的权限.

  3. 常见的div布局面试题

    题目1:如何让一个子元素在父元素里水平垂直居中? 方法1 .box{width:400px;height:400px;background:#ccc;position:relative;} .chil ...

  4. Js 文件上传后缀验证

    //img格式验证 function imgFormat(name) { //再对文件名进行截取,以取得后缀名 var namearr= name.split("."); //获取 ...

  5. python之set集合、深浅拷贝

    一.基本数据类型补充 1,关于int和str在之前的学习中已经介绍了80%以上了,现在再补充一个字符串的基本操作: li = ['李嘉诚','何炅','海峰','刘嘉玲'] s = "_&q ...

  6. Kendo MVVM 数据绑定(二) Checked

    Kendo MVVM 数据绑定(二) Checked Checked 绑定用在 checkbox ()或 radio button ()上.注意: checked 绑定只适用于支持 checked 的 ...

  7. springmvc学习经验

    Spring MVC属于SpringFrameWork的后续产品,已经融合在Spring Web Flow里面.Spring 框架提供了构建 Web 应用程序的全功能 MVC 模块.使用 Spring ...

  8. Linux 系统挂载阿里云数据盘

    适用系统:Linux(Redhat , CentOS,Debian,Ubuntu) *  Linux的云服务器数据盘未做分区和格式化,可以根据以下步骤进行分区以及格式化操作. 下面的操作将会把数据盘划 ...

  9. python+selenium之处理HTML5的视频播放

    from selenium import webdriver from time import sleep driver = webdriver.Firefox() driver.get(" ...

  10. Python +selenium之设置元素等待

    注:本文转载http://www.cnblogs.com/mengyu/p/6972968.html 当浏览器在加载页面时,页面上的元素可能并不是同时被加载完成,这给元素的定位增加了困难.如果因为在加 ...