在 Ubuntu 14.04 LTS 上使用 Munin 和 Monit 进行服务器监控在 Ubuntu 14.04 LTS 上使用 Munin 和 Monit 进行服务器监控在 Ubuntu 14.04 LTS 上使用 Munin 和 Monit 进行服务器监控在 Ubuntu 14.04 LTS 上使用 Munin 和 Monit 进行服务器监控
  • 文章
  • 正则表达式
    • 工具
  • 登录
找到的结果: {phrase} (显示: {results_count} 共: {results_count_total})
显示: {results_count} 共: {results_count_total}

加载更多搜索结果...

搜索范围
模糊匹配
搜索标题
搜索内容
发表 admin at 2025年2月28日
类别
  • 未分类
标签

在 Ubuntu 14.04 LTS 上使用 Munin 和 Monit 进行服务器监控

本教程适用于这些操作系统版本

  • Ubuntu 16.04(Xenial Xerus)
  • Ubuntu 14.04 LTS(Trusty Tahr)

在此页

  1. 1 条初步说明
  2. 2 安装和配置 Munin
  3. 3 密码保护 Munin 输出目录(可选但强烈推荐)
  4. 4 在 Munin 中启用其他模块
  5. 5 在 ISPConfig 中配置 Munin(可选)

本教程将向您展示如何使用 Munin 和 Monit 监控 Ubuntu 14.04 服务器。 Munin 生成关于服务器几乎每个方面的漂亮图表,而 Monit 检查 Apache、MySQL、Postfix 等服务的可用性,并在发现服务未按预期运行时采取适当的措施,例如重启。两者的结合为您提供了全面的监控:让您识别当前或即将出现的问题的图形,以及确保被监控服务可用性的看门狗。本教程包含两个(可选)章节,介绍如何将 Munin 和 Monit 集成到 ISPConfig 中。

1 初步说明

我们的系统主机名是 server1.example.com,我们有一个网站 www.example.com,其文档根目录为 /var/www/www.example.com/web。

以下步骤必须以 root 用户身份执行。要成为您服务器上的根用户,请运行以下命令:

sudo su

在开始安装 Munin 之前确保系统是最新的,运行:

apt-get update
apt-get upgrade

Apache 用于显示 Munin 页面,Munin 图形缩放功能需要 apache fcgid 模块。我将使用 apt 安装 apache 和 libapache2-mod-fcgid 模块。

apt-get install apache2 libcgi-fast-perl libapache2-mod-fcgid

在 apache 中启用 fcgid 模块。

a2enmod fcgid

2 安装和配置 Munin

要在 Ubuntu 14.04 上安装 Munin,请运行以下命令:

apt-get install munin munin-node munin-plugins-extra

当服务器运行 MySQL 或 MariaDB 时,启用一些额外的 Munin 插件来监控 MySQL:

cd /etc/munin/plugins
ln -s /usr/share/munin/plugins/mysql_ mysql_
ln -s /usr/share/munin/plugins/mysql_bytes mysql_bytes
ln -s /usr/share/munin/plugins/mysql_queries mysql_queries
ln -s /usr/share/munin/plugins/mysql_slowqueries mysql_slowqueries
ln -s /usr/share/munin/plugins/mysql_threads mysql_threads

接下来,我们必须编辑 Munin 配置文件 /etc/munin/munin.conf。取消对 dbdir、htmldir、logdir、rundir 和 tmpldir 行的注释(默认值很好)。我们希望 Munin 在 HTML 输出中使用名称 server1.example.com 而不是 localhost.localdomain,因此,我们在简单主机树部分中将 localhost.localdomain 替换为 server1.example.com。没有注释,更改后的文件如下所示:

nano /etc/munin/munin.conf
# Example configuration file for Munin, generated by 'make build'

# The next three variables specifies where the location of the RRD
# databases, the HTML output, logs and the lock/pid files. They all
# must be writable by the user running munin-cron. They are all
# defaulted to the values you see here.
#
dbdir /var/lib/munin
htmldir /var/cache/munin/www
logdir /var/log/munin
rundir /var/run/munin

# Where to look for the HTML templates
#
tmpldir /etc/munin/templates

# Where to look for the static www files
#
#staticdir /etc/munin/static

# temporary cgi files are here. note that it has to be writable by
# the cgi user (usually nobody or httpd).
#
# cgitmpdir /var/lib/munin/cgi-tmp # (Exactly one) directory to include all files from. includedir /etc/munin/munin-conf.d [...] # a simple host tree
[server1.example.com]
address 127.0.0.1
use_node_name yes [...]

