Apache Web サーバーの負荷とページ統計を監視する方法
この記事では、CentOS などの Linux ディストリビューションの mod_status モジュールを使用して Apache Web サーバーの負荷とリクエストを監視する方法を学習します。RHEL とFedora です。
mod_statusとは何ですか?
mod_status は、Web ブラウザ経由でアクセスできる HTML インターフェイスを使用して、Web サーバーの負荷と現在の httpd 接続を監視するのに役立つ Apache モジュールです。
Apache の mod_status は、Web サーバーの現在の統計に関する情報を含むプレーン HTML ページを表示します。
- 受信リクエストの総数
- サーバーの合計バイト数とカウント数
- WebサーバーのCPU使用率
- サーバー負荷
- サーバー稼働時間
- 総トラフィック量
- アイドル状態のワーカーの総数
- それぞれのクライアントの PID など。
デフォルトの Apache プロジェクトでは、サーバー統計ページを一般公開できるようになりました。ビジーな Web サイトのステータス ページのデモを参照するには、にアクセスしてください。
- https://status.apache.org/
テスト環境
この記事では、mod_status について詳しく調べるために、いくつかの実用的な例とスクリーンショットを使用して、次のテスト環境を使用しました。
- オペレーティング システム – CentOS 8/7
- アプリケーション – Apache Web サーバー
- IP アドレス – 5.175.142.66
- ドキュメントルート – /var/www/html
- Apache 設定ファイル – /etc/httpd/conf/httpd.conf
- デフォルトの HTTP ポート – 80 TCP
- テスト構成設定 – httpd -t
このチュートリアルの前提条件は、基本的な Apache サーバーのインストールおよび構成方法をすでに理解していることです。 Apache のセットアップ方法がわからない場合は、独自の Apache Web サーバーのセットアップに役立つ次の記事をお読みください。
- Linux で独自の Web サーバーを作成して Web サイトをホスティングする
Apache で mod_status を有効にする方法
デフォルトの Apache インストールでは、mod_status が有効になっています。そうでない場合は、Apache 構成ファイルで必ず有効にしてください。
[root@tecmint ~]# vi /etc/httpd/conf/httpd.conf
「mod_status 」という単語を検索するか、「mod_status 」を含む行が見つかるまで下にスクロールし続けます。
#LoadModule status_module modules/mod_status.so
「LoadModule」の先頭に「#」文字が表示されている場合は、mod_status が無効になっていることを意味します。 mod_status を有効にするには、「#」を削除します。
LoadModule status_module modules/mod_status.so
mod_statusを構成する
ここでもう一度「Location 」という単語を検索するか、次のような mod_status のセクションが見つかるまで下にスクロールします。
Allow server status reports generated by mod_status,
with the URL of http://servername/server-status
Change the ".example.com" to match your domain to enable.
#
#<Location /server-status>
SetHandler server-status
Order deny,allow
Deny from all
Allow from .example.com
#</Location>
上のセクションで、必要に応じて場所ディレクティブ、SetHandler、およびディレクトリ制限の行のコメントを解除します。たとえば、注文の許可と拒否をすべてに許可することでシンプルにしています。
<Location /server-status>
SetHandler server-status
Order allow,deny
Deny from all
Allow from all
</Location>
注: 上記の設定は、デフォルトの Apache Web サイト (単一 Web サイト) のデフォルト設定です。 1 つ以上の Apache 仮想ホストを作成している場合、上記の構成は機能しません。
したがって、基本的には、Apache で構成したドメインの仮想ホストごとに同じ構成を定義する必要があります。たとえば、mod_status の仮想ホスト構成は次のようになります。
<VirtualHost *:80>
ServerAdmin [email
DocumentRoot /var/www/html/example.com
ServerName example.com
ErrorLog logs/example.com-error_log
CustomLog logs/example.com-access_log common
<Location /server-status>
SetHandler server-status
Order allow,deny
Deny from all
Allow from example.com
</Location>
</VirtualHost>
拡張ステータスを有効にする
「ExtendedStatus」設定では、CPU 使用率、1 秒あたりのリクエスト、総トラフィックなどの詳細情報を統計ページに追加します。など。有効にするには、同じhttpd.conf ファイルを編集して「拡張」という単語を検索し、行のコメントを解除してステータスを「オン<」に設定します。 」 ExtendedStatus ディレクティブ。
ExtendedStatus controls whether Apache will generate "full" status
information (ExtendedStatus On) or just basic information (ExtendedStatus
Off) when the "server-status" handler is called. The default is Off.
#
ExtendedStatus On
Apacheを再起動する
ここで、Apache サーバー ステータス ページが正しく有効化され、設定されていることを確認してください。次のコマンドを使用して、httpd.conf 設定のエラーを確認することもできます。
[root@tecmint ~]# httpd -t
Syntax OK
構文がOKであることを確認したら、httpdサービスを再起動できます。
[root@tecmint ~]# service httpd restart
OR
[root@tecmint ~]# systemctl restart httpd
Stopping httpd: [ OK ]
Starting httpd: [ OK ]
mod_statusページにアクセスする
Apache ステータス ページには、次の URL にある「/server-status」を含むドメイン名からアクセスできます。
http://serveripaddress/server-status
OR
http://serev-hostname/server-status
ExtendedStatus が有効になっていると、次のページのようなものが表示されます。
上のスナップショットでは、サーバー稼働時間に関するすべての情報を表示するHTMLインターフェイスとプロセスIDとそのそれぞれの情報が表示されていることがわかります。クライアント、アクセスしようとしているページ。
また、ステータスの表示に使用されるすべての略語の意味と使用法も示されており、状況をより深く理解するのに役立ちます。
また、数秒 (たとえば5 秒) ごとにページを更新して、更新された統計を確認することもできます。自動更新を設定するには、URL の末尾に「?refresh=N」 を追加してください。 N は、ページを更新する秒数に置き換えることができます。
http://serveripaddress/server-status/?refresh=5
コマンドラインステータスページビュー
リンクまたは lynx と呼ばれる特別なコマンドライン ブラウザを使用して、コマンドライン インターフェイスから Apache ステータス ページを表示することもできます。以下に示すように、yum と呼ばれるデフォルトのパッケージ マネージャー ユーティリティを使用してこれらをインストールできます。
yum install links
OR
yum install lynx
をインストールしたら、次のコマンドを使用して端末で同じ統計を取得できます。
[root@tecmint ~]# links http://serveripaddress/server-status
OR
[root@tecmint ~]# lynx http://serveripaddress/server-status
OR
[root@tecmint ~]# /etc/init.d/httpd fullstatus
サンプル出力
Apache Server Status for localhost
Server Version: Apache/2.2.15 (Unix) DAV/2 PHP/5.3.3
Server Built: Aug 13 2013 17:29:28
--------------------------------------------------------------------------
Current Time: Tuesday, 14-Jan-2014 04:34:13 EST
Restart Time: Tuesday, 14-Jan-2014 00:33:05 EST
Parent Server Generation: 0
Server uptime: 4 hours 1 minute 7 seconds
Total accesses: 2748 - Total Traffic: 9.6 MB
CPU Usage: u.9 s1.06 cu0 cs0 - .0135% CPU load
.19 requests/sec - 695 B/second - 3658 B/request
1 requests currently being processed, 4 idle workers
.__.__W...
Scoreboard Key:
"_" Waiting for Connection, "S" Starting up, "R" Reading Request,
"W" Sending Reply, "K" Keepalive (read), "D" DNS Lookup,
"C" Closing connection, "L" Logging, "G" Gracefully finishing,
"I" Idle cleanup of a worker, "." Open slot with no current process
Srv PID Acc M CPU SS Req Conn Child Slot Client VHost Request
0-0 - 0/0/428 . 0.30 5572 0 0.0 0.00 1.34 127.0.0.1 5.175.142.66 OPTIONS * HTTP/1.0
GET
1-0 5606 0/639/639 _ 0.46 4 0 0.0 2.18 2.18 115.113.134.14 5.175.142.66 /server-status?refresh=5
HTTP/1.1
GET
2-0 5607 0/603/603 _ 0.43 0 0 0.0 2.09 2.09 115.113.134.14 5.175.142.66 /server-status?refresh=5
HTTP/1.1
3-0 - 0/0/337 . 0.23 5573 0 0.0 0.00 1.09 127.0.0.1 5.175.142.66 OPTIONS * HTTP/1.0
GET
4-0 5701 0/317/317 _ 0.23 9 0 0.0 1.21 1.21 115.113.134.14 5.175.142.66 /server-status?refresh=5
HTTP/1.1
GET
5-0 5708 0/212/213 _ 0.15 6 0 0.0 0.85 0.85 115.113.134.14 5.175.142.66 /server-status?refresh=5
HTTP/1.1
6-0 5709 0/210/210 W 0.16 0 0 0.0 0.84 0.84 127.0.0.1 5.175.142.66 GET /server-status
HTTP/1.1
7-0 - 0/0/1 . 0.00 5574 0 0.0 0.00 0.00 127.0.0.1 5.175.142.66 OPTIONS * HTTP/1.0
--------------------------------------------------------------------------
Srv Child Server number - generation
PID OS process ID
Acc Number of accesses this connection / this child / this slot
M Mode of operation
CPU CPU usage, number of seconds
SS Seconds since the beginning of the most recent request
Req Milliseconds required to process most recent request
Conn Kilobytes transferred this connection
Child Megabytes transferred this child
Slot Total megabytes transferred this slot
--------------------------------------------------------------------------
Apache/2.2.15 (CentOS) Server at localhost Port 80
結論
Apache の mod_status モジュールは、Web サーバーのアクティビティのパフォーマンスを監視するための非常に便利な監視ツールであり、問題自体を強調表示できます。詳細については、Web サーバー管理者としてより成功するために役立つステータス ページをお読みください。
- Apache mod_status ホームページ
現時点では mod_status についてはこれですべてです。今後のチュートリアルでは、Apache に関するさらにいくつかのトリックやヒントを紹介します。それまでは、Geeky のままで linux-console.net をチェックし、貴重なコメントを追加することを忘れないでください。