在 Linux 上安装和配置 Munin 监控服务器
Munin 是一款类似 RRD tool 的非常棒的系统监控工具,它能提供给你多方面的系统性能信息,例如 磁盘、网络、进程、系统和用户。这些是 Munin 默认监控的内容。
Munin 如何工作?
Munin 以客户端-服务器模式运行。主服务器上运行的 Munin 服务器进程会从本地运行的客户端守护进程(Munin 可以监控它自己的资源)或者远程客户端(Munin 可以监控上百台机器)收集数据,然后在它的 web 界面上以图形的方式显示出来。
在服务器中配置 Munin
要配置服务器端和客户端,我们需要完成以下两步。
- 安装 Munin 服务器软件包并配置,使得它能从客户端收集数据。
- 安装 Munin 客户端,使得服务器能连接到客户端守护进程进行数据收集。
在 Linux 上安装 munin 服务器端
在基于 Ubuntu/Debian 的机器上安装 Munin 服务器:
<span class="kwd">apt-get</span><span class="pln"> install munin apache2</span>
在基于 RedHat/CentOS 的机器上安装 Munin 服务器:
在基于 Redhat 的机器上安装 Munin 之前,你需要确保 启用 EPEL 软件仓库,因为基于 Redhat 的机器的软件仓库默认没有 Munin。
<span class="kwd">yum</span><span class="pln"> install munin httpd</span>
在 Linux 上配置 Munin 服务器端
下面是我们要在服务器上启动 Munini 所进行的步骤:
- 在 /etc/munin/munin.conf 中添加需要监控的主机详情。
- 配置 apache web 服务器使其包括 munin 配置。
- 为 web 界面创建用户名和密码
- 重启 apache 服务器
步骤 1
在 /etc/munin/munin.conf 文件中添加主机条目。调到文件末尾添加要监控的客户端。在这个例子中,我添加了要监控的数据库服务器和它的 IP 地址。
示例:
<span class="pun">[</span><span class="pln">db</span><span class="pun">.</span><span class="pln">linuxnix</span><span class="pun">.</span><span class="pln">com</span><span class="pun">]</span>
<span class="pln">address </span><span class="lit">192.168</span><span class="pun">.</span><span class="lit">1.25</span>
<span class="pln">use_node_name </span><span class="kwd">yes</span>
保存文件并退出。
步骤 2
在 /etc/apache2/conf.d 目录中编辑或创建文件 munin.conf 用于包括 Munin 和 Apache 相关的配置。另外注意一点,默认其它和 web 相关的 Munin 配置保存在 /var/www/munin 目录。
<span class="kwd">vi</span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">apache2</span><span class="pun">/</span><span class="pln">conf</span><span class="pun">.</span><span class="pln">d</span><span class="pun">/</span><span class="pln">munin</span><span class="pun">.</span><span class="pln">conf</span>
内容:
<span class="typ">Alias</span><span class="pun">/</span><span class="pln">munin </span><span class="pun">/</span><span class="kwd">var</span><span class="pun">/</span><span class="pln">www</span><span class="pun">/</span><span class="pln">munin</span>
<span class="pun"><</span><span class="typ">Directory</span><span class="pun">/</span><span class="kwd">var</span><span class="pun">/</span><span class="pln">www</span><span class="pun">/</span><span class="pln">munin</span><span class="pun">></span>
<span class="typ">Order</span><span class="pln"> allow</span><span class="pun">,</span><span class="pln">deny</span>
<span class="typ">Allow</span><span class="kwd">from</span><span class="pln"> localhost </span><span class="lit">127.0</span><span class="pun">.</span><span class="lit">0.0</span><span class="pun">/</span><span class="lit">8</span><span class="pun">::</span><span class="lit">1</span>
<span class="typ">AllowOverride</span><span class="kwd">None</span>
<span class="typ">Options</span><span class="typ">ExecCGI</span><span class="typ">FollowSymlinks</span>
<span class="typ">AddHandler</span><span class="pln"> cgi</span><span class="pun">-</span><span class="kwd">script</span><span class="pun">.</span><span class="pln">cgi</span>
<span class="typ">DirectoryIndex</span><span class="pln"> index</span><span class="pun">.</span><span class="pln">cgi</span>
<span class="typ">AuthUserFile</span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">munin</span><span class="pun">/</span><span class="pln">munin</span><span class="pun">.</span><span class="kwd">passwd</span>
<span class="typ">AuthType</span><span class="pln"> basic</span>
<span class="typ">AuthName</span><span class="str">"Munin stats"</span>
<span class="kwd">require</span><span class="pln"> valid</span><span class="pun">-</span><span class="pln">user</span>
<span class="pun"><</span><span class="typ">IfModule</span><span class="pln"> mod_expires</span><span class="pun">.</span><span class="pln">c</span><span class="pun">></span>
<span class="typ">ExpiresActive</span><span class="typ">On</span>
<span class="typ">ExpiresDefault</span><span class="pln"> M310</span>
<span class="pun"></</span><span class="typ">IfModule</span><span class="pun">></span>
<span class="pun"></</span><span class="typ">Directory</span><span class="pun">></span>
保存文件并退出。
步骤 3
现在为查看 munin 的图示而创建用户名和密码:
<span class="pln">htpasswd </span><span class="pun">-</span><span class="pln">c </span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">munin</span><span class="pun">/</span><span class="pln">munin</span><span class="pun">-</span><span class="pln">htpasswd munin</span>
注意:对于 Redhat/Centos 机器,要访问你的配置文件,需要在每个路径中用 “httpd” 替换 “apache2”。
步骤 4
重启 Apache 服务器,使得 Munin 配置生效。
基于 Ubuntu/Debian :
<span class="pln">service apache2 restart</span>
基于 Centos/Redhat :
<span class="pln">service httpd restart</span>
在 Linux 上安装和配置 Munin 客户端
步骤 1
在 Linux 上安装 Munin 客户端
<span class="kwd">apt-get</span><span class="pln"> install munin</span><span class="pun">-</span><span class="pln">node</span>
注意:如果你想监控你的 Munin 服务器端,你也需要在服务器端安装 munin-node。
步骤 2
编辑 munin-node.conf 文件配置客户端。
<span class="kwd">vi</span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">munin</span><span class="pun">/</span><span class="pln">munin</span><span class="pun">-</span><span class="pln">node</span><span class="pun">.</span><span class="pln">conf</span>
示例:
<span class="pln">allow </span><span class="pun">^</span><span class="lit">127</span><span class="pln">\.</span><span class="lit">0</span><span class="pln">\.</span><span class="lit">0</span><span class="pln">\.</span><span class="lit">1</span><span class="pln">$</span>
<span class="pln">allow </span><span class="pun">^</span><span class="lit">10</span><span class="pln">\.</span><span class="lit">10</span><span class="pln">\.</span><span class="lit">20</span><span class="pln">\.</span><span class="lit">20</span><span class="pln">$</span>
<span class="com">#</span><span class="pun">监听到哪个地址上</span>
<span class="pln">host </span><span class="pun">*</span>
<span class="com">#</span><span class="pun">以及哪个端口</span>
<span class="pln">port </span><span class="lit">4949</span>
注意: 10.10.20.20 是我的 Munin 服务器,它连接到客户端的 4949 端口获取数据。
步骤 3
在客户端机器中重启 munin-node:
<span class="pln">service munin</span><span class="pun">-</span><span class="pln">node restart</span>
测试连接
检查你是否能从服务器的连接到客户端的 4949 端口,如果不行,你需要在客户端机器中的防火墙打开该端口。
<span class="pln">telnet db</span><span class="pun">.</span><span class="pln">linuxnix</span><span class="pun">.</span><span class="pln">com </span><span class="lit">4949</span>
访问 Munin web 页面
<span class="pln">http</span><span class="pun">:</span><span class="com">//munin.linuxnix.com/munin/index.html</span>
希望这些能对你配置基本的 Munin 服务器有所帮助。