{"id":162,"date":"2013-05-30T17:34:11","date_gmt":"2013-05-30T17:34:11","guid":{"rendered":"http:\/\/blog.shineservers.com\/?p=162"},"modified":"2013-05-30T17:34:11","modified_gmt":"2013-05-30T17:34:11","slug":"how-to-install-nagios-on-centos-6","status":"publish","type":"post","link":"https:\/\/www.shineservers.com\/2013\/05\/30\/how-to-install-nagios-on-centos-6\/","title":{"rendered":"How To Install Nagios On CentOS 6"},"content":{"rendered":"<h3>Step 1 &#8211; Install Packages on Monitoring Server<\/h3>\n<hr \/>\n<pre>rpm -Uvh http:\/\/dl.fedoraproject.org\/pub\/epel\/6\/x86_64\/epel-release-6-8.noarch.rpm\nrpm -Uvh http:\/\/rpms.famillecollet.com\/enterprise\/remi-release-6.rpm\nyum -y install nagios nagios-plugins-all nagios-plugins-nrpe nrpe php httpd\nchkconfig httpd on &amp;&amp; chkconfig nagios on\nservice httpd start &amp;&amp; service nagios start<\/pre>\n<p>We should also enable SWAP memory on this droplet, at least 2GB:<\/p>\n<pre>dd if=\/dev\/zero of=\/swap bs=1024 count=2097152\nmkswap \/swap &amp;&amp; chown root. \/swap &amp;&amp; chmod 0600 \/swap &amp;&amp; swapon \/swap\necho \/swap swap swap defaults 0 0 &gt;&gt; \/etc\/fstab\necho vm.swappiness = 0 &gt;&gt; \/etc\/sysctl.conf &amp;&amp; sysctl -p<\/pre>\n<h3>Step 2 &#8211; Set Password Protection<\/h3>\n<hr \/>\n<p>Set Nagios Admin Panel Password:<\/p>\n<pre>htpasswd -c \/etc\/nagios\/passwd nagiosadmin<\/pre>\n<p><img decoding=\"async\" alt=\"\" src=\"http:\/\/imgbowl.com\/do\/CentOS6-Nagios1.png\" width=\"680\" \/><\/p>\n<p>Make sure to keep this username as &#8220;nagiosadmin&#8221; &#8211; otherwise you would have to change \/etc\/nagios\/cgi.cfg and redefine authorized admin.<\/p>\n<p>Now you can navigate over to your droplet&#8217;s IP address\u00a0<b>http:\/\/IP\/nagios<\/b>\u00a0and login.<\/p>\n<p>You will be prompted for password you set in Step 2:<\/p>\n<p><img decoding=\"async\" alt=\"\" src=\"http:\/\/imgbowl.com\/do\/CentOS6-Nagios2.png\" width=\"680\" \/><\/p>\n<p>This is what the Nagios admin panel looks like:<\/p>\n<p><img decoding=\"async\" alt=\"\" src=\"http:\/\/imgbowl.com\/do\/CentOS6-Nagios3.png\" width=\"680\" \/><\/p>\n<p>Since this is a fresh installation, we don&#8217;t have any hosts currently being monitored.<\/p>\n<p><img decoding=\"async\" alt=\"\" src=\"http:\/\/imgbowl.com\/do\/CentOS6-Nagios4.png\" width=\"680\" \/><\/p>\n<p>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).<\/p>\n<p>From public ports, we can monitor ping, any open ports such as webserver, e-mail server, etc.<\/p>\n<p>For internal services that are listening on localhost, such as MySQL, memcached, system services, we will need to use NRPE.<\/p>\n<h3>Step 3 &#8211; Install NRPE on Clients<\/h3>\n<hr \/>\n<pre>rpm -Uvh http:\/\/dl.fedoraproject.org\/pub\/epel\/6\/x86_64\/epel-release-6-8.noarch.rpm\nrpm -Uvh http:\/\/rpms.famillecollet.com\/enterprise\/remi-release-6.rpm\nyum -y install nagios nagios-plugins-all nrpe\nchkconfig nrpe on<\/pre>\n<p>This next step is where you get to specify any manual commands that Monitoring server can send via NRPE to these client hosts.<\/p>\n<p>Make sure to change\u00a0<b>allowed_hosts<\/b>\u00a0to your own values.<\/p>\n<p>Edit\u00a0<b>\/etc\/nagios\/nrpe.cfg<\/b><\/p>\n<pre>log_facility=daemon\npid_file=\/var\/run\/nrpe\/nrpe.pid\nserver_port=5666\nnrpe_user=nrpe\nnrpe_group=nrpe\nallowed_hosts=198.211.117.251\ndont_blame_nrpe=1\ndebug=0\ncommand_timeout=60\nconnection_timeout=300\ninclude_dir=\/etc\/nrpe.d\/\ncommand[check_users]=\/usr\/lib64\/nagios\/plugins\/check_users -w 5 -c 10\ncommand[check_load]=\/usr\/lib64\/nagios\/plugins\/check_load -w 15,10,5 -c 30,25,20\ncommand[check_disk]=\/usr\/lib64\/nagios\/plugins\/check_disk -w 20% -c 10% -p \/dev\/vda\ncommand[check_zombie_procs]=\/usr\/lib64\/nagios\/plugins\/check_procs -w 5 -c 10 -s Z\ncommand[check_total_procs]=\/usr\/lib64\/nagios\/plugins\/check_procs -w 150 -c 200\ncommand[check_procs]=\/usr\/lib64\/nagios\/plugins\/check_procs -w $ARG1$ -c $ARG2$ -s $ARG3$<\/pre>\n<hr \/>\n<p>Note:<\/p>\n<p>In check_disk above, the partition being checked is \/dev\/vda &#8211; make sure your droplet has the same partition by running\u00a0<b>df -h \/<\/b><\/p>\n<p>You can also modify when to trigger warnings or critical alerts &#8211; above configuration sets Warning at 20% free disk space remaining, and Critical alert at 10% free space remaining.<\/p>\n<hr \/>\n<p>We should also setup firewall rules to allow connections from our Monitoring server to those clients and drop everyone else:<\/p>\n<pre>iptables -N NRPE\niptables -I INPUT -s 0\/0 -p tcp --dport 5666 -j NRPE\niptables -I NRPE -s 198.211.117.251 -j ACCEPT\niptables -A NRPE -s 0\/0 -j DROP\n\/etc\/init.d\/iptables save<\/pre>\n<p>Now you can start NRPE on all of your client hosts:<\/p>\n<pre>service nrpe start<\/pre>\n<h3>Step 4 &#8211; Add Server Configurations on Monitoring Server<\/h3>\n<hr \/>\n<p>Back on our Monitoring server, we will have to create config files for each of our client servers:<\/p>\n<pre>echo \"cfg_dir=\/etc\/nagios\/servers\" &gt;&gt; \/etc\/nagios\/nagios.cfg\ncd \/etc\/nagios\/servers\ntouch cloudmail.tk.cfg\ntouch emailocean.tk.cfg<\/pre>\n<p>Edit each client&#8217;s configuration file and define which services you would like monitored.<\/p>\n<pre>nano \/etc\/nagios\/servers\/cloudmail.tk.cfg<\/pre>\n<p>Add the following lines:<\/p>\n<pre>define host {\n        use                     linux-server\n        host_name               cloudmail.tk\n        alias                   cloudmail.tk\n        address                 198.211.107.218\n        }\n\ndefine service {\n        use                             generic-service\n        host_name                       cloudmail.tk\n        service_description             PING\n        check_command                   check_ping!100.0,20%!500.0,60%\n        }\n\ndefine service {\n        use                             generic-service\n        host_name                       cloudmail.tk\n        service_description             SSH\n        check_command                   check_ssh\n        notifications_enabled           0\n        }\n\ndefine service {\n        use                             generic-service\n        host_name                       cloudmail.tk\n        service_description             Current Load\n        check_command                   check_local_load!5.0,4.0,3.0!10.0,6.0,4.0\n        }<\/pre>\n<p>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:<\/p>\n<p>This is a snippet of\u00a0<b>\/etc\/nagios\/servers\/emailocean.tk.cfg<\/b>:<\/p>\n<pre>define host {\n        use                     linux-server\n        host_name               emailocean.tk\n        alias                   emailocean.tk\n        address                 198.211.112.99\n        }\n\n...<\/pre>\n<p>You can add additional clients to be monitored as<b>\/etc\/nagios\/servers\/AnotherHostName.cfg<\/b><\/p>\n<p>Finally, after you are done adding all the client configurations, you should set folder permissions correctly and restart Nagios on your Monitoring Server:<\/p>\n<pre>chown -R nagios. \/etc\/nagios\nservice nagios restart<\/pre>\n<h3>Step 5 &#8211; Monitor Hosts in Nagios<\/h3>\n<hr \/>\n<p>Navigate over to your Monitoring Server&#8217;s IP address http:\/\/IP\/nagios and enter password set in Step 2.<\/p>\n<p>Now you should be able to see all the hosts and services:<\/p>\n<p><img decoding=\"async\" alt=\"\" src=\"http:\/\/imgbowl.com\/do\/CentOS6-Nagios5.png\" width=\"680\" \/><\/p>\n<p>And you are all done!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Step 1 &#8211; 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 &amp;&amp; chkconfig nagios on service httpd start &amp;&amp; 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 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[53,60],"tags":[82],"class_list":["post-162","post","type-post","status-publish","format-standard","hentry","category-general","category-linux","tag-how-to-install-nagios-on-centos-6"],"acf":[],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.shineservers.com\/wp-json\/wp\/v2\/posts\/162","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.shineservers.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.shineservers.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.shineservers.com\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.shineservers.com\/wp-json\/wp\/v2\/comments?post=162"}],"version-history":[{"count":0,"href":"https:\/\/www.shineservers.com\/wp-json\/wp\/v2\/posts\/162\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.shineservers.com\/wp-json\/wp\/v2\/media?parent=162"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shineservers.com\/wp-json\/wp\/v2\/categories?post=162"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shineservers.com\/wp-json\/wp\/v2\/tags?post=162"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}