系统服务管理systemd  Control the systemd system and service manager

控制systemd系统和服务管理,并行启动服务时充分发挥了多核处理器的性能,缩短了系统启动所需时间。

先前的使用SysV初始化或Upstart的红帽企业版Linux版本中,使用位于/etc/rc.d/init.d/目录中的bash初始化脚本进行管理。

在RHEL 7/CentOS 7中,这些启动脚本被服务单元取代了。为了向后兼容,旧的service命令在CentOS 7中仍然可用,它会重定向所有命令到新的systemctl工具。

systemctl有很多控制参数,这里仅列出常用的部分,更多命令请看man systemctl

查看systemd进程号

[root@localhost ~]# pidof systemd

  单元命令

systemctl start httpd.service # 启动httpd # service httpd start
systemctl stop httpd.service # 停止httpd # service httpd stop
systemctl status httpd # 查看httpd状态 # service httpd status
systemctl restart httpd.service # 重启httpd # service httpd restart
systemctl try-restart httpd.service # 尝试重启httpd #
systemctl reload httpd.service # 重新加载httpd配置文件 #
systemctl enable sshd.service # 设置sshd开机启动 # chkconfig –level sshd on systemctl disable sshd.service # 设置sshd开机不启动 # chkconfig –level sshd off
systemctl enable sshd.service --now  -f # 设置自启的同时,立即启动sshd服务, 强制创建并覆盖冲突链接
systemctl disable sshd.service --now # 设置禁用的同时,立即停止sshd服务
systemctl enable mariadb --no-block --no-reload # 异步操作,不等待结果,不重载配置文件
systemctl disable mariadb --global # 对全局所有在线用户生效
systemctl list-units --type=service # 列出type为service的所有服务的启动状况 # chkconfig –list systemctl list-units --state=failed # 查询state为failed的单元 systemctl list-units --state=loaded --type=socket # 列出已加载的类型为socket的单元
systemctl list-units --plain --no-pager # 分类列出系统单元,直接输出所有结果,不分页

systemctl is-active mariadb.service # 查询mariadb服务状态
systemctl is-enabled mariadb.service # 查询mariadb是否开机自启

  系统命令

systemctl is-system-running  # running 系统完全可控;degraded 系统可控,但存在单元失败;maintenance 营救模式启动;stopping 管理器停止
systemctl suspend  #系统挂起
systemctl hibernate  #系统睡眠
systemctl daemon-reload  #操作系统所有初始化脚本重载
systemctl get-default # 获得默认的系统target systemctl set-default multi-user.target #设置默认的运行目标 systemctl isolate graphical.target #切换到图形界面

自动启动的原理:systemd控制着sysv所管理的程序脚本,由此实现了对sysv的兼容,脚本软连接重定向到chkconfig来管理,系统启动的init进程为systemd,

systemd所管理的程序脚本在/usr/lib/systemd/,而 /etc/systemd/下的都是软连接。操作系统init进程只有systemd这一个。

Created symlink from /etc/systemd/system/multi-user.target.wants/sshd.service to /usr/lib/systemd/system/sshd.service.

[dream361@za ~]$ sudo  systemctl enable network
network.service is not a native service, redirecting to /sbin/chkconfig.
Executing /sbin/chkconfig network on

network 实际是被chkconfig直接管理,systemctl通过chkconfig实现了对network的间接管理

