Linux系统服务的控制

时间:2022-11-06 16:07:46

1.systemctl 命令

systemctl list-units                ##列出当前系统服务的状态
systemctl list-unit-files ##列出服务的开机状态
systemctl status sshd ##查看指定服务的状态
systemctl stop sshd ##关闭指定服务
systemctl start sshd ##开启指定服务
systemctl restart sshd ##从新启动服务
systemctl enable sshd ##设定指定服务开机开启
systemctl disable sshd ##设定指定服务开机关闭
systemctl reload sshd ##使指定服务从新加载配置
systemctl list-dependencies sshd ##查看指定服务的倚赖关系
systemctl mask sshd ##冻结指定服务
systemctl unmask sshd ##启用服务
systemctl set-default multi-user.target ##开机不开启图形
systemctl set-default graphical.target ##开机启动图形
setterm ##文本界面设定color

2.查看服务状态

例:查看firewalld的服务状态

[root@foundation32 ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
Active: active (running) since Sun 2017-07-23 09:16:43 CST; 1h 59min ago
Main PID: 631 (firewalld)
CGroup: /system.slice/firewalld.service
└─631 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid

Jul 23 09:16:43 foundation32.ilt.example.com systemd[1]: Starting firewalld -...
Jul 23 09:16:43 foundation32.ilt.example.com systemd[1]: Started firewalld - ...
Hint: Some lines were ellipsized, use -l to show in full.