systemctl 命令

systemctl 是一个 systemd 工具,主要负责控制 systemd 系统和服务管理器。

systemd 是一个系统管理守护进程、工具和库的集合,用于取代 System V 初始进程。

systemd 的功能是用于集中管理和配置 Linux 系统。

以网络服务 network.service 为例:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
#查看服务状态
systemctl status network.service

#启动服务
systemctl start network.service

#重启服务
systemctl restart network.service

#停止服务
systemctl stop network.service

#开机启动服务
systemctl enable network.servic

#停止开机启动
systemctl disable network.servic

#清理 systemd 失效的服务
systemctl reset-failed mongodb.service

查找所有或者某个服务

1
systemctl list-units --type=service | grep network

systemctl 接受服务(.service),挂载点(.mount),套接口(.socket)和设备(.device)作为单元

列出所有可用单元

1
systemctl list-unit-files

列出所有运行中单元

1
systemctl list-units

列出所有失败单元

1
systemctl --failed

使用systemctl命令杀死服务

1
systemctl kill network.service

列出所有系统挂载点

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
systemctl list-unit-files --type=mount

UNIT FILE                     STATE   
dev-hugepages.mount           static  
dev-mqueue.mount              static  
proc-sys-fs-binfmt_misc.mount static  
sys-fs-fuse-connections.mount static  
sys-kernel-config.mount       static  
sys-kernel-debug.mount        static  
tmp.mount                     disabled

挂载、卸载、重新挂载、重载系统挂载点并检查系统中挂载点状态

1
2
3
4
5
systemctl start tmp.mount
systemctl stop tmp.mount
systemctl restart tmp.mount
systemctl reload tmp.mount
systemctl status tmp.mount