温馨提示:这篇文章已超过490天没有更新,请注意相关的内容是否还可用!
查看服务是否开机启动
systemctl list-unit-files disabled #表示禁止开机启动 enabled #表示开机启动 static #表示该服务与其他服务相关联,不能单独设置该服务的启动状态
#实用案例 [root@localhost ~]# systemctl list-unit-files | grep chronyd chronyd.service enabled [root@localhost ~]# systemctl list-unit-files | grep firewalld firewalld.service disabled
查看服务当前状态
systemctl status 服务名 active(running) #表示程序正在运行 active(exited) #表示执行一次就正常退出的服务,不在系统中执行任何的程序 active(waiting) #正在执行中,处于阻塞状态,需要等待其他程序执行完才能执行 inactive(dead) #未启动状态
vendor preset #前面表示服务当前的启动状态,后面表示服务默认的启动状态 inactive #服务关闭 enabled #服务开机启动 disabled #服务开机不启动 static #服务开机启动项被管理 failed #服务配置错误
#实用案例 [root@localhost ~]# systemctl status firewalld ● firewalld.service - firewalld - dynamic firewall daemon Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled) Active: inactive (dead) Docs: man:firewalld(1) [root@localhost ~]# systemctl status chronyd ● chronyd.service - NTP client/server Loaded: loaded (/usr/lib/systemd/system/chronyd.service; enabled; vendor preset: enabled) Active: active (running) since Fri 2023-07-28 01:25:06 EDT; 1h 51min ago Docs: man:chronyd(8) man:chrony.conf(5) Process: 689 ExecStartPost=/usr/libexec/chrony-helper update-daemon (code=exited, status=0/SUCCESS) Process: 660 ExecStart=/usr/sbin/chronyd $OPTIONS (code=exited, status=0/SUCCESS) Main PID: 675 (chronyd) CGroup: /system.slice/chronyd.service └─675 /usr/sbin/chronyd Jul 28 01:25:06 localhost.localdomain systemd[1]: Starting NTP client/server... Jul 28 01:25:06 localhost.localdomain chronyd[675]: chronyd version 3.4 starting (+CMDMON +NTP +REFCLOCK +...BUG) Jul 28 01:25:06 localhost.localdomain chronyd[675]: Frequency -7.503 +/- 0.603 ppm read from /var/lib/chro...rift Jul 28 01:25:06 localhost.localdomain systemd[1]: Started NTP client/server. Jul 28 01:25:14 localhost.localdomain chronyd[675]: Selected source 202.118.1.81 Jul 28 01:25:14 localhost.localdomain chronyd[675]: System clock wrong by 3926.276392 seconds, adjustment started Jul 28 02:30:40 localhost.localdomain chronyd[675]: System clock was stepped by 3926.276392 seconds Hint: Some lines were ellipsized, use -l to show in full.
其他实用小命令
systemctl start 服务名 #开启服务 systemctl stop 服务名 #关闭服务 systemctl status 服务名 #显示状态 systemctl restart 服务名 #重启服务 systemctl enable 服务名 #开机启动服务 systemctl disable 服务名 #禁止开机启动 systemctl list-units #查看系统中所有正在运行的服务 systemctl list-unit-files #查看系统中所有服务的开机启动状态 systemctl list-dependencies 服务名 #查看系统中服务的依赖关系 systemctl mask 服务名 #冻结服务 systemctl unmask 服务名 #解冻服务 systemctl set-default multi-user.target #开机时不启动图形界面 systemctl set-default graphical.target #开机时启动图形界面
# 修改服务配置文件后需要 systemctl daemon-reload # 设置服务开机自启动 systemctl enable postgresql.service # 查询是否自启动服务 systemctl is-enabled postgresql.service # 取消服务器开机自启动 systemctl disable postgresql.service # 显示某个 Unit 是否正在运行 systemctl is-active application.service # 显示某个 Unit 是否处于启动失败状态 systemctl is-failed application.service # 显示某个 Unit 服务是否建立了启动链接 systemctl is-enabled application.service # 查看每个服务的启动耗时 systemd-analyze blame # 查看当前运行的所有服务 systemctl list-units
文章版权声明:除非注明,否则均为柳三千运维录原创文章,转载或复制请以超链接形式并注明出处。