本文由LinuxProbe.Com团队成员魏丽猿整理发布,原文来自:Linux中国

Munin 是一款类似 RRD tool 的优秀系统监控工具,它能提供给你多方面的系统性能信息,例如 磁盘、网络、进程、系统和用户。
Munin

Munin 的工作原理

Munin 以客户端-服务器模式运行,主服务器上运行的 Munin 服务器进程会从本地运行的客户端守护进程(Munin 可以监控它自己的资源)或者远程客户端(Munin 可以监控上百台机器)收集数据,然后在它的 web 界面上以图形的方式显示出来。
在服务器中配置 Munin

安装

要配置服务器端和客户端,我们需要完成以下两步。

  1. 安装 Munin 服务器软件包并配置,使得它能从客户端收集数据。
  2. 安装 Munin 客户端,使得服务器能连接到客户端守护进程进行数据收集。

1、在 Linux 上安装 munin 服务器端

在基于Ubuntu/Debian的机器上安装 Munin 服务器:

apt-get install munin apache2

在基于 Redhat/CentOS 的机器上安装 Munin 服务器:
在基于 Redhat 的机器上安装 Munin 之前,你需要确保 启用 EPEL 软件仓库,因为基于 Redhat 的机器的软件仓库默认没有 Munin,下载EPEL 的rpm 安装包(下载对应版本):

wget http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm

下载完成后,通过以下命令安装EPEL 软件包

rpm -ivh epel-release-6-8.noarch.rpm或rpm -ivh epel-release*

安装好EPEL 源后,用yum 命令来检查是否添加到源列表:

# yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.vonline.vn
 * epel: buaya.klas.or.id
 * extras: centos-hn.viettelidc.com.vn
 * updates: mirrors.fibo.vn
repo id        repo name                                              status
base           CentOS-6 - Base                                         6,381
epel           Extra Packages for Enterprise Linux 6 - x86_64         10,023
extras         CentOS-6 - Extras                                          13
nginx          nginx repo                                                 47
updates        CentOS-6 - Updates                                      1,555
repolist: 18,019

EPEL已经在repo 后列出,并且显示提供了上万个软件包,所以EPEL 已经安装到你的CentOS了,EPEL源的配置安装到了/etc/yum.repos.d/epel.repo 文件。
然后就可以直接安装munin了,执行命令:

yum install munin httpd

2、在 Linux 上配置 Munin 服务器端:

下面是我们要在服务器上启动 Munini 所进行的步骤:
步骤 1:在 /etc/munin/munin.conf 中添加需要监控的主机详情。
/etc/munin/munin.conf 文件中添加主机条目,调到文件末尾添加要监控的客户端。在这个例子中,我添加了要监控的数据库服务器和它的 IP 地址。

[db.linuxprobe.com]
address 192.168.1.25
use_node_name yes

保存文件并退出。
步骤 2:配置 apache web 服务器使其包括 munin 配置。
/etc/apache2/conf.d 目录中编辑或创建文件 munin.conf 用于包括 Munin 和 Apache 相关的配置,另外注意一点,默认其它和 web 相关的 Munin 配置保存在 /var/www/munin 目录。

vi /etc/apache2/conf.d/munin.conf
内容:
Alias /munin /var/www/munin
<Directory /var/www/munin>
Order allow,deny
Allow from localhost 127.0.0.0/8 ::1
AllowOverride None
Options ExecCGI FollowSymlinks
AddHandler cgi-script .cgi
DirectoryIndex index.cgi
AuthUserFile /etc/munin/munin.passwd
AuthType basic
AuthName "Munin stats"
require valid-user
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault M310
</IfModule>
</Directory>

保存文件并退出。
步骤 3:为 web 界面创建用户名和密码。
现在为查看 munin 的图示而创建用户名和密码:

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

注意:对于 Redhat/Centos 机器,要访问你的配置文件,需要在每个路径中用 “httpd” 替换 “apache2”。
步骤 4:重启 apache 服务器。
重启 Apache 服务器,使得 Munin 配置生效。
基于 Ubuntu/Debian :

service apache2 restart

基于 Centos/Redhat :

service httpd restart

3、在 Linux 上安装和配置 Munin 客户端:

步骤 1:在 Linux 上安装 Munin 客户端。

apt-get install munin-node

注意:如果你想监控你的 Munin 服务器端,你也需要在服务器端安装 munin-node。
步骤 2:编辑 munin-node.conf 文件配置客户端。

vi /etc/munin/munin-node.conf
示例:
allow ^127\.0\.0\.1$
allow ^10\.10\.20\.20$
# 监听到哪个地址上
host *
# 以及哪个端口
port 4949

注意: 10.10.20.20 是我的 Munin 服务器,它连接到客户端的 4949 端口获取数据。
步骤 3:在客户端机器中重启 munin-node:

service munin-node restart
测试连接

检查你是否能从服务器的连接到客户端的 4949 端口,如果不行,你需要在客户端机器中的防火墙打开该端口。
访问 Munin web 页面http://munin.linuxprobe.com/munin/index.html即可。
注意,测试之前已经将域名定义到了指定的服务端的80端口。

本文地址:https://www.linuxprobe.com/munin-monitor-installation-and-configuration.html编辑:魏丽猿,审核员:张宏宇

本文原创地址:https://www.linuxprobe.com/munin-monitor-installation-and-configuration.html编辑:清蒸github,审核员:暂无