一、简介

通过将近2周的了解,个人认为munin属于轻量级的性能展示工具,相对于cacti其部署、展示、添加编辑插件都很简洁,如果拿来主义使用 Munin Exchange 提供的插件建立自己的监控项目那就更简单了。按照Munin官方的介绍,其最初是用来对网络进行监控,目前Munin Exchange 的插件库已经扩展到各个服务领域,通过官方的文档也很方便的写自己的插件。先来看一下安装后默认几个监控图:


网卡流量


中断与上下文切换

二、工作方式

munin使用常见的client-server模式,client端使用名为munin-node的守护进程,server端没有服务,只是通过计划任务每5分钟通过脚本读取配置文件来取配置文件中预先定义好的节点服务器信息保存为rrd格式。最终程序通过rrd文件生成静态的图像和html文件。如果要使用页面展现服务器段必须安装http程序如:apache、nginx。

munin有如下几个优越特性
1、munin完全由perl编写,因此node端的大多数插件都是perl脚本编写的,当然可以随用户喜好使用自己顺手的语言编写插件。
2、通过插件可以实现snmp信息的读取
3、通过nsca插件可以结合nagios发送被动检查结果
4、无需后端数据库支持

三、安装(CentOS)

1、服务器端

最简单的就是使用rpm包安装,通过配置两个yum源来完成

# 配置 epel软件仓库

rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm

#配置dag软件仓库

vi /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

安装服务端程序

yum -y install munin

2、客户端(node)

同样需要配置dag源,然后安装节点程序

yum -y install munin-node

四、配置

1、客户端(节点)

munin-node程序会自带一大部分的插件,这些在安装过程中程序会根据当前目标系统的实际情况应用相应的插件。主要配置文件在/etc/munin目录:

munin-node.conf //节点配置文件
node.d
plugin-conf.d //插件配置文件
plugins //插件文件的软连接

plugins目录中的文件时munin的原始文件的连接文件,这些连接文件都是munin再安装时候自行判断后生成的当前可以使用的插件。至于如何判断生成,后续文章会有介绍
2011-09-14_110217.png
munin-node-configure --suggest 命令可以列出所有插件并显示出哪个插件支持当前节点以及是否启用。

编辑节点配置文件:

vi /etc/munin/munin-node.conf
log_level 4
log_file /var/log/munin/munin-node.log
pid_file /var/run/munin/munin-node.pid
background 1
setsid 1
user root
group root
ignore_file ~$
ignore_file DEADJOE$
ignore_file \.bak$
ignore_file %$
ignore_file \.dpkg-(tmp|new|old|dist)$
ignore_file \.rpm(save|new)$
ignore_file \.pod$

allow ^192.\.168\.8\.29$
host *
port 4949

这个配置很简单,大多数内容不用修改,根据实际情况修改
allow ^192.\.168\.8\.29$ #这个是服务端IP,也就是允许谁来获取监控信息
port 4949 #节点程序监听端口

修改好配置文件后启动服务并设置开机启动

/etc/init.d/munin-node start
chkconfig munin-node on

2、服务端

服务端有两方面的配置:
1、munin配置
2、apache配置

munin的配置
vi /etc/munin/munin.conf

# 注意下面的目录设置
# rrd文件位置
dbdir /var/lib/munin

# 这个htmldir就是apache需要设置的主页目录,根据实际情况修改。注意目录所属者应该为munin
htmldir /opt/munin/www

# 日志主目录,里面会有munin服务端相关的日志
logdir /var/log/munin

# pid文件
rundir /var/run/munin

# 在配置文件的最后面添加刚刚配置好的主机(节点)信息
# 这里大括号里用分号分了两个部分,第一个部分是主机组,第二个部分是主机名
[TestGroup;test00]
# 使用上面设置的主机名,而非客户端的hostname
use_node_name yes
# 客户端ip
address 192.168.8.4

使用telnet命令验证客户端服务是否正常
telnet 192.168.8.4 4949

[root@Server00 ~]# telnet 192.168.8.4 4949
Trying 192.168.8.4...
Connected to test00.domain (192.168.8.4).
Escape character is '^]'.
# munin node at test00.domain
help # Unknown command. Try cap, list, nodes, config, fetch, version or quit
list cpu df df_inode entropy forks fw_packets http_loadtime if_err_eth0 if_err_eth1 if_eth0 if_eth1 interrupts iostat iostat_ios irqstats load memory netstat nfs4_client open_files open_inodes proc_pri processes swap threads uptime users vmstat yum
fetch df _dev_sda1.value 57.0259717428043
_dev_sda2.value 63.2926649641543
_dev_sdb1.value 20.1660167866556
_dev_shm.value 0
.
fetch cpu user.value 1678626920
nice.value 37143
system.value 457048295
idle.value 21342438866
iowait.value 162031502
irq.value 3918512
softirq.value 43630517
steal.value 0
.
nodes test00.domain
.
quit Connection closed by foreign host.

上面
list # 节点支持的插件
nodes # 列出节点名称
fetch PlungsName #获得指定插件的结果

安装完munin服务端后,程序会自动创建一个计划任务:
cat /etc/cron.d/munin

#
# cron-jobs for munin
#

MAILTO=root

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

每五分钟获取一次数据,生成rrd文件并生成相应的html文件和图像文件

apache的配置
apache的配置没有什么特别的,只是让主页目录指定到上面munin的html目录即可
cat munin.conf

DocumentRoot /opt/munin/www
ServerName munin.okooo.net
# SSLRequireSSL
Options None
AllowOverride None
Order allow,deny
Allow from all
AuthType Basic
AuthBasicProvider ldap
AuthName "Please input user info:"
AuthzLDAPAuthoritative off
AuthLDAPURL ldap://192.168.8.68:389/cn=Manager,dc=domain,dc=com?uid?sub?(objectClass=*)
Require ldap-user user1 user2 user3

注意:我这里配置了Ldap用户验证,一般情况设置默认的apache标准验证即可。

本文到处为止,后续文章会介绍使用第三方插件和配置已有插件。

下面是本次配置应用后的截图
2011-09-10_002404.png2011-09-10_002827.png
原创文章,转载请注明: 转自 http://salogs.com

注意:经过几个月的使用,当节点增加到20个以上时,服务器端的perl脚本很耗费系统资源,因此决定停止使用。