{"id":800,"date":"2017-09-15T01:29:06","date_gmt":"2017-09-14T18:29:06","guid":{"rendered":"https:\/\/trichev.com\/blog\/?p=800"},"modified":"2017-09-15T01:30:11","modified_gmt":"2017-09-14T18:30:11","slug":"nagios-4-x-installation-on-centos-6","status":"publish","type":"post","link":"https:\/\/trichev.com\/blog\/2017\/09\/15\/nagios-4-x-installation-on-centos-6\/","title":{"rendered":"Nagios 4.x installation on CentOS 6"},"content":{"rendered":"<p><strong>Installation and Configuration<\/strong><\/p>\n<p><code>yum install httpd php gcc glibc glibc-common gd gd-devel -y<br \/>\nuseradd nagios<br \/>\ngroupadd nagcmd<br \/>\nusermod -a -G nagcmd nagios<br \/>\nusermod -a -G nagcmd apache<\/code><\/p>\n<p><code>yum install -y rpm-build doxygen gperf bind-utils mysql-devel net-snmp-utils openssl-devel postgresql-devel samba-client<\/code><\/p>\n<p><code>mkdir -p ~\/rpmbuild\/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS}<\/code><\/p>\n<p><code>mkdir -p ~\/src &amp;&amp; cd ~\/src<\/code><\/p>\n<p><code>wget http:\/\/sourceforge.net\/projects\/nagios\/files\/nagios-4.x\/nagios-4.0.8\/nagios-4.0.8.tar.gz<br \/>\nwget http:\/\/www.nagios-plugins.org\/download\/nagios-plugins-2.0.3.tar.gz<br \/>\ntar zxvf nagios-4.0.8.tar.gz<br \/>\ntar zxvf nagios-plugins-2.0.3.tar.gz<\/code><\/p>\n<p><code>mv nagios-4.0.8.tar.gz ~\/rpmbuild\/SOURCES<br \/>\nmv nagios-plugins-2.0.3.tar.gz ~\/rpmbuild\/SOURCES\/<\/code><\/p>\n<p><code>cd ~\/src\/nagios-4.0.8 &amp;&amp; ls | grep *.spec<\/code><\/p>\n<p><code>vi nagios.spec<br \/>\n#add<br \/>\n%define _libdir %{_exec_prefix}\/lib<\/code><\/p>\n<p><code>rpmbuild -ba nagios.spec<\/code><\/p>\n<p><code>cd ~\/src\/nagios-plugins-2.0.3 &amp;&amp; ls | grep *.spec<\/code><\/p>\n<p><code>vi nagios-plugins.spec<\/code><br \/>\ncomment <code>%config(missingok,noreplace) %{_sysconfdir}\/command.cfg<\/code><\/p>\n<p>update <code>%doc ChangeLog command.cfg<\/code><br \/>\nto<br \/>\n<code>%doc ChangeLog<\/code><\/p>\n<p><code>rpmbuild -ba nagios-plugins.spec<\/code><\/p>\n<p><code>yum install -y nagios-4.0.8-2.el6.x86_64.rpm nagios-contrib-4.0.8-2.el6.x86_64.rpm nagios-devel-4.0.8-2.el6.x86_64.rpm nagios-plugins-2.0.3-1.x86_64.rpm<\/code><\/p>\n<p><code>vi \/etc\/nagios\/objects\/contacts.cfg<\/code><\/p>\n<p><code>mail user@domain.com;<\/code><\/p>\n<p><code>vi \/etc\/httpd\/conf.d\/nagios.conf<\/code><br \/>\n<code><br \/>\n#Order allow,deny<br \/>\n#Allow from all<br \/>\nOrder deny,allow<br \/>\nDeny from all<br \/>\nAllow from 127.0.0.1 192.168.1.0\/24 192.168.2.0\/24<\/code><\/p>\n<p><code>htpasswd -s -c \/etc\/nagios\/htpasswd.users nagiosadmin<\/code><\/p>\n<p><code>service httpd start<br \/>\nservice nagios start<br \/>\nchkconfig httpd on<br \/>\nchkconfig nagios on<\/code><\/p>\n<p><code>\/usr\/bin\/nagios -v \/etc\/nagios\/nagios.cfg<\/code><\/p>\n<p><code>yum install policycoreutils-python<\/code><\/p>\n<p><code>If SELinux is enforcing then add this line.<br \/>\nsemanage fcontext -a -t httpd_sys_content_t \/usr\/share\/nagios\/<\/code><\/p>\n<p><code>yum install mod_ssl<\/code><\/p>\n<p><code>service httpd restart<\/code><\/p>\n<p><code>vi \/etc\/nagios\/nagios.cfg<br \/>\ncfg_dir=\/etc\/nagios\/servers<\/code><\/p>\n<p><strong>NRPE Server installation\/configuration<\/strong><\/p>\n<p><code>yum install nagios-plugins-nrpe -y <\/code><\/p>\n<p><code>ln -s \/usr\/lib64\/nagios\/plugins\/check_nrpe \/usr\/lib\/nagios\/plugins\/check_nrpe<\/code><br \/>\n<code><br \/>\nvi \/etc\/nagios\/objects\/commands.cfg<br \/>\ndefine command{<br \/>\ncommand_name    check_nrpe<br \/>\ncommand_line    \/usr\/lib\/nagios\/plugins\/check_nrpe -H '$HOSTADDRESS$' -c '$ARG1$'<br \/>\n}<\/code><\/p>\n<p><strong>NRPE Client installation\/configuration<\/strong><\/p>\n<p><code>#nrpe is a part of EPEL repo<br \/>\nyum install nrpe openssl -y<br \/>\nyum install nagios-plugins-2.0.3-1.x86_64.rpm -y<\/code><\/p>\n<p><code>vi \/etc\/nagios\/nrpe.cfg<br \/>\n#nagios server<br \/>\nallowed_hosts=127.0.0.1,192.168.1.60<\/code><\/p>\n<p><code>service nrpe restart<br \/>\nchkconfig nrpe on<\/code><\/p>\n<p><strong>NRPE Server\/Client configuration for PostgreSQL monitoring<\/strong><\/p>\n<p>server:<br \/>\n<code>vi \/etc\/nagios\/servers\/dev-servers-services.cfg<br \/>\ndefine service {<br \/>\nuse generic-service<br \/>\nhost_name srvwiki01v<br \/>\nservice_description Mediawiki PostgreSQLD Connection<br \/>\ncheck_command check_nrpe!check_pgsql<br \/>\n}<\/code><\/p>\n<p>client:<br \/>\n<code>vi \/etc\/nagios\/nrpe.cfg<br \/>\ncommand[check_pgsql]=\/usr\/lib\/nagios\/plugins\/check_pgsql -H 192.168.1.62 -l nagios<\/code><\/p>\n<p><code>service nrpe restart<\/code><\/p>\n<p>Testing from server:<br \/>\n<code>\/usr\/lib\/nagios\/plugins\/check_nrpe -H 192.168.1.62 -c check_pgsql<\/code><br \/>\nCRITICAL &#8211; no connection to &#8216;wikidb&#8217; (FATAL: no pg_hba.conf entry for host &#8220;192.168.1.62&#8221;, user &#8220;nagios&#8221;, database &#8220;wikidb&#8221;, SSL off). *<br \/>\n* or default DB &#8211; &#8220;template1&#8221;<\/p>\n<p>Let&#8217;s configure ACL:<br \/>\n<code>vi \/var\/lib\/pgsql\/data\/pg_hba.conf<br \/>\nhost    template1  nagios      192.168.1.62\/32       trust<\/code><\/p>\n<p>Create nagios user in postgresql:<\/p>\n<pre><code>su postgres -c bash\r\n$createuser\r\nEnter name of role to add: nagios\r\nShall the new role be a superuser? (y\/n) n\r\nShall the new role be allowed to create databases? (y\/n) n\r\nShall the new role be allowed to create more new roles? (y\/n) n\r\n$exit<\/code><\/pre>\n<p>Testing connection from nagios server:<\/p>\n<pre><code>[root@srvmon01v ~]# \/usr\/lib\/nagios\/plugins\/check_nrpe -H 192.168.1.62 -c check_pgsql\r\nOK - database wikidb (0.003504 sec.)|time=0.003504s;2.000000;8.000000;0.000000<\/code><\/pre>\n<p><strong>SNMP Client configuration<\/strong><\/p>\n<p>CentOS6<br \/>\n<code>yum install -y net-snmp<\/code><\/p>\n<p>or<\/p>\n<p>CentOS5<br \/>\n<code>yum install -y net-snmp net-snmp-utils net-snmp-devel<\/code><\/p>\n<p>or<\/p>\n<p>SLES11<br \/>\n<code>zypper install net-snmp<\/code><\/p>\n<p><code>service snmpd stop<\/code><\/p>\n<p><code>mv \/etc\/snmp\/snmpd.conf \/etc\/snmp\/snmpd.conf_bak<\/code><\/p>\n<p>#Creating snmpv3 user<br \/>\nCentOS6<br \/>\n<code>net-snmp-create-v3-user -ro -A snmpv3authPass -a SHA -X snmpv3encPass -x AES snmpv3user<\/code><\/p>\n<p>or<\/p>\n<p>CentOS5<br \/>\n<code>net-snmp-config --create-snmpv3-user -ro -A snmpv3authPass -a SHA -X snmpv3encPass -x AES snmpv3user<\/code><\/p>\n<p><code>chkconfig snmpd on<br \/>\nservice snmpd start<\/code><\/p>\n<p><code>snmpwalk -u snmpv3user -A snmpv3authPass -a SHA -X snmpv3encPass -x AES -l authPriv 127.0.0.1 -v3<\/code><\/p>\n<p>#Ubuntu 9<br \/>\n<code>remove \/usr\/share\/snmp\/snmp.conf and \/var\/lib\/snmp\/snmpd.conf<br \/>\nnet-snmp-config --create-snmpv3-user -ro -A snmpv3authPass -a SHA -X snmpv3encPass -x AES snmpv3user<br \/>\nstart snmpd<\/code><\/p>\n<p><code>vi \/etc\/sysconfig\/iptables<\/code><br \/>\nCentOS6<br \/>\n<code>-A INPUT -m state --state NEW -m udp -p udp -s 192.168.1.60 --dport 161 -j ACCEPT<\/code><\/p>\n<p>or<\/p>\n<p>CentOS5<br \/>\n<code>-A RH-Firewall-1-INPUT -m state --state NEW -m udp -p udp -s 192.168.1.60 --dport 161 -j ACCEPT<\/code><\/p>\n<p><code>service iptables restart<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Installation and Configuration yum install httpd php gcc glibc glibc-common gd gd-devel -y useradd nagios groupadd nagcmd usermod -a -G nagcmd nagios usermod -a -G nagcmd apache yum install -y rpm-build doxygen gperf bind-utils mysql-devel net-snmp-utils openssl-devel postgresql-devel samba-client mkdir -p ~\/rpmbuild\/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS} mkdir -p ~\/src &amp;&amp; cd ~\/src wget http:\/\/sourceforge.net\/projects\/nagios\/files\/nagios-4.x\/nagios-4.0.8\/nagios-4.0.8.tar.gz wget http:\/\/www.nagios-plugins.org\/download\/nagios-plugins-2.0.3.tar.gz tar zxvf nagios-4.0.8.tar.gz [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[231],"tags":[212,32,244,14,11],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/trichev.com\/blog\/wp-json\/wp\/v2\/posts\/800"}],"collection":[{"href":"https:\/\/trichev.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/trichev.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/trichev.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/trichev.com\/blog\/wp-json\/wp\/v2\/comments?post=800"}],"version-history":[{"count":2,"href":"https:\/\/trichev.com\/blog\/wp-json\/wp\/v2\/posts\/800\/revisions"}],"predecessor-version":[{"id":802,"href":"https:\/\/trichev.com\/blog\/wp-json\/wp\/v2\/posts\/800\/revisions\/802"}],"wp:attachment":[{"href":"https:\/\/trichev.com\/blog\/wp-json\/wp\/v2\/media?parent=800"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/trichev.com\/blog\/wp-json\/wp\/v2\/categories?post=800"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/trichev.com\/blog\/wp-json\/wp\/v2\/tags?post=800"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}