同样使用 --level 参数禁用指定运行级别下的服务,下面展示的是在运行级别 3 和运行级别 5 中禁用 httpd 服务。
# chkconfig --level 35 httpd off
如何将一个新服务添加到启动列表中
-–add 参数允许我们添加任何新的服务到启动列表中,默认情况下,新添加的服务会在运行级别 2、3、4、5 下自动开启。
# chkconfig --add nagios
如何从启动列表中删除服务
可以使用 --del 参数从启动列表中删除服务,下面展示的是如何从启动列表中删除 Nagios 服务。
# chkconfig --del nagios
如何使用 systemctl 命令启用或禁用开机自启服务?
systemctl 用于命令行,它是一个用来管理 systemd 的守护进程/服务的基础工具,例如:(开启、重启、关闭、启用、禁用、重载和状态)。
所有服务创建的 unit 文件位与 /etc/systemd/system/ 。
如何列出全部的服务
使用下面的命令列出全部的服务(包括启用的和禁用的)。
# systemctl list-unit-files --type=service UNIT FILE STATE arp-ethers.service disabled auditd.service enabled autovt@.service enabled blk-availability.service disabled brandbot.service static chrony-dnssrv@.service static chrony-wait.service disabled chronyd.service enabled cloud-config.service enabled cloud-final.service enabled cloud-init-local.service enabled cloud-init.service enabled console-getty.service disabled console-shell.service disabled container-getty@.service static cpupower.service disabled crond.service enabled . . 150 unit files listed.
使用下面的格式通过正则表达式匹配出你想要查看的服务的当前状态。下面是使用 systemctl 命令查看 httpd 服务的状态。
# systemctl list-unit-files --type=service | grep httpd httpd.service disabled
如何让指定的服务开机自启
使用下面格式的 systemctl 命令启用一个指定的服务。启用服务将会创建一个符号链接,如下可见:
# systemctl enable httpd Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
运行下列命令再次确认服务是否被启用。
# systemctl is-enabled httpd enabled
如何禁用指定的服务
运行下面的命令禁用服务将会移除你启用服务时所创建的符号链接。
# systemctl disable httpd Removed symlink /etc/systemd/system/multi-user.target.wants/httpd.service.
运行下面的命令再次确认服务是否被禁用。
# systemctl is-enabled httpd disabled
如何查看系统当前的运行级别
使用 systemctl 命令确认你系统当前的运行级别,runlevel 命令仍然可在 systemd 下工作,不过,运行级别对于 systemd 来说是一个历史遗留的概念。所以我建议你全部使用 systemctl 命令。
(编辑:青岛站长网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|