在 CentOS 7 服务器上安装 Nagios 插件
使用 yum 命令安装 Nagios 插件的准备工作包。
[root@nagios-01 nagios-4.4.2]# yum install -y perl-Net-SNMPyum install -y gcc glibc glibc-common make gettext automake autoconf wget openssl-devel net-snmp net-snmp-utils epel-release [root@nagios-01 nagios-4.4.2]# yum install -y perl-Net-SNMP
从 https://www.nagios.org/downloads/nagios-plugins/ 下载 Nagios 插件。
[root@nagios-01 ~]# cd ~/setup [root@nagios-01 setup]# wget https://nagios-plugins.org/download/nagios-plugins-2.2.1.tar.gz
提取下载的 Nagios 插件源。
[root@nagios-01 nagios-4.4.2]# cd ~/setup [root@nagios-01 setup]# tar xvf nagios-plugins-2.2.1.tar.gz
编译 Nagios 插件源。
[root@nagios-01 setup]# cd ~/setup/nagios-plugins-2.2.1 [root@nagios-01 nagios-plugins-2.2.1]# ./configure
安装 Nagios 插件。
[root@nagios-01 nagios-plugins-2.2.1]# make [root@nagios-01 nagios-plugins-2.2.1]# make install
转到 Nagios Web UI 并打开服务页面。
我们可以看到,现在所有服务都处于 OK 状态。
(Nagios Core 需要一段时间来收集每个服务的数据)
我们已经在 CentOS 7 服务器上成功安装和配置了 Nagios Core 4.4.
Nagios Core 是一个免费的开源软件应用程序,可为服务器、交换机、应用程序和服务提供监控和警报服务。
它监视目标(即主机和服务)并在出现问题时提醒用户,并在问题解决后再次提醒他们。
Nagios Core 是主要的应用程序以及监控和警报引擎,大约构建了数百个 Nagios 项目。
在本文中,我们将在 CentOS 7 服务器上安装和配置 Nagios Core 4.4.
在 CentOS 7 上安装 Nagios Core 4.4
使用 yum 命令安装必备软件包。
[root@nagios-01 setup]# yum install -y gcc glibc glibc-common wget unzip httpd php gd gd-devel perl postfix
目前,Nagios Core 不符合 SELinux,因此我们必须禁用 SELinux。
[root@nagios-01 setup]# sed -i 's/SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config [root@nagios-01 setup]# setenforce 0
创建一个用于下载 Nagios Core 源代码的目录。
[root@nagios-01 ~]# mkdir setup
从 https://www.nagios.org/downloads/nagios-core/ 下载 Nagios Core。
[root@nagios-01 ~]# cd ~/setup [root@nagios-01 setup]# wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.4.2.tar.gz
提取 下载的Nagios Core 包。
[root@nagios-01 setup]# tar xvf nagios-4.4.2.tar.gz ... nagios-4.4.2/xdata/xpddefault.h nagios-4.4.2/xdata/xrddefault.c nagios-4.4.2/xdata/xrddefault.h nagios-4.4.2/xdata/xsddefault.c nagios-4.4.2/xdata/xsddefault.h
从提取的源代码中编译并安装 Nagios Core。
[root@nagios-01 setup]# cd ~/setup/nagios-4.4.2 [root@nagios-01 nagios-4.4.2]# ./configure [root@nagios-01 nagios-4.4.2]# make all
为 Nagios Core 创建操作系统用户和组。
[root@nagios-01 nagios-4.4.2]# make install-groups-users groupadd -r nagios useradd -g nagios nagios [root@nagios-01 nagios-4.4.2]# usermod -a -G nagios apache
立即安装 Nagios Core 4.4.
[root@nagios-01 nagios-4.4.2]# make install
安装 Nagios 核心服务。
[root@nagios-01 nagios-4.4.2]# make install-daemoninit /usr/bin/install -c -m 755 -d -o root -g root /lib/systemd/system /usr/bin/install -c -m 755 -o root -g root startup/default-service /lib/systemd/system/nagios.service Created symlink from /etc/systemd/system/multi-user.target.wants/nagios.service to /usr/lib/systemd/system/nagios.service. *** Init script installed ***
启用 httpd 服务。
[root@nagios-01 nagios-4.4.2]# systemctl enable httpd.service Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
安装和配置外部命令文件。
[root@nagios-01 nagios-4.4.2]# make install-commandmode /usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/var/rw chmod g+s /usr/local/nagios/var/rw *** External command directory configured ***
安装 Nagios Core 的示例配置文件。
[root@nagios-01 nagios-4.4.2]# make install-config /usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/windows.cfg /usr/local/nagios/etc/objects/windows.cfg /usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/printer.cfg /usr/local/nagios/etc/objects/printer.cfg /usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/switch.cfg /usr/local/nagios/etc/objects/switch.cfg *** Config files installed *** Remember, these are *SAMPLE* config files. You'll need to read the documentation for more information on how to actually define services, hosts, etc. to fit your particular needs.
将 Nagios Core 配置添加到 Apache Web 服务器。
[root@nagios-01 nagios-4.4.2]# make install-webconf /usr/bin/install -c -m 644 sample-config/httpd.conf /etc/httpd/conf.d/nagios.conf if [ 0 -eq 1 ]; then \ ln -s /etc/httpd/conf.d/nagios.conf /etc/apache2/sites-enabled/nagios.conf; \ fi *** Nagios/Apache conf file installed ***
配置 Linux 防火墙以允许 http 服务。
[root@nagios-01 nagios-4.4.2]# firewall-cmd --permanent --add-service=http success [root@nagios-01 nagios-4.4.2]# firewall-cmd --reload success
Nagios 没有集成用户身份验证,因此,我们必须为此使用基本 HTTP 身份验证。
为 Nagios Core Web UI 创建一个管理员用户。
[root@nagios-01 nagios-4.4.2]# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin New password: Re-type new password: Adding password for user nagiosadmin
启动 httpd 和 nagios 服务。
[root@nagios-01 nagios-4.4.2]# systemctl start httpd.service [root@nagios-01 nagios-4.4.2]# systemctl start nagios.service Warning: nagios.service changed on disk. Run 'systemctl daemon-reload' to reload units. [root@nagios-01 nagios-4.4.2]# systemctl daemon-reload
浏览 URL http://192.168.1.130/nagios 以连接 Nagios Core Web UI。
使用 nagiosadmin 用户登录。
进入服务页面。
我们可以看到所有服务都不可用。
这是因为我们没有在 CentOS 7 服务器上安装 Nagios 插件。