웹사이트 검색

Ubuntu 14.04 LTS에서 Munin 및 Monit로 서버 모니터링


이 튜토리얼은 다음 OS 버전에 대해 존재합니다.

  • 우분투 16.04(Xenial Xerus)
  • 우분투 14.04 LTS(Trusty Tahr)

이 페이지에서

  1. 1 서문
  2. 2 Munin 설치 및 구성
  3. 3 Munin 출력 디렉토리를 암호로 보호(선택 사항이지만 적극 권장)\n
  4. 4 Munin에서 추가 모듈 활성화\n
  5. 5 ISPConfig에서 Munin 구성(선택 사항)\n

이 튜토리얼에서는 Munin 및 Monit를 사용하여 Ubuntu 14.04 서버를 모니터링하는 방법을 보여줍니다. Munin은 서버의 거의 모든 측면에 대한 멋진 그래프를 생성하는 반면 Monit는 Apache, MySQL, Postfix와 같은 서비스의 가용성을 확인하고 서비스가 예상대로 작동하지 않는 경우 재시작과 같은 적절한 조치를 취합니다. 이 둘의 조합은 완전한 모니터링을 제공합니다. 즉, 현재 또는 향후 문제를 인식할 수 있는 그래픽과 모니터링되는 서비스의 가용성을 보장하는 워치독입니다. 이 자습서에는 Munin 및 Monit를 ISPConfig에 통합하는 방법에 대한 두 개의(선택 사항) 장이 포함되어 있습니다.

1 서문

시스템 호스트 이름은 server1.example.com이고 문서 루트가 /var/www/www.example.com/web인 웹사이트 www.example.com이 있습니다.

다음 단계는 루트 사용자로 수행해야 합니다. 서버에서 루트 사용자가 되려면 다음 명령을 실행하십시오.

sudo su

Munin 설치를 시작하기 전에 시스템이 최신 상태인지 확인하고 다음을 실행하십시오.

apt-get update
apt-get upgrade

Apache는 Munin 페이지를 표시하는 데 사용되며 Munin 그래프 줌 기능에는 apache fcgid 모듈이 필요합니다. 아파치와 libapache2-mod-fcgid 모듈을 apt로 설치하겠습니다.

apt-get install apache2 libcgi-fast-perl libapache2-mod-fcgid

Apache에서 fcgid 모듈을 활성화합니다.

a2enmod fcgid

2 Munin 설치 및 구성

Ubuntu 14.04에 Munin을 설치하려면 아래 명령을 실행하십시오.

apt-get install munin munin-node munin-plugins-extra

서버가 MySQL 또는 MariaDB를 실행 중인 경우 몇 가지 추가 Munin 플러그인을 활성화하여 MySQL을 모니터링합니다.

cd /etc/munin/plugins
ln -s /usr/share/munin/plugins/mysql_ mysql_
ln -s /usr/share/munin/plugins/mysql_bytes mysql_bytes
ln -s /usr/share/munin/plugins/mysql_queries mysql_queries
ln -s /usr/share/munin/plugins/mysql_slowqueries mysql_slowqueries
ln -s /usr/share/munin/plugins/mysql_threads mysql_threads

다음으로 Munin 구성 파일 /etc/munin/munin.conf를 편집해야 합니다. dbdir, htmldir, logdir, rundir 및 tmpldir 행의 주석을 제거하십시오(기본값이 좋습니다). Munin이 HTML 출력에서 localhost.localdomain 대신 server1.example.com이라는 이름을 사용하기를 원하므로 단순 호스트 트리 섹션에서 localhost.localdomain을 server1.example.com으로 바꿉니다. 주석이 없으면 변경된 파일은 다음과 같습니다.

nano /etc/munin/munin.conf
# Example configuration file for Munin, generated by 'make build'

# The next three variables specifies where the location of the RRD
# databases, the HTML output, logs and the lock/pid files. They all
# must be writable by the user running munin-cron. They are all
# defaulted to the values you see here.
#
dbdir /var/lib/munin
htmldir /var/cache/munin/www
logdir /var/log/munin
rundir /var/run/munin

# Where to look for the HTML templates
#
tmpldir /etc/munin/templates

# Where to look for the static www files
#
#staticdir /etc/munin/static

# temporary cgi files are here. note that it has to be writable by
# the cgi user (usually nobody or httpd).
#
# cgitmpdir /var/lib/munin/cgi-tmp # (Exactly one) directory to include all files from. includedir /etc/munin/munin-conf.d [...] # a simple host tree
[server1.example.com]
address 127.0.0.1
use_node_name yes [...]

