サービスの自動起動設定
サービスの自動起動設定(CentOS6)
仮想専用サーバー再起動時に自動起動させたいサービスについては、サーバーにログインしroot権限でchkconfigコマンドで自動起動させたいサービスをonと設定してご使用ください。
[root@localhost ~]# chkconfig 自動起動させたいサービス名 on
たとえばhttpdを自動起動させたい場合は
[root@localhost ~]# chkconfig httpd on
を実行します。
設定の確認は以下のコマンドを実行します。
[root@localhost ~]# chkconfig --list | grep httpd httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
httpdの欄で2.3.4.5.にonが表示されていれば設定が完了しています。
その他のサービスを自動起動させたい場合も chkconfig で on と設定してご使用ください。
サービスの自動起動設定(CentOS7)
仮想専用サーバー再起動時に自動起動させたいサービスについては、サーバーにログインしroot権限でsystemctlコマンドで自動起動させたいサービスをenableと設定してご使用ください。
# systemctl enable サービス名.service
たとえばsshdを自動起動させたい場合は
[root@localhost ~]# systemctl enable sshd.service
を実行します。
設定の確認は以下のコマンドを実行します。
[root@localhost ~]# systemctl status sshd.service sshd.service - OpenSSH server daemon Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled) Active: active (running) since Mon 2015-06-08 11:57:36 JST; 1min 8s ago Main PID: 3125 (sshd) CGroup: /system.slice/sshd.service └─3125 /usr/sbin/sshd -D Jun 08 11:57:36 localhost.localdomain systemd[1]: Started OpenSSH server daemon. Jun 08 11:57:36 localhost.localdomain sshd[3125]: Server listening on 0.0.0.0 port 22. Jun 08 11:57:36 localhost.localdomain sshd[3125]: Server listening on :: port 22.
設定状態を一覧確認する場合には「systemctl list-unit-files」コマンドにて確認してください。
[root@localhost ~]# systemctl list-unit-files --type=service | grep sshd.service sshd.service enabled
network, netconsoleなどのサービス確認はCentOS6同様にchkconfigコマンドにてご確認ください。
2.3.4.5.にonが表示されていれば、サーバー起動時にサービスも自動起動します。
※disable/enableの切り替え設定は他サービス同様にsystemctlコマンドで行うことができます。
# chkconfig --list
Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration.
If you want to list systemd services use 'systemctl list-unit-files'.
To see services enabled on particular target use
'systemctl list-dependencies [target]'.
netconsole 0:off 1:off 2:on 3:on 4:on 5:on 6:off
network 0:off 1:off 2:on 3:on 4:on 5:on 6:off
サービスの自動起動設定(CentOS8、Rocky Linux8.4、Rocky Linux9.0, AlmaLinux9.3)
仮想専用サーバー再起動時に自動起動させたいサービスについては、サーバーにログインし root権限で systemctl コマンドで自動起動させたいサービスを enable と設定してご使用ください。
# systemctl enable サービス名.service
たとえばsshdを自動起動させたい場合は
[root@localhost ~]# systemctl enable sshd.service
を実行します。
設定の確認は以下のコマンドを実行します。
[root@localhost ~]# systemctl is-enabled sshd.service
enabled
設定状態を一覧確認する場合には「systemctl list-unit-files」コマンドにて確認してください。
[root@localhost ~]# systemctl list-unit-files --type=service | grep sshd.service sshd.service enabled