how to install nagios on centos 6

7
How To Install Nagios On CentOS 6 Step 1 - Install Packages on Monitoring Server rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6- 8.noarch.rpm rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm yum -y install nagios nagios-plugins-all nagios-plugins-nrpe nrpe php httpd chkconfig httpd on && chkconfig nagios on service httpd start && service nagios start We should also enable SWAP memory on this droplet, at least 2GB: dd if=/dev/zero of=/swap bs=1024 count=2097152 mkswap /swap && chown root. /swap && chmod 0600 /swap && swapon /swap echo /swap swap swap defaults 0 0 >> /etc/fstab echo vm.swappiness = 0 >> /etc/sysctl.conf && sysctl -p Step 2 - Set Password Protection Set Nagios Admin Panel Password: htpasswd -c /etc/nagios/passwd nagiosadmin Make sure to keep this username as "nagiosadmin" - otherwise you would have to change /etc/nagios/cgi.cfg and redefine authorized admin.  Now you can navigate over to your droplet's IP address http://IP/nagios and login. You will be prompted for password you set in Step 2:

Upload: omkar

Post on 14-Apr-2018

235 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: How to Install Nagios on CentOS 6

7/27/2019 How to Install Nagios on CentOS 6

http://slidepdf.com/reader/full/how-to-install-nagios-on-centos-6 1/7

How To Install Nagios On CentOS 6

Step 1 - Install Packages on Monitoring Server

rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpmrpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpmyum -y install nagios nagios-plugins-all nagios-plugins-nrpe nrpe php httpdchkconfig httpd on && chkconfig nagios onservice httpd start && service nagios start

We should also enable SWAP memory on this droplet, at least 2GB:

dd if=/dev/zero of=/swap bs=1024 count=2097152mkswap /swap && chown root. /swap && chmod 0600 /swap && swapon /swapecho /swap swap swap defaults 0 0 >> /etc/fstab

echo vm.swappiness = 0 >> /etc/sysctl.conf && sysctl -p

Step 2 - Set Password Protection

Set Nagios Admin Panel Password:htpasswd -c /etc/nagios/passwd nagiosadmin

Make sure to keep this username as "nagiosadmin" - otherwise you would have to change

/etc/nagios/cgi.cfg and redefine authorized admin.

 Now you can navigate over to your droplet's IP address http://IP/nagios and login.

You will be prompted for password you set in Step 2:

Page 2: How to Install Nagios on CentOS 6

7/27/2019 How to Install Nagios on CentOS 6

http://slidepdf.com/reader/full/how-to-install-nagios-on-centos-6 2/7

This is what the Nagios admin panel looks like:

Page 3: How to Install Nagios on CentOS 6

7/27/2019 How to Install Nagios on CentOS 6

http://slidepdf.com/reader/full/how-to-install-nagios-on-centos-6 3/7

Since this is a fresh installation, we don't have any hosts currently being monitored.

 Now we should add our hosts that will be monitored by Nagios. For example, we will use

cloudmail.tk (198.211.107.218) and emailocean.tk (198.211.112.99).

From public ports, we can monitor ping, any open ports such as webserver, e-mail server, etc.

For internal services that are listening on localhost, such as MySQL, memcached, system

services, we will need to use NRPE.

Step 4 - Install NRPE on Clients

rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

Page 4: How to Install Nagios on CentOS 6

7/27/2019 How to Install Nagios on CentOS 6

http://slidepdf.com/reader/full/how-to-install-nagios-on-centos-6 4/7

rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpmyum -y install nagios nagios-plugins-all nrpechkconfig nrpe on

This next step is where you get to specify any manual commands that Monitoring server can

send via NRPE to these client hosts.

Make sure to change allowed_hosts to your own values.

Edit /etc/nagios/nrpe.cfg

log_facility=daemonpid_file=/var/run/nrpe/nrpe.pidserver_port=5666nrpe_user=nrpenrpe_group=nrpeallowed_hosts=198.211.117.251

