其它综合-有关service、systemctl、chkconfig、init
有关service、systemctl、chkconfig、init
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
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
2.2 查看系统上所有的服务
命令格式:
systemctl [command] [–type=TYPE] [–all]
参数详解:
command- list-units:依据unit列出所有启动的unit。加上–all才会列出没启动的unit;- list-unit-files:依据/usr/lib/systemd/system/内的启动文件,列出启动文件列表
–type=TYPE为unit type, 主要有service、socket、arget
应用举例:
| 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
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 | poweroff.target |
| 1 | rescue.target |
| 2 | multi-user.target |
| 3 | multi-user.target |
| 4 | multi-user.target |
| 5 | graphical.target |
| 6 | reboot.target |
此外还是一个
getty.target用来设置tty的数量。
5.2 设置运行级别
命令格式:
systemctl [command] [unit.target]
参数详解:
command:
get-default:取得当前的targetset-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]
–reverse是用来检查寻哪个 unit 使用了这个 unit
应用举例:
#获得当前运行级别的target
[root@oldboyedu ~]# systemctl get-default
multi-user.target
#查看当前运行级别target(mult-user)启动了哪些服务
[root@oldboyedu ~]# 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@oldboyedu ~]# systemctl list-dependencies --reverse
default.target
└─graphical.target
7. 关闭网络服务
在使用
systemctl关闭网络服务时有一些特殊 需要同时关闭unit.servce和unit.socket
使用
systemctl查看开启的sshd服务
[root@oldboyedu ~]# 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
可以看到系统同时开启了
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
由于
centos 7.x默认没有安装net-tools,因此无法使用netstat来查看主机开发的商品。需要通过yum安装来获得该工具包:
yum -y install net-tools
查看是否关闭 22 端口
netstat -lnp |grep sshd
8. 关闭防火墙firewall
Centos 7.x中取消了iptables, 用firewall取而代之。要关闭防火墙并禁止开机启动服务使用下面的命令:
systemctl stop firewalld.service
systemctl disable firewalld.service
其它综合-有关service、systemctl、chkconfig、init的更多相关文章
- Centos7下的systemctl命令与service和chkconfig
博主使用的操作系统是最新的CentOS 7,所以可能和网上一些老的博文有一定出入,那是因为版本更新的原因. 这里写图片描述1 service service命令用于对系统服务进行管理,比如启动(sta ...
- RHEL 7 中 systemctl 的用法(替代service 和 chkconfig)
1.systemctl是RHEL 7 的服务管理工具中主要的工具,它融合之前service和chkconfig的功能于一体.可以使用它永久性或只在当前会话中启用/禁用服务. systemctl可以列出 ...
- Centos7 服务 service 设置命令 systemctl 用法 (替代service 和 chkconfig)
在Centos 中 systemctl 是设置系统服务的命令,即 service , 它融合之前service和chkconfig的功能于一体. 可以使用它永久性或只在当前会话中启用/禁用服务 ...
- Systemctl和service、chkconfig命令的关系
systemctl命令:是一个systemd工具,主要负责控制systemd系统和服务管理器. service命令:可以启动.停止.重新启动和关闭系统服务,还可以显示所有系统服务的当前状态. ch ...
- 把编译安装的httpd 实现服务脚本,通过service和chkconfig 进行管理
把编译安装的httpd 实现服务脚本,通过service和chkconfig 进行管理 1 编译安装httpd 把httpd编译安装在/app/httpd/目录下. 2 在/etc/rc.d/init ...
- 编译安装的httpd实现服务脚本,通过service和chkconfig进行管理
把编译安装的httpd 实现服务脚本,通过service和chkconfig 进行管理 1 编译安装httpd 把httpd编译安装在/app/httpd/目录下. 2 在/etc/rc.d/init ...
- centos 的系统管理命令 service systemctl
centos 的 systemctl 命令 systemctl is-enabled *.service #查询服务是否开机启动 systemctl enable *.service # ...
- systemctl命令是系统服务管理器指令,它实际上将 service 和 chkconfig 这两个命令组合到一起。
1.centos 检查服务是否开机自启 (ntpd是原生的服务,mysql是注册的服务) 参考:1.http://man.linuxde.net/systemctl
- Service、chkconfig命令
转自:http://my.oschina.net/phptiger86/blog/137656
随机推荐
- 2019前端面试题汇总(主要为Vue)
摘要: 经典面试题. 原文:2019前端面试题汇总(主要为Vue) 作者:前端小酱 Fundebug经授权转载,版权归原作者所有. 毕业之后就在一直合肥小公司工作,没有老司机.没有技术氛围,在技术的道 ...
- 微信小程序异步请求问题
微信小程序为了提高用户体验,提供的api大部分都是异步操作,除了数据缓存操作里面有一些同步操作.是提高了用户体验,但是在开发的时候, 就有点坑了,例如我要写一个公共方法,发起网络请求,去后台去一些数据 ...
- 浏览器登录Dynamics 365 CE没毛病,程序连接却报错。
摘要: 微软动态CRM专家罗勇 ,回复308或者20190308可方便获取本文,同时可以在第一间得到我发布的最新博文信息,follow me!我的网站是 www.luoyong.me . 今天我做实验 ...
- DevOps 工程师实际上是做什么的
DevOps 工程师实际上是做什么的? 我们之前已经讨论过许多关于DevOps和DevOps世界的最新趋势了.但是DevOps工程师到底是做什么的? DevOps工程师以最纯粹的方式弥合了软件开发和运 ...
- leetcode-48.旋转图像
leetcode-48.旋转图像 point: 数组 题意 给定一个 n × n 的二维矩阵表示一个图像. 将图像顺时针旋转 90 度. 说明: 你必须在原地旋转图像,这意味着你需要直接修改输入的二维 ...
- Oracle 10g 应用补丁PSU 10.2.0.5.180717
最近测试了一下在Oracle 10g下面(单实例下面)升级.应用补丁PSU 10.2.0.5.180717,打这个补丁的主要原因是 Oracle 将于 2019年6月启用新的SCN兼容性,并且由于Bi ...
- jQuery如何制作动画
下面为一组图片(四张)展示 1 2 3 4 页面代码如下: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN& ...
- LeetCode算法题-Binary Search(Java实现)
这是悦乐书的第297次更新,第316篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第165题(顺位题号是704).给定n个元素的排序(按升序)整数数组nums和目标值,编 ...
- Blink: How Alibaba Uses Apache Flink
This is a guest post from Xiaowei Jiang, Senior Director of Alibaba’s search infrastructure team. Th ...
- supervisor 工具 配置
配置supervisor工具,管理django后台 supervisor管理进程,是通过fork/exec的方式将这些被管理的进程当作supervisor的子进程来启动,所以我们只需要将要管理进程的可 ...