2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

EC2インスタンスにApacheをインストールするメモ

Posted at

はじめに

  • AWS EC2インスタンスにApacheをインストールしたときの諸々のメモです
  • 誤りがあればご指摘ください

前提

  • EC2インスタンスにSSH接続できている状態

EC2のライブラリをアップデートする

sudo yum update -y
  • EC2を立ち上げたら最新の状態のライブラリにアップデートする
  • yum = Linuxのパッケージ管理ツール。yumで管理しているパッケージを最新化できる
  • yumコマンドはec2-userの権限では実行できないため、rootユーザーの権限(sudo)で実行する
  • -y :yesオプション。付けないとライブラリを逐一インストールするか尋ねられて面倒

Apacheのインストール

sudo yum -y install httpd
  • HTTPD はApacheを構成する実行ファイルのこと

Apacheの起動

sudo systemctl start httpd.service
  • コマンド実行しただけだと起動しているかわからない

Apacheが起動しているか確認する

sudo systemctl status httpd.service
実行結果
httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
   Active: active (running) since 日 2023-01-29 05:18:53 UTC; 34s ago
     Docs: man:httpd.service(8)
 Main PID: 485 (httpd)
   Status: "Total requests: 0; Idle/Busy workers 100/0;Requests/sec: 0; Bytes served/sec:   0 B/sec"
   CGroup: /system.slice/httpd.service
           ├─485 /usr/sbin/httpd -DFOREGROUND
           ├─486 /usr/sbin/httpd -DFOREGROUND
           ├─487 /usr/sbin/httpd -DFOREGROUND
           ├─488 /usr/sbin/httpd -DFOREGROUND
           ├─489 /usr/sbin/httpd -DFOREGROUND
           └─490 /usr/sbin/httpd -DFOREGROUND
  • Active: active となっていたら起動できている

Apacheの起動確認 (プロセスを確認する)

ps -axu
  • ps :Linux上で実行しているプロセスを表示する
  • -ax :すべて表示する
  • u :CPUやメモリ使用率をあわせて表示させる
実行結果(一部省略)
root       485  0.0  0.9 255484  9444 ?        Ss   05:18   0:00 /usr/sbin/httpd -DFOREGROUND
apache     486  0.0  0.6 306872  6440 ?        Sl   05:18   0:00 /usr/sbin/httpd -DFOREGROUND
apache     487  0.0  0.6 536312  6440 ?        Sl   05:18   0:00 /usr/sbin/httpd -DFOREGROUND
apache     488  0.0  0.6 306872  6440 ?        Sl   05:18   0:00 /usr/sbin/httpd -DFOREGROUND
apache     489  0.0  0.6 306872  6440 ?        Sl   05:18   0:00 /usr/sbin/httpd -DFOREGROUND
apache     490  0.0  0.6 306872  6440 ?        Sl   05:18   0:00 /usr/sbin/httpd -DFOREGROUND

↑この表示があれば、Apacheが起動している

httpdに絞ってプロセスを確認する

ps -axu | grep httpd
  • | パイプライン :左の実行結果を次の実行に使いたいときに使用

Apacheを自動で起動させる

sudo systemctl enable httpd.service
  • 通常、毎回Apacheの起動コマンドを入力する必要がある
  • これを行うことで自動起動をオンにできる

Apacheの自動機能ができているか?確認する

sudo systemctl is-enabled httpd.service
  • enabled と表示されたら起動できている

どのポート番号にどのプログラムが待ち受けているか確認するコマンド

sudo lsof -i -n -P
  • -i :ネットワークソケットファイルを表示するオプション。サーバーの待機ポートとプロセスを一覧表示する
  • -n :IPアドレスをホスト名に変換しないオプション
  • -P :ポート番号をサービス名に変換しないオプション
実行結果
COMMAND    PID     USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
rpcbind   2623      rpc    6u  IPv4  15828      0t0  UDP *:111
rpcbind   2623      rpc    7u  IPv4  15829      0t0  UDP *:669
rpcbind   2623      rpc    8u  IPv4  15830      0t0  TCP *:111 (LISTEN)
rpcbind   2623      rpc    9u  IPv6  15831      0t0  UDP *:111
rpcbind   2623      rpc   10u  IPv6  15832      0t0  UDP *:669
rpcbind   2623      rpc   11u  IPv6  15833      0t0  TCP *:111 (LISTEN)
chronyd   2659   chrony    5u  IPv4  16417      0t0  UDP 127.0.0.1:323
chronyd   2659   chrony    6u  IPv6  16418      0t0  UDP [::1]:323
dhclient  2876     root    6u  IPv4  16846      0t0  UDP *:68
dhclient  2925     root    5u  IPv6  17054      0t0  UDP [fe80::4bd:b9ff:feed:6e61]:546
master    3070     root   13u  IPv4  17978      0t0  TCP 127.0.0.1:25 (LISTEN)
sshd      3221     root    3u  IPv4  19769      0t0  TCP *:22 (LISTEN)
sshd      3221     root    4u  IPv6  19778      0t0  TCP *:22 (LISTEN)
sshd     32720     root    3u  IPv4  55233      0t0  TCP 10.0.10.13:22->122.134.104.0:5178 (ESTABLISHED)
sshd     32738 ec2-user    3u  IPv4  55233      0t0  TCP 10.0.10.13:22->122.134.104.0:5178 (ESTABLISHED)
  • LISTEN :他のPCから待ち受けているポート
  • ESTABLISHED : 相手と現在通信中のポート
sshd      3221     root    3u  IPv4  19769      0t0  TCP *:22 (LISTEN)

sshdというプログラムが、22番ポートで待ち受けているよ、という意味
* (アスタリスク):どの接続元のIPでも受け付けるよ、という意味

2
0
0

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
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?