CentOS中的systemctl命令
CentOS 7.x开始,CentOS开始使用systemd服务来代替daemon,原来管理系统启动和管理系统服务的相关命令全部由systemctl命令来代替。
管理命令:
systemctl start [unit type] # 启动服务
systemctl stop [unit type] # 停止服务
systemctl restart [unit type] # 重启服务
systemctl status [unit type] # 参数来查看服务运行情况
systemctl reload [unit type] # 重新加载服务,加载更新后的配置文件并不是所有服务都支持reload,比如network.service
设置开机启动/不启动:
systemctl enable [unit type] # 设置服务开机启动
systemctl disable [unit type] # 设备服务禁止开机启动查看系统上上所有的服务
命令格式:
systemctl [command] [–type=TYPE] [–all]参数详解:
list-units:依据unit列出所有启动的unit. 加上 -all 才会列出没启动的unit; list-unit-files:依据/usr/lib/systemd/system/内的启动文件,列出启动文件列表 -type=TYPE - 为unit type, 主要有service, socket, target
例: ```shell# 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
设置系统运行级别
运行级别对应表
设置运行级别 命令格式:
参数详解: command:
get-default :取得当前的target
set-default :设置指定的target为默认的运行级别
isolate :切换到指定的运行级别
unit.target :为运行级别
使用systemctl分析各服务之前的依赖关系
命令格式:
–reverse是用来检查寻哪个unit使用了这个unit
关闭网络服务
在使用systemctl关闭网络服务时有一些特殊 需要同时关闭unit.servce和unit.socket 使用systemctl查看开启的sshd服务
可以看到系统同时开启了 sshd.service 和 sshd.socket ,如果只闭关了 sshd.service 那么 sshd.socket 还在监听网络,在网络上有要求连接 sshd 时就会启动 sshd.service .因此如果想完全关闭sshd服务的话,需要同时停用 sshd.service 和 sshd.socket .
由于centos 7.x默认没有安装net-tools,因此无法使用netstat来查看主机开发的商品.需要通过yum安装来获得该工具包:
查看是否关闭22端口
CentOS7防火墙firewall
开启,关闭,重启防火墙以及查看防火墙状态
其他服务同理
Last updated
Was this helpful?