Nagios
How to Install Nagios 4.3.2 on CentOS 7 / RHEL 7
systemctl restart nagios.service
service nagios restart
Nagios Image File Location: cd /usr/local/nagios/share/images/logos
READ: Install LAMP Server on CentOS 7 / RHEL 7
Install all packages in a single command.
yum -y install gcc glibc glibc-common gd gd-devel make net-snmp openssl-devel xinetd httpd php wget perl unzip zip
Create a nagios user and nagcmd group for allowing the external commands to be executed through the web interface, add the nagios and apache user to be a part of nagcmd group.
useradd nagios
passwd nagios
groupadd nagcmd
usermod -a -G nagcmd nagios
usermod -a -G nagcmd apache
Download latest Nagios Core.
https://www.nagios.org/downloads/nagios-core/thanks/
https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.4.2.tar.gz
cd /tmp/ wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.3.2.tar.gz tar -zxvf /tmp/nagios-4.*.tar.gz cd /tmp/nagios-4.*
Compile and Install Nagios.
./configure --with-nagios-group=nagios --with-command-group=nagcmd make all make install make install-init make install-config make install-commandmode
Install & Configure Nagios Web Interface:
Install the Nagios web configuration using the following command.
make install-webconf
Run the following command to install a Nagios exfoliation theme
make install-exfoliation
Create a user account (nagiosadmin) for logging into the Nagios web interface. Remember the password that you assign to this user – you’ll need it later.
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
Restart Apache web server to make the new settings take effect.
systemctl restart httpd.service systemctl enable httpd.service
Configure Nagios:
Sample configuration files have now been installed in the /usr/local/nagios/etc directory. These sample files should work fine for getting started with Nagios. You’ll need to make just one change before you proceed…
Edit the /usr/local/nagios/etc/objects/contacts.cfg config file with your favorite editor and change the email address associated with the nagiosadmin contact definition to the address you’d like to use for receiving alerts.
vi /usr/local/nagios/etc/objects/contacts.cfg
Change the Email address field to receive the notification.
define contact{ contact_name nagiosadmin ; Short name of user use generic-contact ; Inherit default values from generic-contact template (defined above) alias Nagios Admin ; Full name of user email admin@itzgeek.com ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ****** }
Download and Install Nagios Plugins:
Download Nagios Plugins to /tmp directory.
cd /tmp wget https://nagios-plugins.org/download/nagios-plugins-2.2.1.tar.gz tar -zxvf /tmp/nagios-plugins-*.tar.gz cd /tmp/nagios-plugins-*/
Compile and install the Nagios plugins.
./configure --with-nagios-user=nagios --with-nagios-group=nagios make make install
Start Nagios Server:
Verify the sample Nagios configuration files.
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
If there are no errors, then start the Nagios service.
systemctl restart nagios.service
service nagios start
Start Nagios on system startup.
systemctl enable nagios.service
chkconfig nagios on
SELinux:
See if SELinux is in Enforcing mode.
getenforce
Put SELinux in Permissive mode or Disable it.
setenforce 0
systemctl start nagios chkconfig --add nagios chkconfig nagios on
To make this change permanent, you’ll have to modify the settings in /etc/selinux/config and reboot.
Iptables:
Make sure to allow web server access through the firewall.
firewall-cmd --permanent --zone=public --add-service=http firewall-cmd --reload
Access Web Interface:
Now access the Nagios web interface using the following URL. You’ll be prompted for the username: (nagiosadmin) and password you specified earlier.
http://your-ip-add-ress/nagios/
Install Nagios 4.3.2 on CentOS 7 – Login Screen
Nagios console will look like below.
Install Nagios 4.3.2 on CentOS 7 – Home Page
Click on Hosts in the left pane to get a list of systems being monitored by Nagios. We have not added any host to Nagios, So it simply monitors the localhost itself. To monitor a remote Linux system,
Install Nagios 4.3.2 on CentOS 7 – Hosts List
Click on Service in the left pane to get the status of any services that is being monitored with Nagios.
Install Nagios 4.3.2 on CentOS 7 – Services
That’s All. In our next article, we will monitor Remote Linux System with Nagios Server.
--------------------
NRPE Plugin:
The NRPE (Nagios Remote Plugin Executor) plugin allows you monitor any application or service running on remote Linux / Windows machines. This NRPE Add-on helps Nagios to monitor any local resources like CPU, Memory, Disk, Swap, etc on remote machines. Finally, you must have this NRPE plugin installed on the remote machine.
[root@tecmint nagios-plugins-2.1.2]# cd /root/nagios
[root@tecmint nagios]# wget http://liquidtelecom.dl.sourceforge.net/project/nagios/nrpe-3.x/nrpe-3.0.tar.gz
wget https://mirrors.netix.net/sourceforge/n/na/nagios/nrpe-3.x/nrpe-3.0.0/nrpe-3.0.tar.gz
wget https://github.com/NagiosEnterprises/nrpe/archive/3.0.1.tar.gz
[root@tecmint nagios]# tar xzf nrpe-3.0.tar.gz
[root@tecmint nrpe-3.0]# cd nrpe-3.0
./configure
make all
make install-plugin
make install-daemon
make install-daemon-config
[root@tecmint nrpe-3.0]# make install-xinetd
OR
[root@tecmint nrpe-3.0]# make install-inetd
########################################################################
Before proceeding the installation, add the “nagios” user and “nagcmd” group.
su -l
Create a new user in the name of “nagios” and give it a password.
useradd nagios
Set the password.
passwd nagios
Download & Install Nagios Plugin:
Download the Nagios and the Nagios plugins on the remote host using the following command ( For latest version Visit Nagios WebSite )
wget http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.16.tar.gz
Extract the Nagios plugins source code tarball.
tar -zxvf nagios-plugins-1.4.16.tar.gz cd nagios-plugins-1.4.16
Compile and install the plugins. While compiling, i got an error; here is the Nagios troubleshooting Tutorial.
./configure --with-nagios-user=nagios --with-nagios-group=nagios make make install
Change the permission of the Nagios plugin directory on the remote host.
chown nagios.nagios /usr/local/nagios chown -R nagios.nagios /usr/local/nagios/libexec/
Download and install NRPE Add-on:
Visit the Nagios download page and download the NRPE Add-on.
wget http://prdownloads.sourceforge.net/sourceforge/nagios/nrpe-2.13.tar.gz
Once downloaded, Extract the tarball.
tar -zxvf nrpe-2.13.tar.gz cd nrpe-2.13
Compile it.
./configure make all make install-plugin make install-daemon make install-daemon-config make install-xinetd
Configure NRPE Add-on:
NRPE is the part of the xinetd daemon, modify the NRPE configurations file to accept the connection from the Nagios server, Edit the /etc/xinetd.d/nrpe.
vi /etc/xinetd.d/nrpe
Add the Nagios server IP address like below.
only_from = 127.0.0.1 192.168.0.151
Add NRPE port at the end of the /etc/services file.
nrpe 5666/tcp # NRPE
Restart the xinetd.d service.
##########################################################################################
----------------------Just for restart----------------------Config VNC --------------
Install the tigervnc server, X11 fonts and xinetd.
[root@server ~]# yum install tigervnc-server xorg-x11-fonts-Type1 xinetd
Enable the XDMCP.
[root@server ~]# vi /etc/gdm/custom.conf
Add the following content.
[security] AllowRemoteRoot=true DisallowTCP=false [xdmcp] Enable=true MaxSessions=30
Create Xinetd service.
[root@server ~]# vi /etc/xinetd.d/vncserver
Place the following content on the above file.
service vncserver { disable = no socket_type = stream protocol = tcp group = tty wait = no user = nobody server = /usr/bin/Xvnc server_args = -inetd -query localhost -geometry 1024×768 -depth 16 -once -fp /usr/share/X11/fonts/misc -securitytypes=none }
Create VNC service.
[root@server ~]# vi /etc/services
Add the following line at the end of file.
vncserver 5900/tcp # VNC and GDM
Restart xinetd service
[root@server ~]# systemctl restart xinetd.service
Add firewall rules to allow the VNC connection, the following rule is set as per the port-offset mentioned in the previous step.
[root@server ~]# firewall-cmd --permanent --zone=public --add-port=5900/tcp [root@server ~]# firewall-cmd --reload
Reboot the machine, if required.
[root@server ~]# reboot
Use VNC viewer to connect.
ipaddress:5900
###################################################################################
systemctl restart xinetd.service
/etc/init.d/xinetd restart
Confirm that NRPE Listening.
netstat -at | grep nrpe tcp 0 0 *:nrpe *:* LISTEN
Confirm the NRPE functioning.
/usr/local/nagios/libexec/check_nrpe -H localhost NRPE v2.13
Modify NRPE Config file:
Edit the vi /usr/local/nagios/etc/nrpe.cfg on the remote host, it contains the command argument to check the service on the remote host. The nrpe.cfg file contains the basic commands to check the remote services, below are the command lines to check the CPU load and running process. The check_load and check_total_procshas to be entered on template file on the server host to enable the monitoring.
command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20 command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 150 -c 200
In the above command -w stands for warning whereas -c stands for critical alert. For example if you execute the second command on the terminal, it will check the running process; it will warn when the process more than 150 or it will report critical when the process more than 200 and at the same time it will say OK if process below 150.
/usr/local/nagios/libexec/check_procs -w 150 -c 200
Output:
PROCS OK: 112 processes
Change warning to 100 and critical to 150 for testing purpose. Now you can see the warning message, according to your requirement you can modify it.
/usr/local/nagios/libexec/check_procs -w 100 -c 150
Output:
PROCS WARNING: 112 processes
Nagios Server Host:
Install NRPE Add-on:
Visit the Nagios download page and download the NRPE Add-on.
wget http://prdownloads.sourceforge.net/sourceforge/nagios/nrpe-2.13.tar.gz
Once downloaded, Extract the tarball.
tar -zxvf nrpe-2.13.tar.gz cd nrpe-2.13
Compile it.
./configure make all make install-plugin
Configure Nagios Server:
Now its the time configure the nagios server to monitor the remote client, You’ll need to create a command definition in one of your Nagios object configuration files in order to use the check_nrpe plugin. Open the sample commands.cfg file for editing…
vi /usr/local/nagios/etc/objects/commands.cfg
Add the following command definition to the file.
define command{ command_name check_nrpe command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$ }
OR
# .check_nrpe. command definition define command{ command_name check_nrpe command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -t 30 -c $ARG1$ }
Create the new configuration file (/usr/local/nagios/etc/objects/remote.cfg) to define the host and service definition. You can use the following template, modify according to your requirement. The following is configured to display the Swap,CPU Load,Disk Space,Current Users. Etc..,
define host{ use linux-server host_name linuxclient1.iii.local alias Client 1 address 192.168.0.152 } define hostgroup{ hostgroup_name Linux Client alias Linux Client 1 members linuxclient1.iii.local } define service{ use local-service host_name linuxclient1.iii.local service_description SWAP Uasge check_command check_nrpe!check_swap } define service{ use local-service host_name linuxclient1.iii.local service_description Root Partition check_command check_nrpe!check_sda1 } define service{ use local-service host_name linuxclient1.iii.local service_description Current Users check_command check_nrpe!check_users } define service{ use local-service host_name linuxclient1.iii.local service_description Total Processes check_command check_nrpe!check_total_procs } define service{ use local-service host_name linuxclient1.iii.local service_description Current Load check_command check_nrpe!check_load }
OR
------------------------------
define host{
use linux-server
host_name mail.worldcm.net
alias worldCm
address 103.20.140.24
}
define hostgroup{
hostgroup_name Linux Client
alias Linux worldCm
members mail.worldcm.net
}
define service{
use local-service
host_name mail.worldcm.net
service_description SWAP Uasge
check_command check_nrpe!check_swap
}
define service{
use local-service
host_name mail.worldcm.net
service_description Root Partition
check_command check_nrpe!check_sda1
}
define service{
use local-service
host_name mail.worldcm.net
service_description Current Users
check_command check_nrpe!check_users
}
define service{
use local-service
host_name mail.worldcm.net
service_description Total Processes
check_command check_nrpe!check_total_procs
}
define service{
use local-service
host_name mail.worldcm.net
service_description Current Load
check_command check_nrpe!check_load
}
---------
Add the new template on the nagios.cfg configuration file, so that it will read the new entries.
vi /usr/local/nagios/etc/nagios.cfg
Add just below.
# Definitions for monitoring the Remote (Linux) cfg_file=/usr/local/nagios/etc/objects/remote.cfg
Now find an uncomment this line by deleting the #
# cfg_dir=/usr/local/nagios/etc/servers
Restart the Nagios server.
systemctl restart nagios.service
service nagios restart
Monitor the remote machine:
Now login to the web interface and start do the monitoring. The following screenshot shows the remote Linux box with the default service available (which were taken from the localhost.cfg).
That’s All
----------------------