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

CentS7からはサービスの確認・停止・起動・再起動などの方法がかなり変わりました。
Apache(httpd)の設定を例に記載します。
Contents
サービス起動の確認
まず、httpdが起動しているかの確認を行います。
「# systemctl list-unit-files | grep httpd」と入力します。
1 2 |
# systemctl list-unit-files | grep httpd httpd.service disabled |
「httpd.service disabled」 と表示されたので、httpdは起動していません。
システムの起動
httpdの起動を確認します。
1 |
# systemctl status httpd |
activeになっていないので、起動していない状態になっています。
1 2 3 4 5 |
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を起動してみます。
1 |
# systemctl start httpd |
再度ステータスを確認します。
1 |
# systemctl status httpd |
active(running)と表示されたのでhttpdが起動しました。
1 2 3 |
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」を入力
1 2 |
# 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.」という表示になり、自動設定が解除されます。
関連記事
- [vsftpd] インストールとCentOSのfirewallの設定
- [CentOS 7x] Firewalldが動かない
- [Linux] CentOSでApacheをインストールする方法
- [Apache] エラー対処方法 Job for httpd.service failed because the control process exited with error code
- [Linux] FTPサーバー vsftpd の設定(vsftpd.conf)