我们应该找到 Munin 的 Apache 配置文件 /etc/munin/apache.conf - 它为 munins HTML 输出目录 /var/cache/munin/www 定义了一个名为 munin 的别名,这意味着我们可以访问 munin使用相对路径 /munin(例如 http://www.example.com/munin)从此服务器上的所有网站。

Ubuntu 14.04 附带的 apache.conf 文件仍然包含旧的 apache 2.2 语法,这对于 apache 2.4 是不正确的,因此我们用一个新文件替换该文件。首先我们备份旧文件。

mv /etc/munin/apache.conf /etc/munin/apache.conf_bak

使用编辑器打开新文件:

nano /etc/munin/apache.conf

并粘贴以下内容:

Alias /munin /var/cache/munin/www
<Directory /var/cache/munin/www>
# Require local
Require all granted
Options FollowSymLinks SymLinksIfOwnerMatch
Options None
</Directory>

ScriptAlias /munin-cgi/munin-cgi-graph /usr/lib/munin/cgi/munin-cgi-graph
<Location /munin-cgi/munin-cgi-graph>
# Require local
Require all granted
Options FollowSymLinks SymLinksIfOwnerMatch
<IfModule mod_fcgid.c>
SetHandler fcgid-script
</IfModule>
<IfModule !mod_fcgid.c>
SetHandler cgi-script
</IfModule>
</Location>

重启阿帕奇:

service apache2 restart

然后重启 Munin:

service munin-node restart

现在等待几分钟,以便 Munin 可以生成第一个输出,然后在浏览器中访问 http://www.example.com/munin/,您会看到第一个统计信息:

(这只是 munin 制作的众多图形中的一小部分……)

3 密码保护 Munin 输出目录(可选但强烈推荐)

现在用密码保护 munin 输出目录是一个好主意,除非您希望每个人都能够看到关于您的服务器的每一个小统计信息。

为此,我们必须创建密码文件 /etc/munin/munin-htpasswd。我们想使用用户名 admin 登录,所以我们这样做:

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

输入管理员密码。然后再次打开 /etc/munin/apache.conf ...

nano /etc/munin/apache.conf

...注释掉 \Require all granted 并添加我用红色标记的行:

Alias /munin /var/cache/munin/www
<Directory /var/cache/munin/www>
# Require local
# Require all granted
AuthUserFile /etc/munin/munin-htpasswd
AuthName "Munin"
AuthType Basic
Require valid-user
Options None
</Directory>

ScriptAlias /munin-cgi/munin-cgi-graph /usr/lib/munin/cgi/munin-cgi-graph
<Location /munin-cgi/munin-cgi-graph>
# Require local
# Require all granted
AuthUserFile /etc/munin/munin-htpasswd
AuthName "Munin"
AuthType Basic
Require valid-user
<IfModule mod_fcgid.c>
SetHandler fcgid-script
</IfModule>
<IfModule !mod_fcgid.c>
SetHandler cgi-script
</IfModule>
</Location>

然后重新启动 Apache:

service apache2 restart

4 在 Munin 中启用附加模块

Munin 命令 \munin-node-configure --suggest\ 可用于获取可在服务器上启用的其他 Munin 模块的建议。跑步:

munin-node-configure --suggest

输出应与此类似:

“已使用”列显示模块是否启用,“建议”列显示服务器是否运行可由该模块监控的服务。在 /etc/munin/plugins 中为模块创建符号链接以启用它。

在这里,我将启用 apache_* 模块,例如:

cd /etc/munin/plugins
ln -s /usr/share/munin/plugins/apache_accesses
ln -s /usr/share/munin/plugins/apache_processes
ln -s /usr/share/munin/plugins/apache_volume

重新启动 Munin 以加载新配置。

service munin-node restart

5 在ISPConfig中配置Munin(可选)

ISPConfig 主机控制面板有一个选项可以在 ISPConfig 监视器模块中显示 Munin 数据。 Munin 数据在 iframe 中加载,因为大多数浏览器会阻止从 https 站点中的 http 加载内容,我们将不得不找到一种通过 SSL 访问 Munin 统计信息的方法。最简单的方法是通过在 ISPConfig web 目录中创建到 Munin www 数据目录的符号链接,使用启用 SSL 的 ISPConfig 虚拟主机。

ln -s /var/cache/munin/www /usr/local/ispconfig/interface/web/munin

现在我们可以通过 ISPConfig apache vhost 在浏览器中使用 https://server1.example.com:8080/munin 访问 Munin。

下一步是在 ISPConfig 中添加配置。

以管理员 (admin) 用户身份登录 ISPConfig,然后转到系统 > 服务器配置,填写 Munin 的 URL、用户名和密码,如下所示。

确保在 munin URL 中使用 https:// 和端口 8080。

©2015-2025 艾丽卡 support@alaica.com