[CentOS] 特定のサービスの起動を確認・自動起動設定

CentS7からはサービスの確認・停止・起動・再起動などの方法がかなり変わりました。
Apache(httpd)の設定を例に記載します。

サービス起動の確認

まず、httpdが起動しているかの確認を行います。
「# systemctl list-unit-files | grep httpd」と入力します。

# systemctl list-unit-files | grep httpd
httpd.service     disabled

「httpd.service disabled」 と表示されたので、httpdは起動していません。

システムの起動

httpdの起動を確認します。

# systemctl status httpd

activeになっていないので、起動していない状態になっています。

 httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
Active: inactive (dead)
 Docs: man:httpd(8)
man:apachectl(8)

httpdを起動してみます。

# systemctl start httpd

再度ステータスを確認します。

# systemctl status httpd

active(running)と表示されたのでhttpdが起動しました。

httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
Active: active (running) since 土 2018-01-27 14:00:23 JST; 33s ago

自動起動の設定

それでは自動起動を設定してみます。
ターミナルに「# systemctl enable httpd」を入力

# systemctl enable httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.

「Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.」という表示が出れば自動起動が設定されました。

自動起動設定解除は「# systemctl disable httpd」になります。
「Removed symlink /etc/systemd/system/multi-user.target.wants/httpd.service.」という表示になり、自動設定が解除されます。



Author: webmaster