CentOS7中systemctl的使用与CentOS6中service的区别
https://blog.csdn.net/u012834750/article/details/80501440
从CentOS 7.x开始,CentOS开始使用systemd服务来代替daemon,
原来管理系统启动和管理系统服务的相关命令全部由systemctl命令来代替。
1、原来的 service 命令与 systemctl 命令对比
| daemon命令 | systemctl命令 | 说明 |
|---|---|---|
| service [服务] start | systemctl start [unit type] | 启动服务 |
| service [服务] stop | systemctl stop [unit type] | 停止服务 |
| service [服务] restart | systemctl restart [unit type] | 重启服务 |
此外还是二个systemctl参数没有与service命令参数对应
- status:参数来查看服务运行情况
- reload:重新加载服务,加载更新后的配置文件(并不是所有服务都支持这个参数,比如network.service)
应用举例:
#启动网络服务
systemctl start network.service
#停止网络服务
systemctl stop network.service
#重启网络服务
systemctl restart network.service
#查看网络服务状态
systemctl status network.serivce
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
2、原来的chkconfig 命令与 systemctl 命令对比
2.1、设置开机启动/不启动
| daemon命令 | systemctl命令 | 说明 |
|---|---|---|
| chkconfig [服务] on | systemctl enable [unit type] | 设置服务开机启动 |
| chkconfig [服务] off | systemctl disable [unit type] | 设备服务禁止开机启动 |
应用举例:
#停止cup电源管理服务
systemctl stop cups.service
#禁止cups服务开机启动
systemctl disable cups.service
#查看cups服务状态
systemctl status cups.service
#重新设置cups服务开机启动
systemctl enable cups.service
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
2.2、查看系统上上所有的服务
命令格式:
systemctl [command] [–type=TYPE] [–all]
- 1
参数详解:
command – list-units:依据unit列出所有启动的unit。加上 –all 才会列出没启动的unit; – list-unit-files:依据/usr/lib/systemd/system/ 内的启动文件,列出启动文件列表
–type=TYPE – 为unit type, 主要有service, socket, target
应用举例:
| systemctl命令 | 说明 |
|---|---|
| systemctl | 列出所有的系统服务 |
| systemctl list-units | 列出所有启动unit |
| systemctl list-unit-files | 列出所有启动文件 |
| systemctl list-units –type=service –all | 列出所有service类型的unit |
| systemctl list-units –type=service –all grep cpu | 列出 cpu电源管理机制的服务 |
| systemctl list-units –type=target –all | 列出所有target |
3、systemctl特殊的用法
| systemctl命令 | 说明 |
|---|---|
| systemctl is-active [unit type] | 查看服务是否运行 |
| systemctl is-enable [unit type] | 查看服务是否设置为开机启动 |
| systemctl mask [unit type] | 注销指定服务 |
| systemctl unmask [unit type] | 取消注销指定服务 |
应用举例:
#查看网络服务是否启动
systemctl is-active network.service
#检查网络服务是否设置为开机启动
systemctl is-enable network.service
#停止cups服务
systemctl stop cups.service
#注销cups服务
systemctl mask cups.service
#查看cups服务状态
systemctl status cups.service
#取消注销cups服务
systemctl unmask cups.service
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
4、init 命令与systemctl命令对比
| init命令 | systemctl命令 | 说明 |
|---|---|---|
| init 0 | systemctl poweroff | 系统关机 |
init 6 |systemctl reboot |重新启动
与开关机相关的其他命令:
| systemctl命令 | 说明 |
|---|---|
| systemctl suspend | 进入睡眠模式 |
| systemctl hibernate | 进入休眠模式 |
| systemctl rescue | 强制进入救援模式 |
| systemctl emergency | 强制进入紧急救援模式 |
5、设置系统运行级别
5.1、运行级别对应表
| init级别 | systemctl target |
|---|---|
| 0 | shutdown.target |
| 1 | emergency.target |
| 2 | rescure.target |
| 3 | multi-user.target |
| 4 | 无 |
| 5 | graphical.target |
| 6 | 无 |
此外还是一个getty.target用来设置tty的数量。
5.2、设置运行级别
命令格式:
systemctl [command] [unit.target]
- 1
参数详解:
command:
- 1
- get-default :取得当前的target
- set-default :设置指定的target为默认的运行级别
- isolate :切换到指定的运行级别
- unit.target :为5.1表中列出的运行级别
| systemctl命令 | 说明 |
|---|---|
| systemctl get-default | 获得当前的运行级别 |
| systemctl set-default multi-user.target | 设置默认的运行级别为mulit-user |
| systemctl isolate multi-user.target | 在不重启的情况下,切换到运行级别mulit-user下 |
| systemctl isolate graphical.target | 在不重启的情况下,切换到图形界面下 |
6、使用systemctl分析各服务之前的依赖关系
命令格式:
systemctl list-dependencies [unit] [–reverse]
- 1
–reverse是用来检查寻哪个unit使用了这个unit
应用举例:
#获得当前运行级别的target
[root@www ~]# systemctl get-default
multi-user.target
#查看当前运行级别target(mult-user)启动了哪些服务
[root@www ~]# systemctl list-dependencies
default.target
├─abrt-ccpp.service
├─abrt-oops.service
├─vsftpd.service
├─basic.target
│ ├─alsa-restore.service
│ ├─alsa-state.service
.....(中间省略).....
│ ├─sockets.target
│ │ ├─avahi-daemon.socket
│ │ ├─dbus.socket
.....(中间省略).....
│ ├─sysinit.target
│ │ ├─dev-hugepages.mount
│ │ ├─dev-mqueue.mount
.....(中间省略).....
│ └─timers.target
│ └─systemd-tmpfiles-clean.timer
├─getty.target
│ └─getty@tty1.service
└─remote-fs.target
#查看哪些target引用了当前运行级别的target
[root@www ~]# systemctl list-dependencies --reverse
default.target
└─graphical.target
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
7、关闭网络服务
在使用systemctl关闭网络服务时有一些特殊 需要同时关闭unit.servce和unit.socket
使用systemctl查看开启的sshd服务
[root@www system]# systemctl list-units --all | grep sshd
sshd-keygen.service loaded inactive dead OpenSSH Server Key Generation
sshd.service loaded active running OpenSSH server daemon
sshd.socket loaded inactive dead OpenSSH Server Socket
- 1
- 2
- 3
- 4
- 5
可以看到系统同时开启了 sshd.service 和 sshd.socket , 如果只闭关了 sshd.service 那么 sshd.socket还在监听网络,在网络上有要求连接 sshd 时就会启动 sshd.service 。因此如果想完全关闭sshd服务的话,需要同时停用 sshd.service 和 sshd.socket 。
systemctl stop sshd.service
systemctl stop sshd.socket
systemctl disable sshd.service sshd.socket
- 1
- 2
- 3
由于centos 7.x默认没有安装net-tools,因此无法使用netstat 来查看主机开发的商品。需要通过yum安装来获得该工具包:
yum -y install net-tools
- 1
查看是否关闭22端口
netstat -lnp |grep sshd
- 1
8、关闭防火墙firewall
Centos 7.x 中取消了iptables, 用firewall取而代之。要关闭防火墙并禁止开机启动服务使用下面的命令:
systemctl stop firewalld.service
systemctl disable firewalld.service
- 1
- 2
CentOS7中systemctl的使用与CentOS6中service的区别的更多相关文章
- 关于centos7和centos6中平滑升级nginx到新版本v1.12.1修复nginx最新漏洞CVE-2017-7529的解决方案
关于centos7和centos6中平滑升级nginx到新版本v1.12.1修复CVE-2017-7529漏洞的解决方案 漏洞描述 2017年7月11日,Nginx官方发布最新的安全公告,在Nginx ...
- centos7 centos6中 更改默认的系统启动级别
centos6中更改默认的启动级别 方法: 1.vi /etc/inittab 2.找到id:x:initdefault:,我的系统是id:3:initdefault:,即默认以字符模式启动. 3.将 ...
- CentOS7.2中systemctl的使用
CentOS 7.x开始,CentOS开始使用systemd服务来代替daemon,原来管理系统启动和管理系统服务的相关命令全部由systemctl命令来代替. 1.原来的 service 命令与 s ...
- 在centos6中编译安装httpd-2.4/搭建LAMP
首先确保centos6安装平台安装一下环境: #yum groupinstall "Development Tools" "Server Platform Develo ...
- CentOS7开启docker远程访问并在idea中连接使用
CentOS7开启docker远程访问并在idea中连接使用 1.编辑/usr/lib/systemd/system/docker.service,配置远程访问.主要是在[Service]这个部分,添 ...
- Systemd初始化进程/RHEL 6系统中System V init命令与RHEL 7系统中systemctl命令的对比
Linux操作系统的开机过程是这样的,即从BIOS开始,然后进入Boot Loader,再加载系统内核,然后内核进行初始化,最后启动初始化进程.初始化进程作为Linux系统的第一个进程,它需要完成Li ...
- Linux中systemctl命令详细介绍
Linux Systemctl是一个系统管理守护进程.工具和库的集合,用于取代System V.service和chkconfig命令,初始进程主要负责控制systemd系统和服务管理器.通过Syst ...
- CentOS 7.X 中systemctl命令用法详解
systemctl是RHEL 7 的服务管理工具中主要的工具,它融合之前service和chkconfig的功能于一体.可以使用它永久性或只在当前会话中启用/禁用服务,下面来看CentOS 7.X 中 ...
- centos7.x 将普通用户加入sudoers中,获取sudo执行权限
centos7.x 将普通用户加入sudoers中,获取sudo执行权限 0 问题由来 你在提起兴致学习的时候,兴冲冲地往黑洞洞的文本窗口输入下一行: [pan@localhost ~]$ sud ...
随机推荐
- 3237: [Ahoi2013]连通图 线段树分治
题解: cf765f cf671e bzoj4184 bzoj4552 线段树分治裸题 还是介绍一下线段树分治 这个东西其实挺简单但也挺有用的 可以把删除+插入操作变成只有插入(倒着就是删除) 像这一 ...
- day5模块学习--re正则模块
1. 正则表达式基础 1.1. 简单介绍 正则表达式并不是Python的一部分.正则表达式是用于处理字符串的强大工具,拥有自己独特的语法以及一个独立的处理引擎,效率上可能不如str自带的方法,但功能十 ...
- BZOJ1036 [ZJOI2008]树的统计Count 树链剖分
欢迎访问~原文出处——博客园-zhouzhendong 去博客园看该题解 题目传送门 - BZOJ1036 题意概括 一个树,每个节点有一个权值.3种操作. 1:修改某一个节点的权值. 2:询问某两个 ...
- In Action HDU3339
这是最短路问题和01背包问题的相结合 第一次用01背包 把j打成了i检查了半个小时 下次要注意! 使用的油耗相当于容量 而power相当于价值 先用dijkstra把从基地到所有路的最短情况算出来 ...
- 010 Spark中的监控----日志聚合的配置,以及REST Api
一:History日志聚合的配置 1.介绍 Spark的日志聚合功能不是standalone模式独享的,是所有运行模式下都会存在的情况 默认情况下历史日志是保存到tmp文件夹中的 2.参考官网的知识点 ...
- 《Gradle权威指南》--Android Gradle多项目构建
No1: Android多项目设置 目录结构: MyProject/ setting.gradle app/ build.gradle libraries/ lib1/ build.gradle li ...
- 001.Docker简介概述
一 简介 Docker最初是dotCloud公司的一个内部项目,诞生于 2013 年初,由google公司开源的Go语言开发. Docker是一个开源的引擎,可以轻松的为任何应用创建一个轻量级的.可移 ...
- Python图形编程探索系列-03-标签组件(Label)
跳转到自己的博客 tkinter.Label介绍 什么是标签? 通俗的将就相当于word的功能,能够进行显示不可修改的文字.图片或者图文混排. 直观体会一下 图1 背景图构成:内容区(黑色),填充区( ...
- crm的知识点整理
''' # 1. 通过ChangeList封装好多数据 # 2. 销售中公共资源:Q查询,3天 15天 from django.db.models import F,Q F 使用查询条件的值,专门取对 ...
- C memset
//#include "stdafx.h" #include <iostream> #include <memory.h> using namespace ...