關閉或啟用 CentOS 7 上的 Service

回覆文章
tony
文章: 585
註冊時間: 2012-02-26, 07:04
聯繫:

關閉或啟用 CentOS 7 上的 Service

未閱讀文章 tony »

以 postfix 為例
關閉 postfix
# service postfix stop
Redirecting to /bin/systemctl stop postfix.service

預設不啟用 postfix
# chkconfig postfix off
注意:正在轉送請求至「systemctl disable postfix.service」。
rm '/etc/systemd/system/multi-user.target.wants/postfix.service'

啟動 postfix
# service postfix start
Redirecting to /bin/systemctl start postfix.service

預設啟用 postfix
# chkconfig postfix on
注意:正在轉送請求至「systemctl enable postfix.service」。
ln -s '/usr/lib/systemd/system/postfix.service' '/etc/systemd/system/multi-user.target.wants/postfix.service'
由上面可以發現 CentOS 7.x 和之前的 CentOS 6.x/5.x 處理方式有些不同

使用 service 時已經改用 systemctl 來做處理
使用 chkconfig 時,是把在 /usr/lib/systemd/system 目錄下的 service 服務名稱 在 /etc/systemd/system/multi-user.target.wants 目錄之下做建立連結或刪除連結

直接使用 systemctl 來做處理

啟動 postfix
# systemctl start postfix
# systemctl start postfix.service

關閉 postfix
# systemctl stop postfix
# systemctl stop postfix.service

預設啟用 postfix
# systemctl enable postfix
# systemctl enable postfix.service
ln -s '/usr/lib/systemd/system/postfix.service' '/etc/systemd/system/multi-user.target.wants/postfix.service'

預設不啟用 postfix
# systemctl disable postfix
rm '/etc/systemd/system/multi-user.target.wants/postfix.service'
# systemctl disable postfix.service
rm '/etc/systemd/system/multi-user.target.wants/postfix.service'

列出所有 service 的啟用狀態
# systemctl list-unit-files
UNIT FILE STATE
proc-sys-fs-binfmt_misc.automount static
dev-hugepages.mount static
dev-mqueue.mount static
proc-fs-nfsd.mount static
proc-sys-fs-binfmt_misc.mount static
sys-fs-fuse-connections.mount static
sys-kernel-config.mount static
sys-kernel-debug.mount static
tmp.mount disabled
var-lib-nfs-rpc_pipefs.mount static
brandbot.path disabled
systemd-ask-password-console.path static
systemd-ask-password-plymouth.path static
systemd-ask-password-wall.path static
session-1.scope static
session-2.scope static
session-4.scope static
abrt-ccpp.service enabled
abrt-oops.service enabled
abrt-pstoreoops.service disabled
abrt-vmcore.service enabled
abrt-xorg.service enabled
abrtd.service enabled
arp-ethers.service disabled
atd.service enabled
auditd.service enabled
[email protected] disabled
回覆文章

誰在線上

正在瀏覽這個版面的使用者:沒有註冊會員 和 2 位訪客