CentOS7中systemctl的使用
来源:互联网 发布:我的世界pe快速建造js 编辑:程序博客网 时间:2024/05/22 07:06
CentOS 7.x开始,CentOS开始使用systemd服务来代替daemon,原来管理系统启动和管理系统服务的相关命令全部由systemctl命令来代替。
1、原来的 service 命令与 systemctl 命令对比
此外还是二个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、设置开机启动/不启动
应用举例:
#停止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, target
应用举例:
3、systemctl特殊的用法
应用举例:
#查看网络服务是否启动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命令对比
与开关机相关的其他命令:
5、设置系统运行级别
5.1、运行级别对应表
此外还是一个getty.target用来设置tty的数量。
5.2、设置运行级别
命令格式:
systemctl [command] [unit.target]
参数详解:
command:
- get-default :取得当前的target
- set-default :设置指定的target为默认的运行级别
- isolate :切换到指定的运行级别
- unit.target :为5.1表中列出的运行级别
6、使用systemctl分析各服务之前的依赖关系
命令格式:
systemctl list-dependencies [unit] [–reverse]
–reverse
是用来检查寻哪个unit使用了这个unit
应用举例:
#获得当前运行级别的target[root@www ~]# systemctl get-defaultmulti-user.target#查看当前运行级别target(mult-user)启动了哪些服务[root@www ~]# systemctl list-dependenciesdefault.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 --reversedefault.target└─graphical.target
7、关闭网络服务
在使用systemctl关闭网络服务时有一些特殊 需要同时关闭unit.servce和unit.socket
使用systemctl查看开启的sshd服务
[root@www system]# systemctl list-units --all | grep sshdsshd-keygen.service loaded inactive dead OpenSSH Server Key Generationsshd.service loaded active running OpenSSH server daemonsshd.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.servicesystemctl stop sshd.socketsystemctl 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.servicesystemctl disable firewalld.service
- CentOS7中systemctl的使用
- CentOS7中systemctl的使用
- CentOS7中systemctl的使用
- CentOS7中systemctl的使用
- centos7中使用systemctl
- Linux中systemctl的使用
- 在CentOS7中systemctl命令
- CentOS7中systemctl命令详解
- centos7 使用systemctl管理tomcat9
- centos7使用systemctl控制nginx
- redhat7 systemctl的使用
- Linux学习总结(27)——CentOS7及以上系统的systemctl命令使用介绍
- docker中使用systemctl启动服务报错的解决办法
- docker中使用systemctl启动服务报错的解决办法
- CentOS7 增加tomcat 启动,停止,使用systemctl进行配置
- CentOS7 增加tomcat 启动,停止,使用systemctl进行配置
- CentOS7 增加tomcat 启动,停止,使用systemctl进行配置
- CentOS7 增加tomcat 启动,停止,使用systemctl进行配置
- WebSocket学习(二)——使用官方的服务器实现WebSocket
- Project Euler 26-30题
- 树——数的子结构
- Linux笔记之配置2:配置网卡信息
- webpack 升级Getting error: configuration.resolve.extensions[0] should not be empty
- CentOS7中systemctl的使用
- NDK手动指定文件再build
- WPF Control Development Unleashed(wpf控件开发揭秘) 章节二 不同的可视化类结构(未完成)
- ELK中的logstash启动后无输出
- 2017 ACM-ICPC 亚洲区(西安赛区)网络赛 C. Sum
- 剑指offer 20 顺时针打印矩阵
- Eclipse 设置控制台不打印包名+类型+@+地址
- 记一次网站渗透乌龙引发的头脑风暴
- webrtc中的位运算封装 BitBuffer