크세노폰의 IT 누리사랑방

Nginx에서 서버 통계도구 "Munin" 설치방법 본문

기술과 지침서/Ubuntu/Linux

Nginx에서 서버 통계도구 "Munin" 설치방법

Xenophon 2014. 10. 31. 06:03
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

Munin은 서버 통계도구다.

서버 모니터링에는 꽤 괜찮은 편이다. 촌스럽지도 않고, 이제 확대도 된다! (야!신난다~)

서비스는 nginx 로 돌고 있기 때문에 기본적으로 아파치에서는 몇 가지 설정을 더 줘야 한다.(엔진x는 빠른데 이런 점이 문제다.)

여하튼 오늘은 munin을 설치하는 방법에 대해 알아보자.

1. apt-get 명령어로 설치하기

=> sudo apt-get install munin munin-node spawn-fcgi libcgi-fast-perl

2. munin 설정하기

=> nano /etc/munin/munin-conf.d/90-fcgi

graph_strategy cgi
html_strategy cgi
cgiurl_graph /munin/munin-cgi-graph
입력 후 저장하기!
3. nginx 설정하기
=> nano  /etc/nginx/sites-enabled/munin
server {
listen 443 ssl;
listen 80;
charset utf-8;
server_name munin.your-domain.com;location ~ ^/munin/munin-cgi-graph/ {
fastcgi_split_path_info ^(/munin/munin-cgi-graph)(.*);
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_pass unix:/var/run/munin/fastcgi-graph.sock;
include fastcgi_params;
}location /munin/static/ {
alias /etc/munin/static/;
expires modified +1w;
}location /munin/ {
fastcgi_split_path_info ^(/munin)(.*);
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_pass unix:/var/run/munin/fastcgi-html.sock;
include fastcgi_params;
}

location / {
rewrite ^/$ munin/ redirect; break;
}
}

입력 후 저장하기.
4. nginx 리로드
service nginx reload
그거 알고계십니까? :  nginx는 restart 보다는 reload 하는게 좋습니다.
5. FastCGI 설정
nano /etc/init.d/munin-fcgi
#!/bin/bash### BEGIN INIT INFO
# Provides:          munin-fcgi
# Required-Start:    $remote_fs $syslog $network
# Required-Stop:     $remote_fs $syslog $network
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start munin FCGI processes at boot time
# Description:       Start the FCGI processes behind http://munin.*/
### END INIT INFOgraph_pidfile=”/var/run/munin/fcgi_graph.pid”
# Ubuntu 12.10: /usr/lib/cgi-bin/munin-cgi-graph
graph_cgi=”/usr/lib/munin/cgi/munin-cgi-graph”
html_pidfile=”/var/run/munin/fcgi_html.pid”
# Ubuntu 12.10: /usr/lib/cgi-bin/munin-cgi-html
html_cgi=”/usr/lib/munin/cgi/munin-cgi-html”retval=0

. /lib/lsb/init-functions

start() {
echo -n “Starting munin graph FastCGI: ”
start_daemon -p ${graph_pidfile} /usr/bin/spawn-fcgi -u munin -g munin \
-s /var/run/munin/fastcgi-graph.sock -U www-data ${graph_cgi}
echo
echo -n “Starting munin html FastCGI: ”
start_daemon -p ${html_pidfile} /usr/bin/spawn-fcgi -u munin -g munin \
-s /var/run/munin/fastcgi-html.sock -U www-data ${html_cgi}
echo
retval=$?
}
stop() {
echo -n “Stopping munin graph FastCGI: ”
killproc -p ${graph_pidfile} ${graph_cgi} -QUIT
echo
echo -n “Stopping munin html FastCGI: ”
killproc -p ${html_pidfile} ${html_cgi} -QUIT
echo
retval=$?
}

case “$1″ in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
*)
echo “Usage: munin-fcgi {start|stop|restart}”
exit 1
;;
esac
exit $retval

스크립트 입력 후 저장!
6. 퍼미션 설정
sudo chmod +x /etc/init.d/munin-fcgi
sudo chown munin /var/log/munin/munin-cgi-*
7. 부팅 시 같이 로드되도록 설정하기
sudo /etc/init.d/munin-fcgi start
sudo update-rc.d munin-fcgi defaults
8. 설정한 사이트로 테스트 해보기.

이렇게 하면 일단 munin이 작동할 것이다.

 

## 디버그 관련

설정하다 잘 안되면 이 경로에서 힌트를 얻을 수 있다.

1. /var/log/nginx/error.log

2. /var/log/munin/munin-cgi-graph.log

3. /var/log/munin/munin-html-graph.log

Comments