如何在 Ubuntu 14.04 上安装 Nagios

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

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

先决条件

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

在 Ubuntu 14.04 上安装 Nagios

步骤 1. 安装 Nagios 的依赖项。

apt-get update apt-get install build-essential apache2 php5 openssl perl make php5-gd libgd2-xpm-dev libapache2-mod-php5 libperl-dev libssl-dev daemon wget apache2-utils

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

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

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

从官网下载最新的 Nagios 源代码:

cd /tmp/ wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.4.6.tar.gz tar xzf nagios-4.4.6.tar.gz cd nagios-4.4.6 ./configure --with-command-group=nagcmd make all make install make install-init make install-config make install-commandmode 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

步骤 4. 配置 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 ****** [...]

步骤 5. 配置 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的重写和 CGI​​ 模块:

sudo a2enmod rewrite sudo a2enmod cgi

步骤 6. 验证并启动 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 [...]

步骤 7. 启动 Apache 和 Nagios 服务。

/etc/init.d/nagios start /etc/init.d/httpd start

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

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

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

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

Save