CentOS6系LinuxでのOS起動時のサービス自動起動は、chkconfigコマンドを使用しますがCentOS7系Linuxではsystemctlコマンドで制御する方法に変更になっています。
合わせて、サービス起動禁止化(mask)についての方法も記載します。
サービス自動起動の確認
全てのサービスを確認する場合は「systemctl list-unit-files -t service」を実行します。
各サービスに対するSTATEの説明は以下の通りです。
enabled | 自動起動ON |
disabled | 自動起動OFF |
static | 依存関係によって起動されるサービス |
[root@cent77 ~]# systemctl list-unit-files -t service
UNIT FILE STATE
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
autovt@.service enabled
blk-availability.service disabled
brandbot.service static
chrony-dnssrv@.service static
chrony-wait.service disabled
chronyd.service enabled
console-getty.service disabled
console-shell.service disabled
container-getty@.service static
cpupower.service disabled
crond.service enabled
dbus-org.fedoraproject.FirewallD1.service enabled
dbus-org.freedesktop.hostname1.service static
dbus-org.freedesktop.import1.service static
dbus-org.freedesktop.locale1.service static
dbus-org.freedesktop.login1.service static
dbus-org.freedesktop.machine1.service static
dbus-org.freedesktop.nm-dispatcher.service enabled
dbus-org.freedesktop.timedate1.service static
dbus.service static
debug-shell.service disabled
dm-event.service static
dmraid-activation.service enabled
dracut-cmdline.service static
dracut-initqueue.service static
dracut-mount.service static
dracut-pre-mount.service static
dracut-pre-pivot.service static
dracut-pre-trigger.service static
dracut-pre-udev.service static
dracut-shutdown.service static
ebtables.service disabled
emergency.service static
firewalld.service enabled
fprintd.service static
fstrim.service static
getty@.service enabled
halt-local.service static
initrd-cleanup.service static
initrd-parse-etc.service static
initrd-switch-root.service static
initrd-udevadm-cleanup-db.service static
iprdump.service disabled
iprinit.service disabled
iprupdate.service disabled
irqbalance.service enabled
kdump.service enabled
kmod-static-nodes.service static
kpatch.service disabled
libstoragemgmt.service enabled
lvm2-lvmetad.service static
lvm2-lvmpolld.service static
lvm2-monitor.service enabled
lvm2-pvscan@.service static
mdadm-grow-continue@.service static
mdadm-last-resort@.service static
mdcheck_continue.service static
mdcheck_start.service static
mdmon@.service static
mdmonitor-oneshot.service static
mdmonitor.service enabled
messagebus.service static
microcode.service enabled
mysqld.service enabled
mysqld@.service disabled
NetworkManager-dispatcher.service enabled
NetworkManager-wait-online.service enabled
NetworkManager.service enabled
nfs-rquotad.service disabled
ntpdate.service disabled
plymouth-halt.service disabled
plymouth-kexec.service disabled
plymouth-poweroff.service disabled
plymouth-quit-wait.service disabled
plymouth-quit.service disabled
plymouth-read-write.service disabled
plymouth-reboot.service disabled
plymouth-start.service disabled
plymouth-switch-root.service static
polkit.service static
psacct.service disabled
qemu-guest-agent.service enabled
quotaon.service static
rc-local.service static
rdisc.service disabled
rescue.service static
rhel-autorelabel-mark.service enabled
rhel-autorelabel.service enabled
rhel-configure.service enabled
rhel-dmesg.service enabled
rhel-domainname.service enabled
rhel-import-state.service enabled
rhel-loadmodules.service enabled
rhel-readonly.service enabled
rngd.service enabled
rpc-rquotad.service disabled
rpcbind.service enabled
rsyncd.service disabled
rsyncd@.service static
rsyslog.service enabled
selinux-policy-migrate-local-changes@.service static
serial-getty@.service disabled
smartd.service enabled
sshd-keygen.service static
sshd.service enabled
sshd@.service static
sysstat.service enabled
systemd-ask-password-console.service static
systemd-ask-password-plymouth.service static
systemd-ask-password-wall.service static
systemd-backlight@.service static
systemd-binfmt.service static
systemd-bootchart.service disabled
systemd-firstboot.service static
systemd-fsck-root.service static
systemd-fsck@.service static
systemd-halt.service static
systemd-hibernate-resume@.service static
systemd-hibernate.service static
systemd-hostnamed.service static
systemd-hwdb-update.service static
systemd-hybrid-sleep.service static
systemd-importd.service static
systemd-initctl.service static
systemd-journal-catalog-update.service static
systemd-journal-flush.service static
systemd-journald.service static
systemd-kexec.service static
systemd-localed.service static
systemd-logind.service static
systemd-machine-id-commit.service static
systemd-machined.service static
systemd-modules-load.service static
systemd-nspawn@.service disabled
systemd-poweroff.service static
systemd-quotacheck.service static
systemd-random-seed.service static
systemd-readahead-collect.service enabled
systemd-readahead-done.service indirect
systemd-readahead-drop.service enabled
systemd-readahead-replay.service enabled
systemd-reboot.service static
systemd-remount-fs.service static
systemd-rfkill@.service static
systemd-shutdownd.service static
systemd-suspend.service static
systemd-sysctl.service static
systemd-timedated.service static
systemd-tmpfiles-clean.service static
systemd-tmpfiles-setup-dev.service static
systemd-tmpfiles-setup.service static
systemd-udev-settle.service static
systemd-udev-trigger.service static
systemd-udevd.service static
systemd-update-done.service static
systemd-update-utmp-runlevel.service static
systemd-update-utmp.service static
systemd-user-sessions.service static
systemd-vconsole-setup.service static
teamd@.service static
tuned.service enabled
usb_modeswitch@.service static
vdo.service enabled
wpa_supplicant.service disabled
173 unit files listed.
自動起動をOFF(無効化)にする
「systemctl disable <サービス名>」で自動起動をOFFにできます。
今回はtuned.service(動的にチューニングしてくれるサービス)を自動起動OFFにしてみます。
★事前確認
[root@cent77 ~]# systemctl list-unit-files -t service |grep tuned
tuned.service enabled
★自動起動OFF
[root@cent77 ~]# systemctl disable tuned.service
Removed symlink /etc/systemd/system/multi-user.target.wants/tuned.service.
★事後確認
[root@cent77 ~]# systemctl list-unit-files -t service |grep tuned
tuned.service disabled
サービスを起動させないようにする
「systemctl mask <サービス名>」で手動でのサービス起動を禁止にすることもできます。
★起動状態の確認
[root@cent77 ~]# systemctl status tuned.service
* tuned.service - Dynamic System Tuning Daemon
Loaded: loaded (/usr/lib/systemd/system/tuned.service; disabled; vendor preset: enabled)
Active: active (running) since Sun 2020-03-29 21:18:46 JST; 3h 48min ago
Docs: man:tuned(8)
man:tuned.conf(5)
man:tuned-adm(8)
Main PID: 1094 (tuned)
CGroup: /system.slice/tuned.service
`-1094 /usr/bin/python2 -Es /usr/sbin/tuned -l -P
Mar 29 21:18:42 cent77 systemd[1]: Starting Dynamic System Tuning Daemon...
Mar 29 21:18:46 cent77 systemd[1]: Started Dynamic System Tuning Daemon.
★起動しているのでtuned.serviceを停止する
[root@cent77 ~]# systemctl stop tuned.service
★サービス起動を禁止(mask)する
[root@cent77 ~]# systemctl mask tuned.service
Created symlink from /etc/systemd/system/tuned.service to /dev/null.
★確認
[root@cent77 ~]# systemctl list-unit-files -t service |grep tuned
tuned.service masked
★起動しようとするとエラーになります
[root@cent77 ~]# systemctl start tuned.service
Failed to start tuned.service: Unit is masked.