Nagios Is One of The Most Popular Open Source Monitoring Systems
Nagios Is One of The Most Popular Open Source Monitoring Systems
Nagios
keeps an inventory of your entire IT infrastructure and ensures your networks,
servers, applications, services, and processes are up and running. In case of
failure or suboptimal performance Nagios will send notification alerts via
various methods.
This tutorial describes how to install and configure Nagios Core on a CentOS 7
server.
Prerequisites
Before continuing with this tutorial, make sure you are logged in as a user with
sudo privileges.
Update your CentOS system and install Apache, PHP and all the packages
necessary to download and compile the Nagios main application and Nagios
plugins:
sudo yum updatesudo yum install httpd php php-cli gcc glibc glibc-common gd gd-devel
net-snmp openssl-devel wgetsudo yum install make gettext autoconf net-snmp-utils
epel-release perl-Net-SNMP postfix unzip automake
Copy
1. Downloading Nagios
We’ll download Nagios source in the /usr/src directory which is the common
location to place source files.
Before continuing with the next steps, make sure you change to the Nagios
source directory by typing:
cd nagioscore-nagios-*/
Copy
2. Compiling Nagios
To start the build process run the configure script which will perform a number
of checks to make sure all of the dependencies on your system are present:
sudo ./configure
Copy
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: /sbin/sendmail
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): /bin/traceroute
The compilation may take some time, depending on your system. Once the
build process is completed, the following message will be printed on your
screen:
....
*** Compile finished ***
...
For more information on obtaining support for Nagios, visit:
https://support.nagios.com
*************************************************************
Enjoy.
Copy
groupadd -r nagios
useradd -g nagios nagios
Copy
Add the Apache apache user to the nagios group:
Run the following command to install Nagios binary files, CGIs, and HTML
files:
...
*** Main program, CGIs and HTML files installed ***
...
Copy
Nagios can process commands from external applications. Create the external
command directory and set the proper permissions by typing:
Run the command below to install the Apache web server configuration files:
The following command installs a systemd unit file and also configure the
nagios service to start on boot.
To be able to access the Nagios web interface wel’ll create an admin user
called nagiosadmin
New password:
Re-type new password:
Adding password for user nagiosadmin
Copy
If you don’t have a firewall configured on your server, you can check our guide
about how to setup a firewall with firewalld on centos
cd /usr/src/
Copy
Download the latest version of the Nagios Plugins from the project Github
repository:
Run the following commands one by one to compile and install the Nagios
plugins:
Starting Nagios
Now that both Nagios and its plugins are installed, start the Nagios service
with:
To verify that Nagios is running, check the service status with the following
command:
sudo systemctl status nagios
Copy
The output should look something like below indicating that Nagios service is
active and running.
nagios.service - Nagios Core 4.4.2
Loaded: loaded (/usr/lib/systemd/system/nagios.service; enabled; vendor preset:
disabled)
Active: active (running) since Sat 2018-12-08 14:33:35 UTC; 3s ago
Docs: https://www.nagios.org/documentation
Process: 22217 ExecStart=/usr/local/nagios/bin/nagios -d
/usr/local/nagios/etc/nagios.cfg (code=exited, status=0/SUCCESS)
Process: 22216 ExecStartPre=/usr/local/nagios/bin/nagios -v
/usr/local/nagios/etc/nagios.cfg (code=exited, status=0/SUCCESS)
Main PID: 22219 (nagios)
CGroup: /system.slice/nagios.service
Copy
http(s)://your_domain_or_ip_address/nagios
Copy
Enter the nagiosadmin user login credentials and you will be redirected to the
default Nagios home page as shown on the image below:
Conclusion
You have successfully installed the latest Nagios version from source on your
CentOS system.
You should now check the Nagios Documentation and learn more about how
to configure and use Nagios.
and replace IP_ADDRESS and PORT_NUMBER with your actual server IP address and SSH
port number.
Once logged in, make sure that your server is up-to-date by running the following
command:
yum update
You will also need to enable MariaDB and Apache to start on boot with:
systemctl enable httpd.service
systemctl enable mariadb.service
and run the following command to download the tar archive file:
wget -O nagioscore.tar.gz
https://github.com/NagiosEnterprises/nagioscore/archive/nagios-4.4.2.tar.gz
Once the download is complete, execute the following command to extract the archive
file:
tar xzf nagioscore.tar.gz
and run the following command in order to configure the installer and prepare the
Nagios Core source code for the compilation process:
./configure
After the configuration is completed, you can now compile Nagios Core by execution
the following command:
make all
You also need to run the following commands to create the nagios user and group and
add apacheto the nagios group:
make install-groups-users
usermod -a -G nagios apache
Now, you can finally run the following command in order to install Nagios Core:
make install
To, install the initialization script which can be used to manage your Nagios service, run
the following command:
make install-daemoninit
Next, run the following command to install the Nagios sample configuration files:
make install-config
Run the following command to install and configure the external command file to make
Nagios Core to work from the command line:
make install-commandmode
The following command will install the Apache web server configuration files:
make install-webconf
After all the installations are complete, restart your apache service with:
systemctl restart httpd
With this step, the main Nagios Core installation is now complete. However, for Nagios
Core to operate properly you will also need to install the Nagios Plugins as explained in
the next step.
To download and extract the latest version of the Nagios Plugins to the tmp directory on
your server, run the following commands:
cd /tmp
wget --no-check-certificate -O nagios-plugins.tar.gz https://github.com/nagios-
plugins/nagios-plugins/archive/release-2.2.1.tar.gz
tar zxf nagios-plugins.tar.gz
Once the Nagios Plugins archive is extracted, run the following commands to compile
and install the Nagios Plugins on your server:
cd /tmp/nagios-plugins-release-2.2.1/
./tools/setup
./configure
make
make install
Of course, you don’t have to install Nagios Core on CentOS 7, if you use one of
our premium server management services, in which case you can simply ask our expert
system administrators to install the latest version of Nagios Core on CentOS 7 for you,
using the LAMP stack or any other web hosting stack of your choice. They are available
24×7 and will take care of your request immediately.
PS. If you liked this post, on how to install Nagios Core on CentOS 7, please share it with
your friends on the social networks using the buttons below or simply leave a comment
in the comments section. Thanks.
https://linuxhostsupport.com/blog/how-to-install-nagios-core-on-centos-7/
Install fprobe
——————
Download fprobe from SourceForge Site and install
# tar -xjvf fprobe-1.11.tar.bz2
# cd fprobe-1.11
# ./configure
# make
# make install
Now run fprobe using command – /usr/local/sbin/fprobe -i eth0 -f”ip” -n7 remote:port
e.g.
# /usr/local/sbin/fprobe -i eth0 -f”ip” -n7 127.0.0.1:9995
and make sure that the process is running using ‘ps aux’ command.
Nfdump installation
———————-
Download nfdump from SourceForge Site and install
# tar -zxvf nfdump-1.6.11.tar.gz
# cd nfdump-1.6.11
nfdump-1.6.11]# ./configure –enable-nfprofile –enable-nftrack –enable-nfpcapd
nfdump-1.6.11]# make
nfdump-1.6.11]# make install
### You can check whether nfcapd can collect network data or not using
# nfcapd -w -D -S 2 -B 1024000 -l /opt/nfcapd_test/ -p 9995
Nfsen installation
————————
Make all the necessay changes in nfsen.conf. Just go through the README file of nfsen for
installation and configuration instructions. These are really helpful.
When you install nfsen, it will automatically configure nfcapd program as a daemon.
So, there is no need to run nfcapd seperately as a daemon.
But, yes, if you would like to test it with tools like fprobe/softflowd, you can make use of nfcapd
program as a standalone and capture the flows from softflowd/fprobe.
# Make nfsen to start at boot. Please refer to reference links for writing a daemon script.
# chmod 755 nfsen && chkconfig –add nfsen && chkconfig nfsen on
Typical Errors
——————
If you encounter errors like:
Please ignore them. For some reason, pre-built graphs could not be generated. Make sure
that RRD.pm is installed correctly.
After some time, the graphs will be rebuilt.
Another error you might encounter is – “ERROR: nfsend connect() error: Permission denied!” This
is a permissions issue, as documented in
– https://code.google.com/p/nfsenplugins/wiki/NFSEN_Installation_Gotchas. You need to make
sure that the nfsen package can read the nfsen.comm socket file.
Typical checks
———————
Check whether fprobe is working correctly or not by using tcpdump. Fprobe is collecting traffic on
interface eth0 and capturing network flows and sending it to port 9995 over udp.
### If you change the configuration in nfsen.conf, do not forget to reconfigure nfsen by using
command:
# nfsen reconfig
#### check if the required ports are listening to the traffic using netstat command:
# netstat -t -u -c
Reference Links:
http://www.forwardingplane.net/2014/01/install-nfsen-and-nfdump-on-centos-6-5-for-netflow-and-
or-sflow-collection/
https://www.m00nie.com/2014/02/install-nfsen-centos-6-fedora-20/
http://manpages.ubuntu.com/manpages/hardy/man8/fprobe.8.html
http://www.itsprite.com/linuxhow-to-install-nfdump-and-nfsen/
http://blogfranz.blogspot.in/2010/11/netflow-on-endpoint.html
https://pradyumnajoshi.wordpress.com/2014/03/18/setting-up-network-flow-monitoring-using-nfsen-
on-centos/
How to install Nagios on
CentOS 6
Nagios is a powerful monitoring system that monitors your servers and/or services and
alerts staff if a problem should arise. The system is plugable which gives administrators
the ability to write their own or use hundreds of pre written plugins to monitor their
infrastructure.
Installation
Install required packages
yum -y install http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-
6-8.noarch.rpm
yum -y install nagios nagios-plugins-all
touch /var/www/html/index.html
Start Services
service httpd start
service nagios start
Web Interface
You can now open your browser and goto your server's hostname or ip address
prefixed with /nagios. You will be prompted for a username and password. The
username is nagiosadmin unless you changed it, and the password is what you set
above.
Example: http://192.168.1.1/nagios
define host {
use linux-server
host_name server1.domain.com
alias server1.domain.com
address 10.0.0.1
}
define service {
use generic-service
host_name server1.domain.com
service_description PING
check_command check_ping!100.0,20%!500.0,60%
}
define service {
use generic-service
host_name server1.domain.com
service_description SSH
check_command check_ssh
}
Scenario
Nagios server:
IP Address : 192.168.1.101/24
Nagios client:
IP Address : 192.168.1.100/24
Prerequisites
Before installing Nagios, make sure that you’ve a properly installed and
configured LAMP stack in your server. To install and configure LAMP server, refer
any one of the following links.
Also install the following prerequisites too. All commands should be run as root
user.
I tested this how-to on CentOS 6.5 minimal server, although it should work on
all RHEL 6.x and its clones like CentOS 6.x and Scientific Linux 6.x.
Nagios will not be found in CentOS official repositories, so let us add the EPEL
repository to install nagios. To add and enable EPEL repository, refer the following
link.
Next install nagios with all plug-ins and nagios agents(nrpe-agent) using
command:
# vi /etc/sysconfig/iptables
Add the following line:
[...]
[...]
Save and close the file. Restart iptables.
Add the admin mail address in the nagios contact file to receive alerts from nagios
server. To do that edit file /etc/nagios/objects/contacts.cfg,
# vi /etc/nagios/objects/contacts.cfg
Find the following line and enter the email id:
[...]
email [email protected] ;
[...
Save and close the file. Then Edit file /etc/httpd/conf.d/nagios.conf,
# vi /etc/httpd/conf.d/nagios.conf
And edit the following lines if you want to access nagios administrative console
from a particular IP series. Here i want to allow nagios administrative access from
192.168.1.0/24 series only.
[...]
# Order allow,deny
Order deny,allow
[...]
Set nagiosadmin password
New password:
# chkconfig nagios on
# chkconfig httpd on
Access Nagios admin console
Click
on the “Hosts” section in the left pane of the console. You will see the no of
hosts to be monitored by Nagios server. Initially, the nagios server (localhost)
itself will only be monitored.
Click
on the monitoring host to display more details:
Like i said before, you have to add EPEL repository in your CentOS/RHEL/Scientific
Linux 6.x clients to install nrpe package.
# vi /etc/nagios/nrpe.cfg
Add your Nagios server ip address
[...]
allowed_hosts=127.0.0.1 192.168.1.101
[...]
Start nrpe service:
# vi /etc/nagios/nagios.cfg
and uncomment the following lines.
## Line 52 - Uncomment ##
cfg_dir=/etc/nagios/servers
Create a directory called “servers” under “/etc/nagios/”.
# mkdir /etc/nagios/servers
Create config file to the client to be monitored:
# vi /etc/nagios/servers/clients.cfg
define host{
use linux-server
host_name client
alias client
address 192.168.1.100
max_check_attempts 5
check_period 24x7
notification_interval 30
notification_period 24x7
}
Finally restart nagios service.
Like
this way, you can define more clients by creating a separate config
files “/etc/nagios/servers directory for each client.
Define services
We did define the monitoring host before. Now let us add some services of the
monitoring host. For example to monitor the ssh service, add the following lines
shown in red colour in the /etc/nagios/servers/clients.cfg file.
# vi /etc/nagios/servers/clients.cfg
define host{
use linux-server
host_name client
alias client
address 192.168.1.100
max_check_attempts 5
check_period 24x7
notification_interval 30
notification_period 24x7
define service {
use generic-service
host_name client
service_description SSH
check_command check_ssh
notifications_enabled 0
}
Save and close the file. Restart Nagios.
Reference Links:
Nagios Homepage
TAGS
monitoring tools
nagios
http://www.ostecnix.com/
A Linux enthusiast, FOSS Supporter & Linux Consultant from Tamilnadu, India.
Fedora 25 released!
Sponsored Links