CentOS Linux安装munin

Munin是一个网络资源监控工具,通过自带插件可以监控很多系统服务。官网:http://munin-monitoring.org/。Munin需要在web server上运行。这里系统为CentOS6.2,监控机IP为192.168.1.100,被监控机IP为192.168.1.200。经过比较,不使用复杂的源码编译安装,参考官方wiki上使用yum方式安装。

一、监控机配置(Munin master)
0、先安装web server
这里使用apache。

yum install httpd

apache基本配置略过。Munin也可以运行在一个Java的web server上(Resin from www.caucho.com)。

1、安装EPEL源

rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-5.noarch.rpm


vim /etc/yum.repos.d/dag.repo

输入:

[dag]
name=Dag RPM Repository for Red Hat Enterprise Linux
baseurl=http://apt.sw.be/redhat/el$releasever/en/$basearch/dag
gpgcheck=1
gpgkey=http://dag.wieers.com/rpm/packages/RPM-GPG-KEY.dag.txt
enabled=1

2、安装munin

yum install munin

3、简单配置munin master
安装完后在/var/www/html会有munin目录,/etc下也有munin目录。
PS:刚安装完/var/www/html/munin目录下是没有index.html,但后面登陆时会自动生成的。

vim /etc/munin/munin.conf

将以下几行的注释去掉:

dbdir  /var/lib/munin
htmldir /var/www/html/munin
logdir /var/log/munin
rundir  /var/run/munin
tmpldir        /etc/munin/templates


将以下监控本机的代码注释掉:

#[x86-07.phx2.fedoraproject.org]
#    address 127.0.0.1
#    use_node_name yes


同时添加被监控机地址:

[server01]
address 192.168.1.200
use_node_name yes

use_node_name命令控制munin命名节点的方式,如果后面跟的参数为yes就是用括号中的值来命名,如果是no则将执行一个DNS查询。

4、设置登陆用户和密码:

htpasswd -c /etc/munin/munin-htpasswd muninadmin

输入两遍密码。这里建立了一个名为muninadmin的用户。

5、安装完munin服务端后,程序会自动创建一个计划任务

cat /etc/cron.d/munin

可以看到是每5分钟获取一次数据:

*/5 * * * * munin test -x /usr/bin/munin-cron && /usr/bin/munin-cron

需要启动crond服务:

service crond start

6、重启httpd

service httpd restart

二、被监控机配置(Munin node)
1、也需要安装EPEL源

rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-5.noarch.rpm


vim /etc/yum.repos.d/dag.repo

输入:

[dag]
name=Dag RPM Repository for Red Hat Enterprise Linux
baseurl=http://apt.sw.be/redhat/el$releasever/en/$basearch/dag
gpgcheck=1
gpgkey=http://dag.wieers.com/rpm/packages/RPM-GPG-KEY.dag.txt
enabled=1

2、安装munin-node

yum install munin-node

3、配置munin node

vim /etc/munin/munin-node.conf

找到:

allow ^127\.0\.0\.1$

这里是表示允许谁来获取信息,在下面加上监控机IP:

allow ^192\.168\.1\.100$

4、启动munin-node

service munin-node start

三、收尾
1、监控机测试客户端
在监控机使用telnet命令连接到客户端:

telnet 192.168.1.200 4949

使用list、fetch cpu命令查看能否获得信息。

2、访问http://监控机IP/munin
输入前面设置的用户名和密码登陆。如果验证用户名和密码和后,页面显示Index of munin说明index.html没有生成,看日志是因为没有nodes,检查配置是否有错,ip是不是写错了。

3、其它
监控机会产生四个日志文件,在/var/log/munin目录下:
munin-graph.log
munin-html.log
munin-limits.log
munin-update.log

被监控机产生一个日志文件,同样在/var/log/munin目录下:
munin-node.log

被监控机的插件目录在/etc/munin/plugins目录。

参考资料:
http://blog.zfcms.com/article/458
http://blog.chinaunix.net/uid-15795819-id-3118511.html
http://salogs.com/2011/09/munin-application-notes-installation/
http://www.debian-administration.org/articles/597
http://munin-monitoring.org/wiki/LinuxInstallation