Contents
Nagios Server, open source integrated monitoring software
Nagios is an open source monitoring solution running on Linux.
Nagios is designed to periodically check critical network, application, or server parameters.
These parameters include microprocessor load, number of running processes, log files, disk and memory usage, as well as many other services such as SMTP (Simple Mail Transfer Protocol), HTTP (Hypertext Transfer Protocol), POP3 (Post Office Protocol 3), etc. can be checked.
These parameters require a microprocessor load, a database such as PHP or MySQL to run Nagois, and a web server such as Apache or Nginx. We will proceed under the assumption that all of these have already been configured.
SELinux must be set to permissive
1 2 3 4 5 6 7 |
# setenforce 0 && sed -i 's/^SELINUX=.*/SELINUX=permissive/g' /etc/selinux/config # cat /etc/selinux/config | grep SELINUX= # SELINUX= can take one of these three values: # NOTE: In earlier Fedora kernel builds, SELINUX=disabled would also #SELINUX=enforcing SELINUX=permissive |
1. Install necessary packages
1 |
# dnf -y install gcc glibc glibc-common gd gd-devel make net-snmp openssl-devel |
Start and enable Apache and PHP-FPM
1 |
# systemctl enable --now httpd php-fpm |
2. Installing Nagios Core
①Download
To download the latest Nagios Core source code, go to the Nagios download page and check for the latest release version (as of 2022.11.3).
1 2 3 4 |
# VER=4.4.8 # wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-$VER.tar.gz # tar xzf nagios-$VER.tar.gz -y |
②Install
1 2 |
# cd nagios-$VER/ # ./configure |
It appears as follows
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
checking for a BSD-compatible install... /usr/bin/install -c checking build system type... x86_64-pc-linux-gnu checking host system type... x86_64-pc-linux-gnu --omission-- config.status: creating lib/snprintf.h config.status: creating lib/iobroker.h Creating sample config files in sample-config/ ... *** Configuration summary for nagios 4.4.8 2022-10-04 ***: General Options: ------------------------- Nagios executable: nagios Nagios user/group: nagios,nagios Command user/group: nagios,nagios Event Broker: yes Install ${prefix}: /usr/local/nagios Install ${includedir}: /usr/local/nagios/include/nagios Lock file: /run/nagios.lock Check result directory: /usr/local/nagios/var/spool/checkresults Init directory: /lib/systemd/system Apache conf.d directory: /etc/httpd/conf.d Mail program: /usr/bin/mail Host OS: linux-gnu IOBroker Method: epoll Web Interface Options: ------------------------ HTML URL: http://localhost/nagios/ CGI URL: http://localhost/nagios/cgi-bin/ Traceroute (used by WAP): /usr/bin/traceroute Review the options above for accuracy. If they look okay, type 'make all' to compile the main program and CGIs |
compile
1 |
# make all |
It appears as follows
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
- This installs the Exfoliation theme for the Nagios web interface make install-classicui - This installs the classic theme for the Nagios web interface *** Support Notes ******************************************* If you have questions about configuring or running Nagios, please make sure that you: - Look at the sample config files - Read the documentation on the Nagios Library at: https://library.nagios.com before you post a question to one of the mailing lists. Also make sure to include pertinent information that could help others help you. This might include: - What version of Nagios you are using - What version of the plugins you are using - Relevant snippets from your config files - Relevant error messages from the Nagios log file For more information on obtaining support for Nagios, visit: https://support.nagios.com ************************************************************* Enjoy. |
Install Nagios Core
1 |
# make install |
Install Nagios init script
1 2 3 |
# make install-init /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 |
Install external command files and permissions
1 2 3 4 |
# 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 *** |
Install Nagios Configuration Files
1 2 3 4 5 |
# make install-config *** 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. |
Install Apache configuration files for Nagios
1 2 3 4 5 6 |
# 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 *** |
③Create Nagios Users and Groups
1 |
# make install-groups-users |
Add Apache User to Nagios Group
1 |
# usermod -aG nagios apache |
3. Install Nagios Plugin
①Download the latest code from the Nagios Plugins page
1 |
# wget https://nagios-plugins.org/download/nagios-plugins-2.3.3.tar.gz |
②Install
1 2 3 4 5 |
# tar -xvf nagios-plugins- 2.3.3.tar.gz # cd nagios-plugins- 2.3.3 # ./configure --with-nagios-user=nagios --with-nagios-group=nagios # make # make install |
③Create necessary directories
1 2 |
# mkdir -p /usr/local/nagios/var/spool/checkresults # chown -R nagios:nagios /usr/local/nagios/var/spool/checkresults |
4. Creating a Nagios Web User
Create a user account to access the Nagios Web Dashboard. This user account is used for authentication.
The default name of the user is nagiosadmin, which is defined as the preferred user name in the /usr/local/nagios/etc/cgi.cfg file.
1 2 3 4 |
# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin New password: Re-type new password: Adding password for user nagiosadmin |
Set ownership and permissions
1 2 |
# chown apache:apache /usr/local/nagios/etc/htpasswd.users # chmod 640 /usr/local/nagios/etc/htpasswd.users |
Restart Apache
1 |
# systemctl restart httpd |
Allow HTTP service port in firewall
1 2 |
# firewall-cmd --add-port=80/tcp --permanent # firewall-cmd --reload |
Start and Enable Nagios Services
1 2 |
# systemctl enable nagios –now Created symlink /etc/systemd/system/multi-user.target.wants/nagios.service → /usr/lib/systemd/system/nagios.service. |
Reboot system
1 |
# shutdown -r now |
Confirmation of service execution
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# systemctl status nagios ● nagios.service - Nagios Core 4.4.8 Loaded: loaded (/usr/lib/systemd/system/nagios.service; enabled; vendor pr> Active: active (running) since Wed 2022-11-02 20:36:36 JST; 1min 10s ago Docs: https://www.nagios.org/documentation Process: 832 ExecStartPre=/usr/local/nagios/bin/nagios -v /usr/local/nagios> Process: 842 ExecStart=/usr/local/nagios/bin/nagios -d /usr/local/nagios/et> Main PID: 843 (nagios) Tasks: 6 (limit: 10944) Memory: 21.0M CPU: 56ms CGroup: /system.slice/nagios.service tq843 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios> tq844 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/> tq845 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/> tq846 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/> tq847 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/> mq850 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios> |
5. Access the Nagios Web Interface
Access http://[IP_Address]/nagios/ with any browser
Username : nagoisadmin
Password : Password specified when the user was created above
Click [Sign in]
After successful login, the following dashboard will appear
Show host availability
Click on [Hosts] in the left menu
Click [Tactical Overview] on the left menu to view the monitoring data
6. Nagios Agent Configuration
To monitor the agent. Install the following
• Nagios plugins for data collection
• NRPE Agent to run plugins
6.1 Installing Nagios plugins
Install using the EPEL repository
1 |
# dnf install epel-release |
Available Nagios Plugins
1 |
# dnf list nagios-plugins-* |
The following nagios-plugins are available
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
Available Packages nagios-plugins-all.x86_64 2.4.0-7.el9 epel nagios-plugins-apt.x86_64 2.4.0-7.el9 epel nagios-plugins-breeze.x86_64 2.4.0-7.el9 epel nagios-plugins-by_ssh.x86_64 2.4.0-7.el9 epel nagios-plugins-cluster.x86_64 2.4.0-7.el9 epel nagios-plugins-dhcp.x86_64 2.4.0-7.el9 epel nagios-plugins-dig.x86_64 2.4.0-7.el9 epel nagios-plugins-disk.x86_64 2.4.0-7.el9 epel nagios-plugins-disk_smb.x86_64 2.4.0-7.el9 epel nagios-plugins-dns.x86_64 2.4.0-7.el9 epel nagios-plugins-dummy.x86_64 2.4.0-7.el9 epel nagios-plugins-file_age.x86_64 2.4.0-7.el9 epel nagios-plugins-flexlm.x86_64 2.4.0-7.el9 epel nagios-plugins-fping.x86_64 2.4.0-7.el9 epel nagios-plugins-game.x86_64 2.4.0-7.el9 epel nagios-plugins-hpjd.x86_64 2.4.0-7.el9 epel nagios-plugins-http.x86_64 2.4.0-7.el9 epel nagios-plugins-icmp.x86_64 2.4.0-7.el9 epel nagios-plugins-ide_smart.x86_64 2.4.0-7.el9 epel nagios-plugins-ifoperstatus.x86_64 2.4.0-7.el9 epel nagios-plugins-ifstatus.x86_64 2.4.0-7.el9 epel nagios-plugins-ircd.x86_64 2.4.0-7.el9 epel nagios-plugins-ldap.x86_64 2.4.0-7.el9 epel nagios-plugins-load.x86_64 2.4.0-7.el9 epel nagios-plugins-log.x86_64 2.4.0-7.el9 epel nagios-plugins-mailq.x86_64 2.4.0-7.el9 epel nagios-plugins-mrtg.x86_64 2.4.0-7.el9 epel nagios-plugins-mrtgtraf.x86_64 2.4.0-7.el9 epel nagios-plugins-mysql.x86_64 2.4.0-7.el9 epel nagios-plugins-nagios.x86_64 2.4.0-7.el9 epel nagios-plugins-nrpe.x86_64 4.1.0-2.el9 epel nagios-plugins-nt.x86_64 2.4.0-7.el9 epel nagios-plugins-ntp.x86_64 2.4.0-7.el9 epel nagios-plugins-nwstat.x86_64 2.4.0-7.el9 epel nagios-plugins-oracle.x86_64 2.4.0-7.el9 epel nagios-plugins-overcr.x86_64 2.4.0-7.el9 epel nagios-plugins-perl.x86_64 2.4.0-7.el9 epel nagios-plugins-pgsql.x86_64 2.4.0-7.el9 epel nagios-plugins-ping.x86_64 2.4.0-7.el9 epel nagios-plugins-procs.x86_64 2.4.0-7.el9 epel nagios-plugins-real.x86_64 2.4.0-7.el9 epel nagios-plugins-remove_perfdata.x86_64 2.4.0-7.el9 epel nagios-plugins-rpc.x86_64 2.4.0-7.el9 epel nagios-plugins-sensors.x86_64 2.4.0-7.el9 epel nagios-plugins-smtp.x86_64 2.4.0-7.el9 epel nagios-plugins-snmp.x86_64 2.4.0-7.el9 epel nagios-plugins-ssh.x86_64 2.4.0-7.el9 epel nagios-plugins-ssl_validity.x86_64 2.4.0-7.el9 epel nagios-plugins-swap.x86_64 2.4.0-7.el9 epel nagios-plugins-tcp.x86_64 2.4.0-7.el9 epel nagios-plugins-time.x86_64 2.4.0-7.el9 epel nagios-plugins-ups.x86_64 2.4.0-7.el9 epel nagios-plugins-uptime.x86_64 2.4.0-7.el9 epel nagios-plugins-users.x86_64 2.4.0-7.el9 epel nagios-plugins-wave.x86_64 2.4.0-7.el9 epel |
Install the important Nagios plugin.(Install check the processes, disk space, swap space, dns, users, uptime, httpand load, for example)
1 |
# dnf install nagios-plugins-{load,http,users,procs,disk,swap,nrpe,uptime,dns} |
After installation, the package is stored in the path /usr/lib64/nagios/plugins/.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
# ls -1 /usr/lib64/nagios/plugins/ check_disk check_dns check_http check_load check_nrpe check_procs check_swap check_uptime check_users eventhandlers negate urlize utils.sh |
1 2 |
# systemctl enable zabbix-server-mysql zabbix-agent httpd php-fpm # systemctl restart zabbix-server-mysql zabbix-agent httpd php-fpm |
6.2 Installing Nagios NRPE Agent
Install from the EPEL repository
1 |
# dnf install nrpe |
Version Check
1 2 3 |
# nrpe -V NRPE - Nagios Remote Plugin Executor Version: 4.1.0 |
Start and activate the service
1 2 |
# systemctl enable nrpe –now Created symlink /etc/systemd/system/multi-user.target.wants/nrpe.service → /usr/lib/systemd/system/nrpe.service. |
Check if the service is running
1 2 3 4 5 6 7 8 9 10 11 |
# systemctl status nrpe ● nrpe.service - Nagios Remote Plugin Executor Loaded: loaded (/usr/lib/systemd/system/nrpe.service; enabled; vendor pres> Active: active (running) since Wed 2022-11-02 22:24:18 JST; 1min 11s ago Docs: http://www.nagios.org/documentation Main PID: 4396 (nrpe) Tasks: 1 (limit: 10944) Memory: 1.3M CPU: 8ms CGroup: /system.slice/nrpe.service mq4396 /usr/sbin/nrpe -c /etc/nagios/nrpe.cfg -f |
Allow services to pass through the firewall
1 2 |
# firewall-cmd --add-port=5666/tcp --permanent # firewall-cmd --reload |
1 |
# systemctl restart nagios |
Monitoring of added hosts can now be performed from the Nagios Web UI. It will take some time before the host is available.