LoginSignup
169
162

More than 5 years have passed since last update.

CentOS7最小インストールからHTTP接続が接続できるまで

Last updated at Posted at 2014-09-13

VMware playerにCentOS7をインストール。
CentOS7は最小パッケージがデフォルトなので、
デフォルトでインストールしたシステムから
apache(httpd) をインストールしてつなげるまでの手順。


前提条件は

・外部からシステムに接続できる(SSHとか)ネットワークが設定完了していること

外からつながらない方は過去記事を参照のこと。
CentOS7が出たので、最小インストールからSSHが接続できるまで

・yumからパッケージがインストールできる環境であること

システムがインターネットにつながっていたら、おそらく何もしなくて大丈夫。
オフライン作業の場合は、インストールメディアからパッケージをインストールしましょう。
インストールメディアからyumする方法は過去記事参照のこと。

オフラインのCentOS7にインストールメディアからyumでパッケージをインストールする(CLI)


(1) httpd のインストール

# yum install -y httpd

細かい記載は省略します。わかるよね。


(2) HTTPサービスの起動

・起動前確認

CentOS6までによく使っていた service コマンドはなくなっています。

# service status httpd
The service command supports only basic LSB actions (start, stop, restart, try-r
estart, reload, force-reload, status). For other actions, please try to use syst
emctl.

指示された通り、systemctl コマンドを使います。

# systemctl status httpd
httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled)
   Active: inactive (dead)

Active: inactive (dead) の部分に注目します。

ポートのLISTEN状態を確認します。
こちらも CentOS6までによく使っていた netstat コマンドはデフォルトでは使用できません。

# netstat -nat
-bash: netstat: コマンドが見つかりません

ss コマンドを使用してみましょう。

# ss -nat
State      Recv-Q Send-Q        Local Address:Port          Peer Address:Port 
LISTEN     0      100               127.0.0.1:25                       *:*     
LISTEN     0      128                       *:22                       *:*     
ESTAB      0      96            192.168.101.3:22           192.168.101.1:55185 
LISTEN     0      100                     ::1:25                      :::*     
LISTEN     0      128                      :::22                      :::*     

SSH経由で接続しているので ESTAB が一つあります。
80番ポートが LISTEN していないことを確認します。

・サービスの起動

service コマンドと同様に start で起動します。

# systemctl start httpd.service

・起動後確認

再度ステータスを確認。

# systemctl status httpd.service
httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled)
   Active: active (running) since 土 2014-09-13 17:08:35 JST; 6s ago
 Main PID: 10562 (httpd)
   Status: "Processing requests..."
   CGroup: /system.slice/httpd.service
           tq10562 /usr/sbin/httpd -DFOREGROUND
           tq10563 /usr/sbin/httpd -DFOREGROUND
           tq10564 /usr/sbin/httpd -DFOREGROUND
           tq10565 /usr/sbin/httpd -DFOREGROUND
           tq10566 /usr/sbin/httpd -DFOREGROUND
           mq10567 /usr/sbin/httpd -DFOREGROUND

 9月 13 17:08:35 localhost.localdomain systemd[1]: Starting The Apache HTTP ...
 9月 13 17:08:35 localhost.localdomain httpd[10562]: AH00558: httpd: Could n...
 9月 13 17:08:35 localhost.localdomain systemd[1]: Started The Apache HTTP S...
Hint: Some lines were ellipsized, use -l to show in full.

Active: active (running) になりました。

ポートの LISTEN 状態も確認します。

# ss -nat
State      Recv-Q Send-Q        Local Address:Port          Peer Address:Port 
LISTEN     0      100               127.0.0.1:25                       *:*     
LISTEN     0      128                       *:22                       *:*     
ESTAB      0      96            192.168.101.3:22           192.168.101.1:55185 
LISTEN     0      100                     ::1:25                      :::*     
LISTEN     0      128                      :::80                      :::*     
LISTEN     0      128                      :::22                      :::*     

80番ポートの LISTEN が増えました。


(3) ファイアウォール停止

今回はとりあえず外部から接続するのが目的なので
ファイアウォールのプロセスは落としてしまいます。

CentOS6で一般的な iptables はまだ利用されていますが、
CentOS7以降では firewalld というプロセスから設定を調整し
iptables に自動的に適用する形になるようです。

iptables のコマンド自体はそのまま入りました。
現在のポリシー?も確認できます。

# iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
ACCEPT     all  --  anywhere             anywhere             ctstate RELATED,ESTABLISHED
ACCEPT     all  --  anywhere             anywhere            
(略)

httpd と同様、systemctl でサービスを落とします。

# systemctl status firewalld
firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled)
   Active: active (running) since 土 2014-09-13 16:26:23 JST; 1h 14min ago
 Main PID: 695 (firewalld)
   CGroup: /system.slice/firewalld.service
           mq695 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid

 9月 13 16:26:23 localhost.localdomain systemd[1]: Started firewalld - dynam...
Hint: Some lines were ellipsized, use -l to show in full.
#
# systemctl stop firewalld
#
# systemctl status firewalld
firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled)
   Active: inactive (dead)

 9月 13 16:26:23 localhost.localdomain systemd[1]: Started firewalld - dynam...
 9月 13 18:22:29 localhost.localdomain systemd[1]: Stopping firewalld - dyna...
 9月 13 18:22:29 localhost.localdomain systemd[1]: Stopped firewalld - dynam...
Hint: Some lines were ellipsized, use -l to show in full.

iptables も無効(というか制限なし)になりました。

# iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         

(4) アクセス確認

外部PCからアクセスしてみます。
http://<IPアドレス>/ ですね。

Win81_000240.jpg

筆者は apache 2.4 の画面をここで初めて見ました。
こじゃれてる。


(5) 自動起動サービスの登録

起動サービスとして登録する場合は CentOS6 までは chkconfig から登録していましたが
chkconfig にも出てこなくなってしまいました。

# chkconfig --list

注記: この出力は SysV サービスのみであり、ネイティブな systemd のサービスは含まれていません。
      systemd services. SysV 設定のデータはネイティブな systemd の設定によって上書きされます。
      systemd サービスを一覧表示するには 'systemctl list-unit-files' を使用してください。
      特定のターゲットにおいて有効化されているサービスを確認するには、
      'systemctl list-dependencies [target]' 。

iprdump         0:off   1:off   2:on    3:on    4:on    5:on    6:off
iprinit         0:off   1:off   2:on    3:on    4:on    5:on    6:off
iprupdate       0:off   1:off   2:on    3:on    4:on    5:on    6:off
netconsole      0:off   1:off   2:off   3:off   4:off   5:off   6:off
network         0:off   1:off   2:on    3:on    4:on    5:on    6:off

こちらも systemctl で設定するようです。
たくさん出てくるので grep します。(試しに打ってみるとわかります)

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

httpd を enable に変更します。

# systemctl enable httpd.service
ln -s '/usr/lib/systemd/system/httpd.service' '/etc/systemd/system/multi-user.ta
rget.wants/httpd.service'
#
# systemctl list-unit-files | grep httpd
httpd.service                               enabled 

firewalld も必要に応じて disable にしましょう。

# systemctl list-unit-files | grep firewall
firewalld.service                           enabled
#
# systemctl disable firewalld.service
rm '/etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service'
rm '/etc/systemd/system/basic.target.wants/firewalld.service'
#
# systemctl list-unit-files | grep firewall
firewalld.service                           disabled
#
169
162
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
169
162