Linux 服务器之 systemctl 命令使用详解
# systemctl介绍
systemctl主要负责控制systemd系统和服务管理器。在ubuntu 、centos等一系列发行版中可用。可以方便的管理需要启动的服务等。可以实现开机自启动、出错重启和定时重启等等功能。
# systemctl管理命令
#语法
systemctl COMMAND name.service
#启动
systemctl start name.service
#停止
systemctl stop name.service
#重启
systemctl restart name.service
#查看状态
systemctl status name.service
#禁止自动和手动启动
systemctl mask name.service
#取消禁止
systemctl unmask name.service
#查看哪些已经设置了开机启动
systemctl list-unit-files | grep enable
#查看某服务当前激活与否的状态:
systemctl is-active name.service
#查看所有已经激活的服务:
systemctl list-units --type|-t service
#查看所有服务:
systemctl list-units --type service --all
#设定某服务开机自启,相当于chkconfig name on
systemctl enable name.service
#设定某服务开机禁止启动:相当于chkconfig name off
systemctl disable name.service
#查看所有服务的开机自启状态,相当于chkconfig --list
systemctl list-unit-files --type service
#用来列出该服务在哪些运行级别下启用和禁用:chkconfig –list name
ls /etc/systemd/system/*.wants/name.service
#查看服务是否开机自启:
systemctl is-enabled name.service
#列出失败的服务
systemctl --failed --type=service
#开机并立即启动或停止
systemctl enable --now postfix
systemctl disable --now postfix
#查看服务的依赖关系:
systemctl list-dependencies name.service
#杀掉进程:
systemctl kill unitname
#重新加载配置文件
systemctl daemon-reload
#关机
systemctl halt、systemctl poweroff
#重启:
systemctl reboot
#挂起:
systemctl suspend
#休眠:
systemctl hibernate
#休眠并挂起:
systemctl hybrid-sleep
#查看某个systemctl状态
journalctl -u xxx.service
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
上次更新: 2024/05/29, 17:27:32
- 01
- Node与GLIBC_2.27不兼容解决方案08-19
- 02
- Git清空本地文件跟踪缓存08-13