dont_blame_nrpe=1debug=0command_timeout=60connection_timeout=300include_dir=/etc/nrpe.d/command[check_users]=/usr/lib64/nagios/plugins/check_users -w 5 -c 10command[check_load]=/usr/lib64/nagios/plugins/check_load -w 15,10,5 -c30,25,20command[check_disk]=/usr/lib64/nagios/plugins/check_disk -w 20% -c 10% -p/dev/vdacommand[check_zombie_procs]=/usr/lib64/nagios/plugins/check_procs -w 5 -c 10-s Zcommand[check_total_procs]=/usr/lib64/nagios/plugins/check_procs -w 150 -c 200command[check_procs]=/usr/lib64/nagios/plugins/check_procs -w $ARG1$ -c

$ARG2$ -s $ARG3$

 Note:

In check_disk above, the partition being checked is /dev/vda - make sure your droplet has the

same partition by running df -h /

You can also modify when to trigger warnings or critical alerts - above configuration sets

Warning at 20% free disk space remaining, and Critical alert at 10% free space remaining.

We should also setup firewall rules to allow connections from our Monitoring server to thoseclients and drop everyone else:

iptables -N NRPEiptables -I INPUT -s 0/0 -p tcp --dport 5666 -j NRPEiptables -I NRPE -s 198.211.117.251 -j ACCEPTiptables -A NRPE -s 0/0 -j DROP/etc/init.d/iptables save

Page 5: How to Install Nagios on CentOS 6

7/27/2019 How to Install Nagios on CentOS 6

http://slidepdf.com/reader/full/how-to-install-nagios-on-centos-6 5/7

 Now you can start NRPE on all of your client hosts:service nrpe start

Step 5 - Add Server Configurations on Monitoring Server

Back on our Monitoring server, we will have to create config files for each of our client servers:echo "cfg_dir=/etc/nagios/servers" >> /etc/nagios/nagios.cfgcd /etc/nagios/serverstouch cloudmail.tk.cfgtouch emailocean.tk.cfg

Edit each client's configuration file and define which services you would like monitored.

nano /etc/nagios/servers/cloudmail.tk.cfg

Add the following lines:

define host {use linux-serverhost_name cloudmail.tkalias cloudmail.tkaddress 198.211.107.218}

define service {

use generic-servicehost_name cloudmail.tkservice_description PINGcheck_command check_ping!100.0,20%!500.0,60%}

define service {use generic-servicehost_name cloudmail.tkservice_description SSHcheck_command check_sshnotifications_enabled 0}

define service {use generic-servicehost_name cloudmail.tkservice_description Current Loadcheck_command check_local_load!5.0,4.0,3.0!

10.0,6.0,4.0}

You can add more services to be monitored as desired. Same configuration should be added for 

second client, emailocean.tk, with different IP address and host_name:

Page 6: How to Install Nagios on CentOS 6

7/27/2019 How to Install Nagios on CentOS 6

http://slidepdf.com/reader/full/how-to-install-nagios-on-centos-6 6/7

This is a snippet of /etc/nagios/servers/emailocean.tk.cfg :define host {

use linux-serverhost_name emailocean.tkalias emailocean.tk

address 198.211.112.99}

...

You can add additional clients to be monitored as /etc/nagios/servers/AnotherHostName.cfg

Finally, after you are done adding all the client configurations, you should set folder permissionscorrectly and restart Nagios on your Monitoring Server:

chown -R nagios. /etc/nagios

service nagios restart

Step 6 - Monitor Hosts in Nagios

 Navigate over to your Monitoring Server's IP address http://IP/nagios and enter password set in

Step 2.

 Now you should be able to see all the hosts and services:

Page 7: How to Install Nagios on CentOS 6

7/27/2019 How to Install Nagios on CentOS 6

http://slidepdf.com/reader/full/how-to-install-nagios-on-centos-6 7/7

And you are all done!