Munin /etc/munin/apache.conf에 대한 Apache 구성 파일을 찾아야 합니다. 이 파일은 munin이라는 별칭을 munin HTML 출력 디렉토리 /var/cache/munin/www에 정의합니다. 이는 munin에 액세스할 수 있음을 의미합니다. 상대 경로 /munin(예: http://www.example.com/munin)을 사용하여 이 서버의 모든 웹사이트에서.

Ubuntu 14.04와 함께 제공되는 apache.conf 파일에는 여전히 apache 2.4에 맞지 않는 이전 apache 2.2 구문이 포함되어 있으므로 해당 파일을 새 파일로 교체합니다. 먼저 이전 파일을 백업합니다.

mv /etc/munin/apache.conf /etc/munin/apache.conf_bak

편집기로 새 파일을 엽니다.

nano /etc/munin/apache.conf

그리고 아래 내용을 붙여넣습니다.

Alias /munin /var/cache/munin/www
<Directory /var/cache/munin/www>
# Require local
Require all granted
Options FollowSymLinks SymLinksIfOwnerMatch
Options None
</Directory>

ScriptAlias /munin-cgi/munin-cgi-graph /usr/lib/munin/cgi/munin-cgi-graph
<Location /munin-cgi/munin-cgi-graph>
# Require local
Require all granted
Options FollowSymLinks SymLinksIfOwnerMatch
<IfModule mod_fcgid.c>
SetHandler fcgid-script
</IfModule>
<IfModule !mod_fcgid.c>
SetHandler cgi-script
</IfModule>
</Location>

아파치를 다시 시작합니다.

service apache2 restart

그런 다음 Munin을 다시 시작하십시오.

service munin-node restart

이제 Munin이 첫 번째 출력을 생성할 수 있도록 몇 분 정도 기다린 다음 브라우저에서 http://www.example.com/munin/으로 이동하면 첫 번째 통계가 표시됩니다.

(이것은 munin이 생성하는 많은 그래픽의 일부일 뿐입니다...)

3 Munin 출력 디렉터리를 암호로 보호(선택 사항이지만 적극 권장)

이제 모든 사람이 서버에 대한 모든 작은 통계를 볼 수 있기를 원하지 않는 한 munin 출력 디렉토리를 암호로 보호하는 것이 좋습니다.

이렇게 하려면 암호 파일 /etc/munin/munin-htpasswd를 만들어야 합니다. 사용자 이름 admin으로 로그인하고 싶으므로 다음을 수행합니다.

htpasswd -c /etc/munin/munin-htpasswd admin

관리자의 비밀번호를 입력하세요. 그런 다음 /etc/munin/apache.conf를 다시 엽니다...

nano /etc/munin/apache.conf

... "모든 부여가 필요함을 주석 처리하고 내가 빨간색으로 표시한 줄을 추가합니다.

Alias /munin /var/cache/munin/www
<Directory /var/cache/munin/www>
# Require local
# Require all granted
AuthUserFile /etc/munin/munin-htpasswd
AuthName "Munin"
AuthType Basic
Require valid-user
Options None
</Directory>

ScriptAlias /munin-cgi/munin-cgi-graph /usr/lib/munin/cgi/munin-cgi-graph
<Location /munin-cgi/munin-cgi-graph>
# Require local
# Require all granted
AuthUserFile /etc/munin/munin-htpasswd
AuthName "Munin"
AuthType Basic
Require valid-user
<IfModule mod_fcgid.c>
SetHandler fcgid-script
</IfModule>
<IfModule !mod_fcgid.c>
SetHandler cgi-script
</IfModule>
</Location>

그런 다음 Apache를 다시 시작합니다.

service apache2 restart

4 Munin에서 추가 모듈 활성화

Munin 명령 "munin-node-configure --suggest"를 사용하여 서버에서 활성화할 수 있는 추가 Munin 모듈에 대한 권장 사항을 얻을 수 있습니다. 달리다:

munin-node-configure --suggest

출력은 다음과 유사해야 합니다.

"used" 열은 모듈이 활성화되었는지 여부를 표시하고 "Suggestions" 열은 서버가 이 모듈에서 모니터링할 수 있는 서비스를 실행하는지 여부를 표시합니다. 모듈을 활성화하려면 /etc/munin/plugins에서 모듈에 대한 심볼릭 링크를 만드십시오.

여기서는 예를 들어 apache_* 모듈을 활성화합니다.

cd /etc/munin/plugins
ln -s /usr/share/munin/plugins/apache_accesses
ln -s /usr/share/munin/plugins/apache_processes
ln -s /usr/share/munin/plugins/apache_volume

새 구성을 로드하려면 Munin을 다시 시작하십시오.

service munin-node restart

5 ISPConfig에서 Munin 구성(선택 사항)

ISPConfig 호스팅 제어판에는 ISPConfig 모니터 모듈 내에서 Munin 데이터를 표시하는 옵션이 있습니다. Munin 데이터는 iframe에 로드됩니다. 대부분의 브라우저는 https 사이트 내의 http에서 로드되는 콘텐츠를 차단하기 때문에 SSL을 통해 Munin 통계에 액세스하는 방법을 찾아야 합니다. 가장 쉬운 방법은 SSL 지원 ISPConfig 가상 호스트를 사용하여 ISPConfig 웹 디렉토리 내부에 Munin www 데이터 디렉토리에 대한 심볼릭 링크를 생성하는 것입니다.

ln -s /var/cache/munin/www /usr/local/ispconfig/interface/web/munin

이제 https://server1.example.com:8080/munin이 있는 브라우저에서 ISPConfig 아파치 가상 호스트를 통해 Munin에 액세스할 수 있습니다.

다음 단계는 ISPConfig에 구성을 추가하는 것입니다.

관리자(admin) 사용자로 ISPConfig에 로그인하고 시스템 > 서버 구성으로 이동하여 아래와 같이 Munin의 URL, 사용자 이름 및 비밀번호를 입력합니다.

munin URL에서 https:// 및 포트 8080을 사용해야 합니다.