서버 모니터링 · 10 min read · Oct 15, 2025
Debian 10에서 Munin 및 Monit으로 서버 모니터링

이 기사에서는 Debian 10 (Buster) 서버를 Munin 및 Monit으로 모니터링하는 방법을 설명합니다. Munin은 서버의 거의 모든 측면(부하 평균, 메모리 사용량, CPU 사용량, MySQL 처리량, 네트워크 트래픽 등)에 대한 멋진 그래프를 생성하며, 많은 구성 없이도 작동합니다. Monit은 Apache, MySQL, Postfix와 같은 서비스의 가용성을 확인하고 서비스가 예상대로 작동하지 않을 경우 재시작과 같은 적절한 조치를 취합니다. 두 가지를 결합하면 현재 또는 임박한 문제를 볼 수 있는 그래프(예: “서버의 부하 평균이 급격히 증가하고 있으므로 더 큰 서버가 필요합니다.”)와 모니터링된 서비스의 가용성을 보장하는 감시 도구를 제공합니다.
Munin으로 여러 서버를 모니터링할 수 있지만, 여기서는 설치된 시스템의 모니터링만 논의합니다.
이 가이드는 Debian 10 (Buster)을 위해 작성되었지만, 구성은 Ubuntu와 같은 다른 배포판에도 약간의 변경으로 적용될 수 있습니다.
1 사전 참고
이 튜토리얼의 모든 명령은 루트 사용자로 실행됩니다. SSH를 통해 루트로 서버에 로그인하거나 터미널 창을 엽니다. 루트가 아닌 다른 사용자로 로그인한 경우, 다음 명령을 사용하여 루트 사용자로 전환합니다.
su -우리 시스템의 호스트 이름은 server1.example.com이며, 문서 루트가 /var/www/www.example.com/web인 웹사이트 www.example.com이 있습니다.
Munin을 설치하기 전에 시스템이 최신 상태인지 확인하려면 다음을 실행합니다:
apt update
apt upgradeApache는 Munin 페이지를 표시하는 데 사용되며, Apache fcgid 모듈은 Munin 그래프 확대 기능에 필요합니다. apt를 사용하여 apache와 fcgid 모듈을 설치합니다.
apt install apache2 libcgi-fast-perl libapache2-mod-fcgidApache에서 fcgid 모듈을 활성화합니다.
a2enmod fcgid2 Munin 설치 및 구성
Debian에 Munin을 설치하려면 다음과 같이 합니다:
apt install munin munin-node munin-plugins-extra서버가 MySQL 또는 MariaDB를 실행 중인 경우, MySQL을 모니터링하기 위해 몇 가지 추가 Munin 플러그인을 활성화합니다:
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_innodb mysql_innodb
ln -s /usr/share/munin/plugins/mysql_isam_space_ mysql_isam_space_
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 줄의 주석을 제거합니다(기본값은 괜찮습니다). HTML 출력에서 localhost.localdomain 대신 server1.example.com을 사용하도록 Munin을 설정하려고 하므로, 간단한 호스트 트리 섹션에서 localhost.localdomain을 server1.example.com으로 교체합니다. 주석이 없는 변경된 파일은 다음과 같습니다:
nano /etc/munin/munin.conf# Munin을 위한 예제 구성 파일, 'make build'에 의해 생성됨
# 다음 세 변수는 RRD 데이터베이스, HTML 출력, 로그 및 잠금/pid 파일의 위치를 지정합니다. 모두
# munin-cron을 실행하는 사용자가 쓸 수 있어야 합니다. 모두
# 여기에서 볼 수 있는 값으로 기본 설정됩니다.
#
dbdir /var/lib/munin
htmldir /var/cache/munin/www
logdir /var/log/munin
rundir /var/run/munin
# HTML 템플릿을 찾을 위치
#
tmpldir /etc/munin/templates
# 정적 www 파일을 찾을 위치
#
#staticdir /etc/munin/static
# 임시 cgi 파일은 여기 있습니다. cgi 사용자(일반적으로 nobody 또는 httpd)가 쓸 수 있어야 합니다.
#
# cgitmpdir /var/lib/munin/cgi-tmp
# (정확히 하나) 모든 파일을 포함할 디렉토리.
includedir /etc/munin/munin-conf.d
[...]
# 간단한 호스트 트리
[server1.example.com]
address 127.0.0.1
use_node_name yes
[...] Apache 2.4의 Munin 구성 파일 /etc/munin/apache24.conf를 찾아야 합니다. 이 파일은 Munin의 HTML 출력 디렉토리 /var/cache/munin/www에 대한 별칭인 munin을 정의합니다. 이는 이 서버의 모든 웹사이트에서 상대 경로 /munin을 사용하여 munin에 접근할 수 있음을 의미합니다(예: http://www.example.com/munin).
Apache Munin 구성은 기본적으로 활성화되어 있지 않으며, 이는 Debian Wheezy에서 Jessie로 변경되었습니다. 새로운 구성 디렉토리는 이전 버전인 Wheezy 및 Squeeze에서 사용된 /etc/apache2/conf.d 대신 /etc/apache2/conf-enabled입니다.
다음 명령을 실행하여 구성을 활성화하고 Apache에 로드합니다.
cd /etc/apache2/conf-enabled/
ln -s /etc/munin/apache24.conf munin.conf
service apache2 restartRequire local 줄의 주석을 제거하고 대신 Require all granted 및 Options FollowSymLinks SymLinksIfOwnerMatch를 추가해야 합니다(그렇지 않으면 localhost에서만 Munin 출력을 접근할 수 있습니다):
nano /etc/munin/apache24.confAlias /munin /var/cache/munin/www
# Require local
Require all granted
Options FollowSymLinks SymLinksIfOwnerMatch
ScriptAlias /munin-cgi/munin-cgi-graph /usr/lib/munin/cgi/munin-cgi-graph
# Require local
Require all granted
Options FollowSymLinks SymLinksIfOwnerMatch
SetHandler fcgid-script
SetHandler cgi-script
Apache를 재시작합니다:
systemctl restart apache2.service그런 다음 Munin을 재시작합니다:
systemctl restart munin-node.service이제 Munin이 첫 번째 출력을 생성할 수 있도록 몇 분간 기다린 후, 브라우저에서 http://www.example.com/munin/으로 이동하면 첫 번째 통계를 볼 수 있습니다:

(이는 munin이 생성하는 많은 그래프 중 일부에 불과합니다…)
3 Munin 출력 디렉토리 비밀번호 보호(선택 사항이지만 강력히 권장)
이제 모든 사람이 서버에 대한 모든 작은 통계를 볼 수 있도록 하려는 것이 아니라면 munin 출력 디렉토리를 비밀번호로 보호하는 것이 좋습니다.
이를 위해 비밀번호 파일 /etc/munin/munin-htpasswd를 생성해야 합니다. 우리는 사용자 이름 admin으로 로그인하고 싶으므로 다음과 같이 합니다:
htpasswd -c /etc/munin/munin-htpasswd adminadmin의 비밀번호를 입력합니다. 그런 다음 /etc/munin/apache24.conf를 다시 엽니다…
nano /etc/munin/apache24.conf… “Require all granted”의 주석을 제거하고 빨간색으로 표시된 줄을 추가합니다:
Alias /munin /var/cache/munin/www
# Require local
# Require all granted
AuthUserFile /etc/munin/munin-htpasswd
AuthName "Munin"
AuthType Basic
Require valid-user
Options None
ScriptAlias /munin-cgi/munin-cgi-graph /usr/lib/munin/cgi/munin-cgi-graph
# Require local
# Require all granted
AuthUserFile /etc/munin/munin-htpasswd
AuthName "Munin"
AuthType Basic
Require valid-user
SetHandler fcgid-script
SetHandler cgi-script
그런 다음 Apache를 재시작합니다:
systemctl restart apache2.service4 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을 재시작합니다.
systemctl restart munin-node.service5 Monit 설치 및 구성
Monit은 Debian Buster 백포트 저장소에서 사용할 수 있습니다. 이 저장소는 기본적으로 활성화되어 있지 않으므로 먼저 추가해야 합니다. 다음 명령을 실행합니다:
echo 'deb http://ftp.de.debian.org/debian buster-backports main' > /etc/apt/sources.list.d/buster-backports.list그런 다음 패키지 목록을 업데이트합니다:
apt updateMonit을 설치하려면 다음과 같이 합니다:
apt install monit이제 /etc/monit/monitrc를 편집해야 합니다. 기본 /etc/monit/monitrc에는 많은 예제가 있으며, http://mmonit.com/monit/documentation/에서 더 많은 구성 예제를 찾을 수 있습니다. 그러나 제 경우에는 proftpd, sshd, mysql, apache 및 postfix를 모니터링하고 싶고, 포트 2812에서 Monit 웹 인터페이스를 활성화하고 싶으며, https 웹 인터페이스에 로그인할 때 사용자 이름 admin과 비밀번호 howtoforge를 사용하고 싶고, Monit이 root@localhost로 이메일 알림을 보내도록 하고 싶습니다. 그래서 제 파일은 다음과 같습니다(다른 데몬에 대한 예제를 추가하여 파일을 필요에 맞게 조정할 수 있습니다):
cp /etc/monit/monitrc /etc/monit/monitrc_orig
cat /dev/null > /etc/monit/monitrc
nano /etc/monit/monitrcset daemon 60
set logfile syslog facility log_daemon
set mailserver localhost
set mail-format { from: [email protected] }
set alert root@localhost
set httpd port 2812 and
SSL ENABLE
PEMFILE /var/certs/monit.pem
allow admin:howtoforge
check process sshd with pidfile /var/run/sshd.pid
start program "/usr/sbin/service ssh start"
stop program "/usr/sbin/service ssh stop"
if failed port 22 protocol ssh then restart
if 5 restarts within 5 cycles then timeout
check process apache with pidfile /var/run/apache2/apache2.pid
group www
start program = "/usr/sbin/service apache2 start"
stop program = "/usr/sbin/service apache2 stop"
if failed host localhost port 80 protocol http
and request "/monit/token" then restart
if cpu is greater than 60% for 2 cycles then alert
if cpu > 80% for 5 cycles then restart
if totalmem > 500 MB for 5 cycles then restart
if children > 250 then restart
if loadavg(5min) greater than 10 for 8 cycles then stop
if 3 restarts within 5 cycles then timeout
# ---------------------------------------------------------------------------------------------
# NOTE: example.pid를 서버의 pid 이름으로 교체하십시오. 이름은 호스트 이름에 따라 다릅니다.
# ---------------------------------------------------------------------------------------------
#check process mysql with pidfile /var/lib/mysql/example.pid
# group database
# start program = "/usr/sbin/service mysql start"
# stop program = "/usr/sbin/service mysql stop"
# if failed host 127.0.0.1 port 3306 then restart
# if 5 restarts within 5 cycles then timeout
#check process proftpd with pidfile /var/run/proftpd.pid
# start program = "/usr/sbin/service proftpd start"
# stop program = "/usr/sbin/service proftpd stop"
# if failed port 21 protocol ftp then restart
# if 5 restarts within 5 cycles then timeout
#
#check process postfix with pidfile /var/spool/postfix/pid/master.pid
# group mail
# start program = "/usr/sbin/service postfix start"
# stop program = "/usr/sbin/service postfix stop"
# if failed port 25 protocol smtp then restart
# if 5 restarts within 5 cycles then timeout
#
#check process nginx with pidfile /var/run/nginx.pid
# start program = "/usr/sbin/service nginx start"
# stop program = "/usr/sbin/service nginx stop"
# if failed host 127.0.0.1 port 80 then restart
#
#check process memcached with pidfile /var/run/memcached.pid
# start program = "/usr/sbin/service memcached start"
# stop program = "/usr/sbin/service memcached stop"
# if failed host 127.0.0.1 port 11211 then restart
#
#check process pureftpd with pidfile /var/run/pure-ftpd/pure-ftpd.pid
# start program = "/usr/sbin/service pure-ftpd-mysql start"
# stop program = "/usr/sbin/service pure-ftpd-mysql stop"
# if failed port 21 protocol ftp then restart
# if 5 restarts within 5 cycles then timeout
#
#check process named with pidfile /var/run/named/named.pid
# start program = "/usr/sbin/service bind9 start"
# stop program = "/usr/sbin/service bind9 stop"
# if failed host 127.0.0.1 port 53 type tcp protocol dns then restart
# if failed host 127.0.0.1 port 53 type udp protocol dns then restart
# if 5 restarts within 5 cycles then timeout
#
#check process ntpd with pidfile /var/run/ntpd.pid
# start program = "/usr/sbin/service ntp start"
# stop program = "/usr/sbin/service ntp stop"
# if failed host 127.0.0.1 port 123 type udp then restart
# if 5 restarts within 5 cycles then timeout
#
#check process mailman with pidfile /var/run/mailman/mailman.pid
# group mail
# start program = "/usr/sbin/service mailman start"
# stop program = "/usr/sbin/service mailman stop"
#
#check process amavisd with pidfile /var/run/amavis/amavisd.pid
# group mail
# start program = "/usr/sbin/service amavis start"
# stop program = "/usr/sbin/service amavis stop"
# if failed port 10024 protocol smtp then restart
# if 5 restarts within 5 cycles then timeout
#
#check process courier-imap with pidfile /var/run/courier/imapd.pid
# group mail
# start program = "/usr/sbin/service courier-imap start"
# stop program = "/usr/sbin/service courier-imap stop"
# if failed host localhost port 143 type tcp protocol imap then restart
# if 5 restarts within 5 cycles then timeout
#
#check process courier-imap-ssl with pidfile /var/run/courier/imapd-ssl.pid
# group mail
# start program = "/usr/sbin/service courier-imap-ssl start"
# stop program = "/usr/sbin/service courier-imap-ssl stop"
# if failed host localhost port 993 type tcpssl sslauto protocol imap then restart
# if 5 restarts within 5 cycles then timeout
#
#check process courier-pop3 with pidfile /var/run/courier/pop3d.pid
# group mail
# start program = "/usr/sbin/service courier-pop start"
# stop program = "/usr/sbin/service courier-pop stop"
# if failed host localhost port 110 type tcp protocol pop then restart
# if 5 restarts within 5 cycles then timeout
#
#check process courier-pop3-ssl with pidfile /var/run/courier/pop3d-ssl.pid
# group mail
# start program = "/usr/sbin/service courier-pop-ssl start"
# stop program = "/usr/sbin/service courier-pop-ssl stop"
# if failed host localhost port 995 type tcpssl sslauto protocol pop then restart
# if 5 restarts within 5 cycles then timeout
#
#check process dovecot with pidfile /var/run/dovecot/master.pid
# group mail
# start program = "/usr/sbin/service dovecot start"
# stop program = "/usr/sbin/service dovecot stop"
# if failed host localhost port 993 type tcpssl sslauto protocol imap then restart
# if 5 restarts within 5 cycles then timeout구성 파일은 상당히 자명합니다. 옵션에 대해 확실하지 않은 경우 Monit 문서를 참조하십시오: http://mmonit.com/monit/documentation/monit.html
Monit 구성의 apache 부분에서 다음을 찾을 수 있습니다:
if failed host localhost port 80 protocol http
and request "/monit/token" then restart이는 Monit이 localhost의 포트 80에 연결하려고 시도하고 /monit/token 파일에 접근하려고 시도함을 의미합니다. 이는 우리의 웹사이트 문서 루트가 /var/www/html이기 때문에 /var/www/html/monit/token입니다. Monit이 성공하지 못하면 Apache가 실행되고 있지 않다는 의미이며, Monit은 이를 재시작할 것입니다. 이제 /var/www/html/monit/token 파일을 생성하고 무작위 문자열을 작성해야 합니다:
mkdir /var/www/html/monit
echo "hello" > /var/www/html/monit/token다음으로 SSL 암호화된 Monit 웹 인터페이스에 필요한 pem 인증서(/var/certs/monit.pem)를 생성합니다:
mkdir /var/certs
cd /var/certs인증서를 생성하기 위해 OpenSSL 구성 파일이 필요합니다. 다음과 같이 작성할 수 있습니다:
nano /var/certs/monit.cnf# RSA 인증서 생성 - 서버
[ req ]
default_bits = 2048
encrypt_key = yes
distinguished_name = req_dn
x509_extensions = cert_type
[ req_dn ]
countryName = Country Name (2 letter code)
countryName_default = MO
stateOrProvinceName = State or Province Name (full name)
stateOrProvinceName_default = Monitoria
localityName = Locality Name (eg, city)
localityName_default = Monittown
organizationName = Organization Name (eg, company)
organizationName_default = Monit Inc.
organizationalUnitName = Organizational Unit Name (eg, section)
organizationalUnitName_default = Dept. of Monitoring Technologies
commonName = Common Name (FQDN of your server)
commonName_default = server.monit.mo
emailAddress = Email Address
emailAddress_default = [email protected]
[ cert_type ]
nsCertType = server이제 다음과 같이 인증서를 생성합니다:
openssl req -new -x509 -days 365 -nodes -config ./monit.cnf -out /var/certs/monit.pem -keyout /var/certs/monit.pemopenssl dhparam 2048 >> /var/certs/monit.pemopenssl x509 -subject -dates -fingerprint -noout -in /var/certs/monit.pemchmod 600 /var/certs/monit.pem마지막으로 Monit을 시작할 수 있습니다:
service monit restart이제 브라우저를 https://www.example.com:2812/로 이동시키고(포트 2812가 방화벽에 의해 차단되지 않았는지 확인), admin과 howtoforge로 로그인하면 Monit 웹 인터페이스를 볼 수 있습니다. 다음과 같아야 합니다:

(메인 화면)


(SSHd 상태 페이지)
/etc/monit/monitrc의 구성에 따라 monit는 서비스가 실패할 경우 서비스를 재시작하고 서비스의 PID가 변경될 경우 이메일 알림을 보냅니다.
셸에서 Monit 상태를 확인하려면 “monit status” 명령을 실행합니다:
monit status이 명령은 모니터링된 모든 서비스의 상태를 보여줍니다.

6 링크
- munin: http://munin-monitoring.org/
- monit: http://mmonit.com/monit/
새 게시물을 받은 편지함에서 받기
스팸은 없습니다. 언제든지 구독 해지 가능합니다.