如何在 Ubuntu 15.04 上安装 Nagios

在本教程中,我们将向您展示如何在 Ubuntu 15.04 上安装 Nagios。 对于那些不知道的人,Nagios 是可用于网络和基础设施监控的开源软件。 Nagios 将监控服务器、交换机、应用程序和服务。 它会在出现问题时向系统管理员发出警报,并在问题得到纠正时发出警报。 可以监控的资源包括 CPU、内存和磁盘空间负载、日志文件、温度或硬件错误。 它可以监控HTTP、SMTP、DNS等服务的各种参数和问题,并在插件的帮助下,可以进行高度扩展。 Nagios Core 最初设计为在 Linux 下运行,尽管它也应该在大多数其他单元下运行。

本文假设您至少具备 Linux 的基本知识,知道如何使用 shell,最重要的是,您将网站托管在自己的 VPS 上。 安装非常简单。 我将向您展示在 ubuntu 15.04 服务器中逐步安装 Nagios。

先决条件

  • 运行以下操作系统之一的服务器:Ubuntu 15.04,以及任何其他基于 Debian 的发行版,如 Linux Mint。
  • 建议您使用全新的操作系统安装来防止任何潜在问题。
  • 对服务器的 SSH 访问(或者如果您在桌面上,则只需打开终端)。
  • 一种 non-root sudo user或访问 root user. 我们建议充当 non-root sudo user,但是,如果您在充当 root 时不小心,可能会损害您的系统。

在 Ubuntu 15.04 上安装 Nagios

步骤 1. 首先,通过运行以下命令确保所有系统包都是最新的 apt-get 终端中的命令。

sudo apt-get update sudo apt-get upgrade

步骤 2. 安装 LAMP 服务器。

需要 Ubuntu 15.04 LAMP 服务器。 如果您没有安装 LAMP,您可以在此处按照我们的指南进行操作。 此外,安装 Nagios 的依赖项:

apt-get install build-essential php5-gd wget libgd2-xpm-dev libapache2-mod-php5 apache2-utils daemon unzip

步骤 3. 为 Nagios 创建用户和组。

useradd nagios groupadd nagcmd usermod -a -G nagcmd nagios usermod -a -G nagcmd www-data

步骤 4. 安装 Nagios 服务和 Nagios 插件。

下载最新的稳定版 Nagios,在撰写本文时它是 4.4.6 版:

cd /tmp/ wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.4.6.tar.gz cd nagios-4.4.6/ sudo ./configure --with-command-group=nagcmd sudo make all sudo make install sudo make install-init sudo make install-config sudo make install-commandmode sudo make install-webconf

下载最新的 Nagios-plugins 源并使用以下命令进行安装:

cd /tmp wget https://nagios-plugins.org/download/nagios-plugins-2.0.3.tar.gz tar xzf nagios-plugins-2.0.3.tar.gz cd nagios-plugins-2.0.3 ./configure --with-nagios-user=nagios --with-nagios-group=nagios make make install

配置 Nagios

步骤 5. 配置 Nagios。

编辑 /usr/local/nagios/etc/objects/contacts.cfg 使用您喜欢的编辑器配置文件,并将与 nagiosadmin 联系人定义关联的电子邮件地址更改为您希望用于接收警报的地址。

nano /usr/local/nagios/etc/objects/contacts.cfg

更改电子邮件地址字段以接收通知:

[...] define contact{ contact_name nagiosadmin ; Short name of userus generic-contact ; Inherit default values from generic-contact template (defined above) alias Nagios Admin ; Full name of useremail [email protected] ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ****** [...]

步骤 6. 配置 Apache 网络服务器。

nano /etc/apache2/sites-enabled/nagios.conf

如果要从特定 IP 系列访问 Nagios 管理控制台,请编辑以下行,在这里,我只想允许从 192.168.1.0/24 系列访问 Nagios 管理控制台:

[...] ## Comment the following lines ## #   Order allow,deny #   Allow from all  ## Uncomment and Change lines as shown below ## Order deny,allow Deny from all Allow from 127.0.0.1 192.168.1.0/24 [...]

使能够 Apache的重写和 cgi 模块:

sudo a2enmod rewrite sudo a2enmod cgi

配置 Apache 验证:

我们需要为用户 nagiosadmin 设置密码。 此用户名将用于访问 Web 界面,因此请务必记住您将在此处输入的密码。 运行以下命令设置密码并输入两次密码:

# sudo htpasswd -s -c /usr/local/nagios/etc/htpasswd.users nagiosadmin New password: Re-type new password: Adding password for user nagiosadmin

重新开始 Apache 使更改生效:

systemctl restart apache2

步骤 7. 验证并启动 Nagios 服务。

接下来,我们要让 Nagios 在启动时启动,所以首先验证配置文件没有错误运行以下命令:

sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

你应该得到输出:

[...] Checking objects...     Checked 8 services.     Checked 1 hosts.     Checked 1 host groups.     Checked 0 service groups.     Checked 1 contacts.     Checked 1 contact groups.     Checked 24 commands.     Checked 5 time periods.     Checked 0 host escalations.     Checked 0 service escalations. Checking for circular paths...     Checked 1 hosts     Checked 0 service dependencies     Checked 0 host dependencies     Checked 5 timeperiods Checking global event handlers... Checking obsessive compulsive processor commands... Checking misc settings...  Total Warnings: 0 Total Errors:   0  Things look okay - No serious problems were detected during the pre-flight check [...]

如果没有错误,启动 Nagios 服务并让它在每次启动时自动启动:

sudo service nagios start

当您尝试启动 Nagios 并使用 Nagios 启动脚本时出现以下错误。 要修复此错误,请复制 /etc/init.d/skeleton/etc/init.d/nagios 使用以下命令:

cp /etc/init.d/skeleton /etc/init.d/nagios

编辑文件 /etc/init.d/nagios:

nano /etc/init.d/nagios

添加以下行:

DESC="Nagios" NAME=nagios DAEMON=/usr/local/nagios/bin/$NAME DAEMON_ARGS="-d /usr/local/nagios/etc/nagios.cfg" PIDFILE=/usr/local/nagios/var/$NAME.lock

最后,您需要更改权限:

chmod +x /etc/init.d/nagios

您可以使用以下命令启动 Nagios:

/etc/init.d/nagios start

步骤 8. 从 Web 浏览器访问 Nagios。

Nagios 创建自己的 apache 配置文件 /etc/httpd/conf.d/nagios.conf. 无需对其进行任何更改。 只需在浏览器中打开 URL https://nagios-server-ip/nagios.

当提示输入用户名和密码时,您将输入用户名“nagiosadmin”和您在步骤 6 中输入的密码。如果您忘记了此密码,您可以通过在步骤 5 中重新运行 htpasswd 命令来修改它。

恭喜! 您已成功安装 Nagios。 感谢您使用本教程在 ubuntu 15.04 系统中安装 Nagios。 如需更多帮助或有用信息,我们建议您查看 Nagios 官方网站.

Save

Save