Rhel 8/CentOS 8上安装和配置Nagios 4
如何在Rhel 8/CentOS 8 Linux机器上安装Nagios Core?
本教程将解释如何在RHEL 8/CentOS 8上安装和配置Nagios 4. Nagios是各种操作系统的开源主机,服务,过程和网络监控工具,如Linux,Windows,BSD,AIX 等。
Nagios使用文本文件配置,并提供了一种用于管理和监视的直观Web界面。
如果出现问题,服务退化或者中断,Nagios将通过电子邮件,短信或者甚至电话发送警报,如果配置为这样做。
按照以下步骤安装和配置RHEL/CentOS 8上的Nagios 4监视服务器。
安装前提条件
在许可模式下设置SELinux:
sudo sed -i 's/SELINUX=.*/SELINUX=permissive/g' /etc/selinux/config sudo setenforce 0
第1步:安装依赖项
建议在更新系统上工作。
sudo dnf update
安装REL/CentOS 8上的构建和运行Nagios Server的所需依赖项。
sudo dnf install @php sudo dnf install @perl @httpd wget unzip glibc automake glibc-common gettext autoconf php php-cli gcc gd gd-devel net-snmp openssl-devel unzip net-snmp postfix net-snmp-utils
我们还可以检查如何在Rhel/CentOS 8上安装开发工具。
sudo dnf groupinstall "Development Tools"
安装后,启动和启用HTTPD和PHP-FPM服务。
sudo systemctl enable --now httpd php-fpm
确认服务状态。
$systemctl status httpd php-fpm ● httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled) Drop-In: /usr/lib/systemd/system/httpd.service.d └─php-fpm.conf Active: active (running) since Mon 2019-03-18 21:07:31 EAT; 17min ago Docs: man:httpd.service(8) Main PID: 794 (httpd) Status: "Running, listening on: port 443, port 80" Tasks: 213 (limit: 11510) Memory: 38.0M CGroup: /system.slice/httpd.service ├─794 /usr/sbin/httpd -DFOREGROUND ├─810 /usr/sbin/httpd -DFOREGROUND ├─811 /usr/sbin/httpd -DFOREGROUND ├─812 /usr/sbin/httpd -DFOREGROUND └─813 /usr/sbin/httpd -DFOREGROUND Mar 18 21:07:30 rhel8.local systemd[1]: Starting The Apache HTTP Server… Mar 18 21:07:31 rhel8.local httpd[794]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using rhel8.local. Set > Mar 18 21:07:31 rhel8.local httpd[794]: Server configured, listening on: port 443, port 80 Mar 18 21:07:31 rhel8.local systemd[1]: Started The Apache HTTP Server. ● php-fpm.service - The PHP FastCGI Process Manager Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; enabled; vendor preset: disabled) Active: active (running) since Mon 2019-03-18 21:07:31 EAT; 17min ago Main PID: 795 (php-fpm) Status: "Processes active: 0, idle: 5, Requests: 0, slow: 0, Traffic: 0req/sec" Tasks: 6 (limit: 11510) Memory: 43.2M CGroup: /system.slice/php-fpm.service ├─ 795 php-fpm: master process (/etc/php-fpm.conf) ├─1023 php-fpm: pool www ├─1030 php-fpm: pool www ├─1033 php-fpm: pool www ├─1043 php-fpm: pool www └─1087 php-fpm: pool www Mar 18 21:07:30 rhel8.local systemd[1]: Starting The PHP FastCGI Process Manager… Mar 18 21:07:31 rhel8.local systemd[1]: Started The PHP FastCGI Process Manager.
我们可以在安装PHP和Apache Httpd Server上看到详细教程。
第2步:下载Nagios Core
查看最新Nagios的版本页面可用。
然后下载并提取Nagios tar包。
cd ~ export VER="4.4.6" curl -SL https://github.com/NagiosEnterprises/nagioscore/releases/download/nagios-$VER/nagios-$VER.tar.gz | tar -xzf
更改为创建的Nagios文件夹。
cd nagios-$VER
第3步:在RHEL 8/CentOS 8上编译Nagios核心 1.
提取存档后,运行配置脚本:
./configure
示例输出。
2
。
使用make命令 all
编译主程序和CGI的选项。
make all
3.
创建用户和组
这会创建Nagios用户和组。
Apache用户也将添加到Nagios组中。
sudo make install-groups-users sudo usermod -a -G nagios apache
4
。
在Rhel/CentOS 8上安装Nagios
安装Nagios Base。
sudo make install
4.
安装init脚本 /lib/systemd/system
。
$sudo 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 /etc/systemd/system/multi-user.target.wants/nagios.service → /usr/lib/systemd/system/nagios.service. *** Init script installed ***
5.
安装并配置用于保存外部命令文件的目录的权限。
$sudo 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 ***
6.
安装示例配置文件 /usr/local/nagios/etc
。
$sudo make install-config /usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/etc /usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/etc/objects /usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/nagios.cfg /usr/local/nagios/etc/nagios.cfg /usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/cgi.cfg /usr/local/nagios/etc/cgi.cfg /usr/bin/install -c -b -m 660 -o nagios -g nagios sample-config/resource.cfg /usr/local/nagios/etc/resource.cfg /usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/templates.cfg /usr/local/nagios/etc/objects/templates.cfg /usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/commands.cfg /usr/local/nagios/etc/objects/commands.cfg /usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/contacts.cfg /usr/local/nagios/etc/objects/contacts.cfg /usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/timeperiods.cfg /usr/local/nagios/etc/objects/timeperiods.cfg /usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/localhost.cfg /usr/local/nagios/etc/objects/localhost.cfg /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.
7.
安装Nagios Web界面的Apache配置文件。
$sudo 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 ***
8.
为Nagios Web界面安装exfoliation主题。
$sudo make install-exfoliation *** Exfoliation theme installed *** NOTE: Use 'make install-classicui' to revert to classic Nagios theme
9.
为Nagios Web界面安装Classic主题。
$sudo make install-classicui *** Classic theme installed *** NOTE: Use 'make install-exfoliation' to use new Nagios theme
第4步:创建Nagios Web用户
我们需要添加一个用户帐户来访问Nagios Web界面。
为此,我们将使用 htpasswd
写信给 /usr/local/nagios/etc/htpasswd.users
文件。
$sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin New password: Re-type new password: Adding password for user nagiosadmin
输入和确认用户的密码。
我们还需要重新启动Apache服务以进行更改以生效:
sudo systemctl restart httpd
第5步:安装Nagios插件
Nagios插件用于扩展Nagios监控功能。
cd ~
从GitHub发布页面下载Nagios插件。
VER="2.3.3" curl -SL https://github.com/nagios-plugins/nagios-plugins/releases/download/release-$VER/nagios-plugins-$VER.tar.gz | tar -xzf
更改为插件源目录:
cd nagios-plugins-$VER
通过在下面的运行命令编译并安装Nagios插件。
./configure --with-nagios-user=nagios --with-nagios-group=nagios make sudo make install
我们应该在成功编译时看到下面的输出。
..... configure: creating ./config.status config.status: creating gl/Makefile config.status: creating nagios-plugins.spec config.status: creating tools/build_perl_modules config.status: creating Makefile config.status: creating tap/Makefile config.status: creating lib/Makefile config.status: creating plugins/Makefile config.status: creating lib/tests/Makefile config.status: creating plugins-root/Makefile config.status: creating plugins-scripts/Makefile config.status: creating plugins-scripts/utils.pm config.status: creating plugins-scripts/utils.sh config.status: creating perlmods/Makefile config.status: creating test.pl config.status: creating pkg/solaris/pkginfo config.status: creating po/Makefile.in config.status: creating config.h config.status: config.h is unchanged config.status: executing depfiles commands config.status: executing libtool commands config.status: executing po-directories commands config.status: creating po/POTFILES config.status: creating po/Makefile ....... make[1]: Leaving directory '/usr/src/nagios-plugins-2.2.1/po' make[1]: Entering directory '/usr/src/nagios-plugins-2.2.1' make[2]: Entering directory '/usr/src/nagios-plugins-2.2.1' make[2]: Nothing to be done for 'install-exec-am'. make[2]: Nothing to be done for 'install-data-am'. make[2]: Leaving directory '/usr/src/nagios-plugins-2.2.1' make[1]: Leaving directory '/usr/src/nagios-plugins-2.2.1'
第6步:验证安装并启动Nagios服务
确认Nagios安装成功并工作。
$sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg Nagios Core 4.4.5 Copyright (c) 2009-present Nagios Core Development Team and Community Contributors Copyright (c) 1999-2009 Ethan Galstad Last Modified: 2019-08-20 License: GPL Website: https://www.nagios.org Reading configuration data… Read main config file okay… Read object config files okay… Running pre-flight check on configuration data… 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 systemctl enable --now nagios Created symlink /etc/systemd/system/multi-user.target.wants/nagios.service → /usr/lib/systemd/system/nagios.service.
服务状态应指示运行。
$systemctl status nagios ● nagios.service - Nagios Core 4.4.3 Loaded: loaded (/usr/lib/systemd/system/nagios.service; enabled; vendor preset: disabled) Active: active (running) since Mon 2019-03-18 22:55:35 EAT; 18s ago Docs: https://www.nagios.org/documentation Process: 29161 ExecStart=/usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg (code=exited, status=0/SUCCESS) Process: 29159 ExecStartPre=/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg (code=exited, status=0/SUCCESS) Main PID: 29162 (nagios) Tasks: 6 (limit: 11510) Memory: 2.9M CGroup: /system.slice/nagios.service ├─29162 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg ├─29163 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh ├─29164 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh ├─29165 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh ├─29166 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh └─29167 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg Mar 18 22:55:35 rhel8.local nagios[29162]: qh: Socket '/usr/local/nagios/var/rw/nagios.qh' successfully initialized Mar 18 22:55:35 rhel8.local nagios[29162]: qh: core query handler registered Mar 18 22:55:35 rhel8.local nagios[29162]: qh: echo service query handler registered Mar 18 22:55:35 rhel8.local nagios[29162]: qh: help for the query handler registered Mar 18 22:55:35 rhel8.local nagios[29162]: wproc: Successfully registered manager as @wproc with query handler Mar 18 22:55:35 rhel8.local nagios[29162]: wproc: Registry request: name=Core Worker 29165;pid=29165 Mar 18 22:55:35 rhel8.local nagios[29162]: wproc: Registry request: name=Core Worker 29163;pid=29163 Mar 18 22:55:35 rhel8.local nagios[29162]: wproc: Registry request: name=Core Worker 29164;pid=29164 Mar 18 22:55:35 rhel8.local nagios[29162]: wproc: Registry request: name=Core Worker 29166;pid=29166 Mar 18 22:55:36 rhel8.local nagios[29162]: Successfully launched command file worker with pid 29167
第7步:访问Nagios Web Dashboard
允许防火墙上的HTTP和HTTPS协议。
sudo firewall-cmd --permanent --add-service={http,https} sudo firewall-cmd --reload
在安装过程中,添加了Nagios的Apache配置文件。
我们可以访问仪表板 http:[IP/hostname]/nagios/
使用前面添加的用户名和密码进行身份验证。
Username: nagiosadmin
我们应该看到Nagios仪表板,我们可以其中添加要监视的设备。