웹사이트 검색

Apache 웹 서버 로드 및 페이지 통계를 모니터링하는 방법


이 문서에서는 CentOS, CentOS와 같은 Linux 배포판의 mod_status 모듈을 사용하여 Apache 웹 서버 로드 및 요청을 모니터링하는 방법을 알아봅니다. Strong>RHEL 및 Fedora.

mod_status란 무엇입니까?

mod_status는 웹 브라우저를 통해 액세스할 수 있는 HTML 인터페이스로 웹 서버 로드와 현재 httpd 연결을 모니터링하는 데 도움이 되는 Apache 모듈입니다.

Apache의 mod_status는 웹 서버의 현재 통계에 대한 정보가 포함된 일반 HTML 페이지를 표시합니다.

  • 수신 요청의 총 수
  • 총 바이트 수 및 개수 서버
  • 웹서버의 CPU 사용량
  • 서버 로드
  • 서버 가동 시간
  • 총 트래픽
  • 총 유휴 작업자 수
  • 해당 클라이언트 등의 PID.

기본 Apache 프로젝트에서는 서버 통계 페이지를 일반 대중에게 공개했습니다. 바쁜 웹사이트의 상태 페이지에 대한 데모를 보려면 다음을 방문하세요.

  • https://status.apache.org/
테스트 환경

이 문서에서는 몇 가지 실제 예와 스크린샷을 통해 mod_status에 대해 자세히 알아보기 위해 다음 테스트 환경을 사용했습니다.

  1. 운영체제 – CentOS 8/7
  2. 애플리케이션 – Apache 웹 서버
  3. IP 주소 – 5.175.142.66
  4. DocumentRoot – /var/www/html
  5. Apache 구성 파일 – /etc/httpd/conf/httpd.conf
  6. 기본 HTTP 포트 – 80 TCP
  7. 테스트 구성 설정 – httpd -t

이 튜토리얼의 전제 조건은 기본 Apache 서버를 설치하고 구성하는 방법을 이미 알고 있어야 한다는 것입니다. Apache를 설정하는 방법을 모르는 경우 Apache 웹 서버를 설정하는 데 도움이 될 수 있는 다음 문서를 읽어보세요.

  1. 나만의 웹 서버를 만들고 Linux에서 웹 사이트 호스팅하기

Apache에서 mod_status를 활성화하는 방법

기본 Apache 설치에는 mod_status가 활성화된 상태로 제공됩니다. 그렇지 않은 경우 Apache 구성 파일에서 활성화하십시오.

[root@tecmint ~]# vi /etc/httpd/conf/httpd.conf

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 웹사이트(단일 웹사이트)에 대한 기본 구성입니다. 하나 이상의 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>

확장 상태 활성화

'확장 상태' 설정은 통계 페이지에 CPU 사용량, 초당 요청, 총 트래픽과 같은 추가 정보를 추가합니다. 등. 이를 활성화하려면 동일한 httpd.conf 파일을 편집하고 "확장"이라는 단어를 검색한 다음 해당 줄의 주석 처리를 제거하고 상태를 "On<으로 설정합니다.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 서버 상태 페이지를 올바르게 활성화하고 구성했는지 확인하십시오. 다음 명령을 사용하여 httpd.conf 구성의 오류를 확인할 수도 있습니다.

[root@tecmint ~]# httpd -t

Syntax 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가 활성화된 다음 페이지와 유사한 내용이 표시됩니다.

위 스냅샷에서 서버 가동 시간, 프로세스 ID에 대한 모든 정보를 각각과 함께 표시하는 HTML 인터페이스를 볼 수 있습니다. 클라이언트, 액세스하려는 페이지입니다.

또한 상태를 표시하는 데 사용되는 모든 약어의 의미와 사용법을 보여 주므로 상황을 더 잘 이해하는 데 도움이 됩니다.

매 초(예: 5초)마다 페이지를 새로 고쳐 업데이트된 통계를 확인할 수도 있습니다. 자동 새로고침을 설정하려면 URL 끝에 '?refresh=N'을 추가하세요. 여기서 N은 페이지를 새로 고치려는 시간(초)으로 바꿀 수 있습니다.

http://serveripaddress/server-status/?refresh=5

명령줄 상태 페이지 보기

link 또는 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 모듈은 웹 서버 활동 성능을 모니터링하기 위한 매우 편리한 모니터링 도구이며 문제 자체를 강조할 수 있습니다. 자세한 내용은 보다 성공적인 웹 서버 관리자가 되는 데 도움이 될 수 있는 상태 페이지를 읽어보세요.

  1. Apache mod_status 홈페이지

지금은 mod_status에 대한 모든 것입니다. 향후 튜토리얼에서는 Apache에 대한 더 많은 요령과 팁을 제시할 것입니다. 그때까지 Geeky를 유지하고 linux-console.net을 주목하고 소중한 의견을 추가하는 것을 잊지 마세요.