永久禁用初始化服务

Max*_*ell 10 httpd centos init upstart

我刚刚配置了一个运行 CentOS 6 的新 VPS,它与 Apache 一起提供。

我想禁用 Apache,因为我将使用 Nginx。

我知道我可以删除 /etc/init.d/ 中的脚本,但我不想这样做,因为它是系统附带的一个库存。我宁愿有一种优雅的方式来禁用该服务。

我以为我可以在 /etc/inittab 中放一些东西,但 inittab 包含:

# inittab is only used by upstart for the default runlevel.
#
# ADDING OTHER CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM.
#
# System initialization is started by /etc/init/rcS.conf
#
# Individual runlevels are started by /etc/init/rc.conf
#
# Ctrl-Alt-Delete is handled by /etc/init/control-alt-delete.conf
#
# Terminal gettys are handled by /etc/init/tty.conf and /etc/init/serial.conf,
# with configuration in /etc/sysconfig/init.
#
# For information on how to write upstart event handlers, or how
# upstart works, see init(5), init(8), and initctl(8).
#
# Default runlevel. The runlevels used are:
#   0 - halt (Do NOT set initdefault to this)
#   1 - Single user mode
#   2 - Multiuser, without NFS (The same as 3, if you do not have networking)
#   3 - Full multiuser mode
#   4 - unused
#   5 - X11
#   6 - reboot (Do NOT set initdefault to this)
# 
id:3:initdefault:
Run Code Online (Sandbox Code Playgroud)

这让我相信系统正在运行新贵。好吧,我看了看,在 upstart 中禁用服务的正确方法是添加一个覆盖文件。所以我运行:

% 'manual' > /etc/init/httpd.override
Run Code Online (Sandbox Code Playgroud)

并重新启动我的服务器。但是httpd还在运行!对此感到困惑,我决定通过运行来检查 upstart 是否是 init 服务

% readlink /proc/1/exe
/sbin/init
Run Code Online (Sandbox Code Playgroud)

嗯,这不是我期望看到的。也许我毕竟不是跑新贵。有没有明确的检查方法?如果我正在运行 init,永久禁用服务的推荐方法是什么?我对这一切都很陌生,似乎有很多相互矛盾的意见。

谢谢大家的帮助。

lar*_*sks 16

在几乎任何 RedHat 派生的发行版下禁用服务的方法是使用以下chkconfig命令:

# chkconfig httpd off
Run Code Online (Sandbox Code Playgroud)

并停止正在运行的服务:

# service httpd stop
Run Code Online (Sandbox Code Playgroud)

无论您的系统是运行的,还是普通的systemd,这些命令都会做正确的事情。upstartSysVInit

值得一提的是,尽管upstart在 CentOS 6 中运行大多数服务实际上使用的是遗留init.d脚本,位于/etc/rc.d/rc<RUNLEVEL>.d. 对于这些服务,chkconfig管理/etc/rc.d/init.d.


小智 5

使用chkconfig禁用您不想在系统引导期间启动的服务。

列出可用服务及其状态

chkconfig --list

在运行级别 2345 中禁用服务 htttpd

chkconfig --level 2345 httpd off