【Linux init】systemd 服务单元管理的更多相关文章

  1. Linux之systemd服务配置及自动重启

    layout: post title: Linux之systemd服务配置及自动重启 date: 2019-09-09 tags: linux --- Linux之systemd服务配置及自动重启 0 ...

  2. linux 下mysql服务的管理

    一.mysql服务的管理 1.1 mysql启动与关闭 linux下启动mysql: /etc/init.d/mysqld start 关闭进程: ps -ef | grep mysql 找到进程号 ...

  3. CentOS 7下设置Docker代理(Linux下Systemd服务的环境变量配置)

    Docker守护程序使用HTTP_PROXY,HTTPS_PROXY以及NO_PROXY环境变量在其启动环境来配置HTTP或HTTPS代理的行为.无法使用daemon.json文件配置这些环境变量. ...

  4. fedora23禁用不需要的服务?--systemd服务单元?

    sign up: 签约; 登记, 注册. i'll sign up and go to the front and fight. he persuaded the company to sign up ...

  5. 在 Linux 系统中如何管理 systemd 服务

    在上一篇文章<Linux的运行等级与目标>中,我介绍过 Linux 用 systemd 来取代 init 作为系统的初始化进程.尽管这一改变引来了很多争议,但大多数发行版,包括 RedHa ...

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

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

  7. Linux软件安装——服务管理的命令

    Linux软件安装——服务管理的命令 摘要:本文主要学习了Linux系统中服务管理的命令. service命令 service命令用于对系统服务进行管理,比如启动(start).停止(stop).重启 ...

  8. Linux软件安装——服务管理

    Linux软件安装——服务管理 摘要:本文主要学习了Linux中有关服务管理的知识. 什么是服务 服务一般是放置在后台运行的一个或多个进分程,为用户或系统提供某项特定的服务,有些是系统服务,有些则是独 ...

  9. linux 学习 12 服务管理

      第十二讲 Linux服务管理 12.1 Linux服务管理-服务分类 ——Linux服务 ----RPM包默认安装的服务 ————独立的服务 ————基于xinetd服务 ----源码包安装的服务 ...

随机推荐

  1. centos7安装nodejs

    方法一.https://github.com/nodesource/distributions#rpminstall 按照上面地址中的教程安装完后,使用node -v命令报错: -bash: /usr ...

  2. Ambari安装之部署 (Metrics Collector和 Metrics Monitor) Install Pending ...问题

    问题的由来 我这里,是因为,拿这个Ambari Metrics服务在做试验!所以先删除它,再添加它,出现了安装被挂起的问题.... Am bari里如何删除某指定的服务(图文详解) 问题详细描述如下: ...

  3. 富文本编辑器UEditor自定义工具栏(一、基础配置与字体、背景色、行间距、超链接实现)

    导读:UEditor 是由百度「FEX前端研发团队」开发的所见即所得富文本web编辑器,功能强大,可定制,是一款优秀的国产在线富文本编辑器,编辑器内可插入图片.音频.视频等. 一.UEditor自定义 ...

  4. 机器学习 —— 基础整理(三)生成式模型的非参数方法: Parzen窗估计、k近邻估计;k近邻分类器

    本文简述了以下内容: (一)生成式模型的非参数方法 (二)Parzen窗估计 (三)k近邻估计 (四)k近邻分类器(k-nearest neighbor,kNN) (一)非参数方法(Non-param ...

  5. 使用Visual Studio加断点调试Unity游戏的C#代码

    1.安装Unity5.2.5 2.安装Microsoft Visual Studio 2013 3.打开VS2013,点击Tools | Extensions and Updates,然后在这个界面点 ...

  6. (转)log4j(一)——为什么要用log4j?

    1 试验环境 OS:win7 JDK:jdk7 Log4j:1.2.17(好尴尬,原本是想试验下log4j2的,结果阴差阳错用了这个版本,不过幸好,试验也不白试验,试验的作用是一样的) 2 先看两个简 ...

  7. 第一回:Scrapy的试水

    前言:今天算是见到Scrapy的第二天,之前只是偶尔查了查,对于这个框架的各种解释,我-----都-----看------不------懂----,没办法,见面就是刚. 目的:如题,试水 目标:< ...

  8. JavaScript系统学习小结——Object类型、Array类型

    今天学习JavaSript中引用变量中的Object类型和Array类型: 1. Js中大多数引用类型值都是Object类型的实例,Object类型在应用程序中存储和传输数据时,是非常理想的选择: 创 ...

  9. Zend Framework1 框架入门(针对Windows,包含安装配置与数据库增删改查)

    最近公司接的项目需要用到Zend Framework框架,本来需要用的是ZendFramework2 ,但是由于原有代码使用了ZendFramework1 框架,所以顺带学习了.现将一些基础入门记录一 ...

  10. mysql控制台出现“unknown column 'password' in 'field list'问题

    今天在windows系统上使用MySQL命令时,出现下面的"unknown column 'password' in 'field list'问题 解决办法如下,使用authenticati ...