# Installation instructions of Nagios on CentOS 6.4 64bit
Author:larry Zhao
Q q:920057952
B L O g:larryzhao.blog.51cto.com
e-mail: [Email protected]
# NTP Service
Yum Install NTP
Service NTPD Start
Chkconfig ntpd on
Crontab-e
* * * * * */usr/sbin/ntpdate cn.pool.ntp.org
# Packets Prepare
nagios-3.3.1.tar.gz nagios-plugins-1.4.15.tar.gz nrpe-2.12.tar.gz rrdtool-1.4.7.tar.gz pnp4nagios-0.6.6.tar.gz
# We Use X-shell to upload these files to our server
Mkdir/upload;cd/upload
######################### Nagios Server 10.0.0.145 ######################################
Tar zxvf nagios-3.3.1.tar.gz
Tar zxvf nagios-plugins-1.4.15.tar.gz
Tar zxvf nrpe-2.12.tar.gz
Tar zxvf rrdtool-1.4.7.tar.gz
Tar zxvf pnp4nagios-0.6.6.tar.gz
Rm-f *.gz
# environment Prepare
Yum install-y net-snmp net-snmp-utils httpd gcc glibc glibc-common *gd* php php-mysql mysql mysql-server mysql-devel Open Ssl-devel
Yum install-y Libpangocairo Pango pango-devel Cairo cairo-devel redhat-lsb-graphics pkgconfig Groff glib Glib-devel Libar t* gettext gettext-devel libxml2 libxml2-devel
Yum install-y freetype freetype-devel libpng libpng-devel libjpeg libjpeg-devel libiconv libiconv-devel Qpixman Qpixman -devel
#SELINUX
Vim/etc/selinux/config
Selinux=disabled
#IPTABLES
Service Iptables Stop
Chkconfig iptables off
# Install Nagios
Groupadd Nagcmd
Useradd-m Nagios
Usermod-a-G Nagcmd Nagios
Usermod-a-G Nagcmd Apache
CD Nagios
./configure--with-command-group=nagcmd--enable-event-broker
Make a && make install && make Install-init && make Install-config && make Install-comma Ndmode && make install-webconf
Htpasswd-c/usr/local/nagios/etc/htpasswd.users Nagiosadmin
# Type new password twice
Here we use Nagios as our password
Service httpd Start
Chkconfig httpd on
Cd.. /nagios-plugins-1.4.15/
./configure--with-nagios-user=nagios--with-nagios-group=nagios--with-mysql
Make && make install
Chkconfig--add Nagios
Chkconfig Nagios on
Vim/etc/profile
# Insert "path= $PATH:/usr/local/nagios/bin" Into/etc/profile
Path= $PATH:/usr/local/nagios/bin
#save and exit
. /etc/profile
Nagios-v/usr/local/nagios/etc/nagios.cfg
Service Nagios Start
#Now If you want access your Nagios server, Http://ip/nagios. Username:nagiosadmin Password:nagios
Cd.. /nrpe-2.12/
./configure--enable-ssl--with-ssl-lib=/lib/
Make all && make Install-plugin
# It is necessary to insert some lines of code INTO/USR/LOCAL/NAGIOS/ETC/OBJECTS/COMMANDS.CFG
Vim/usr/local/nagios/etc/objects/commands.cfg
#check Nrpe
Define Command{
Command_name Check_nrpe
Command_line $USER 1$/check_nrpe-h $HOSTADDRESS $-C $ARG 1$
}
#save and exit
#We can use the command_line below to check our config files
/usr/local/nagios/bin/nagios-v/usr/local/nagios/etc/nagios.cfg
Cd.. /rrdtool-1.4.7
./configure--prefix=/usr/local/rrdtool
Make && make install
Cd.. /pnp4nagios-0.6.6
Chown Nagios.nagios *
chmod +x *
./configure--prefix=/usr/local/pnp4nagios--with-nagios-user=nagios--with-nagios-group=nagios--with-rrdtool=/ Usr/local/rrdtool/bin/rrdtool
Make all
Make install
Make install-webconf
Make Install-config
Make Install-init
cd/usr/local/pnp4nagios/etc/
MV Misccommands.cfg-sample Misccommands.cfg
MV Nagios.cfg-sample Nagios.cfg
MV Rra.cfg-sample Rra.cfg
MV Npcd.cfg-sample Npcd.cfg
MV Process_perfdata.cfg-sample Process_perfdata.cfg
CD pages/
MV Web_traffic.cfg-sample Web_traffic.cfg
Cd.. /check_commands/
MV Check_all_local_disks.cfg-sample Check_all_local_disks.cfg
MV Check_nrpe.cfg-sample Check_nrpe.cfg
MV Check_nwstat.cfg-sample Check_nwstat.cfg
Service NPCD Restart
# Nagios Config files
Vim/usr/local/nagios/etc/nagios.cfg
Process_performance_data=1
Host_perfdata_command=process-host-perfdata
Service_perfdata_command=process-service-perfdata
Vim/usr/local/nagios/etc/objects/commands.cfg
# ' process-host-perfdata ' command definition
Define Command{
Command_name Process-host-perfdata
command_line/usr/local/pnp4nagios/libexec/process_perfdata.pl
}
# ' process-service-perfdata ' command definition
Define Command{
Command_name Process-service-perfdata
command_line/usr/local/pnp4nagios/libexec/process_perfdata.pl
}
Command_name Process-service-perfdata
command_line/usr/local/nagios/libexec/process_perfdata.pl
}
Vim/usr/local/nagios/etc/objects/templates.cfg
Define host {
Name Host-pnp
action_url/pnp4nagios/index.php/graph?host= $HOSTNAME $&srv=_host_ ' class= ' tips ' rel= '/pnp4nagios/index.php/ popup?host= $HOSTNAME $&srv=_host_
Register 0
}
Define Service {
Name Srv-pnp
action_url/pnp4nagios/index.php/graph?host= $HOSTNAME $&srv= $SERVICEDESC $ ' class= ' tips ' rel= '/pnp4nagios/ index.php/popup?host= $HOSTNAME $&srv= $SERVICEDESC $
Register 0
}
cp/upload/pnp4nagios-0.6.6/contrib/ssi/*/usr/local/nagios/share/ssi/
Cd/usr/local/pnp4nagios/share/
MV Install.php Install.php.bak
#check npcd.cfg
/usr/local/pnp4nagios/bin/npcd-d-f/usr/local/pnp4nagios/etc/npcd.cfg
#First Time to access
Http://ip/php4nagios
# create some config files as we like
cd/usr/local/nagios/etc/objects/
Touch Mylinux.cfg;vim Mylinux.cfg
Define Host{
Use Linux-server,host-pnp
HOST_NAME puppet
Alias Puppty_jd_server
Address 10.0.0.148
}
Define Serviceextinfo {
HOST_NAME puppet
Service_description Check_load
action_url/pnp4nagios/index.php/graph?host= $HOSTNAME $&srv= $SERVICEDESC $ ' class= ' tips ' rel= '/pnp4nagios/ index.php/popup?host= $HOSTNAME $&srv= $SERVICEDESC $
}
Define Service{
Use Generic-service,srv-pnp
HOST_NAME puppet
Service_description Check_local_load
Check_command Check_nrpe!check_load
}
Define Service{
Use Generic-service,srv-pnp
HOST_NAME puppet
Service_description check_users
Check_command check_nrpe!check_users
}
Vim.. /nagios.cfg
#cfg_file =/usr/local/nagios/etc/objects/localhost.cfg
Cfg_file=/usr/local/nagios/etc/objects/mylinux.cfg
Service Nagios Restart
Service NPCD Restart
Service httpd Restart
############################ Nagios Client 10.0.0.148 ###################################
# NTP Service
Yum Install NTP
Service NTPD Start
Chkconfig ntpd on
Crontab-e
* * * * * */usr/sbin/ntpdate cn.pool.ntp.org
# Packets Prepare
Nagios-plugins-1.4.15.tar.gz nrpe-2.12.tar.gz
# We Use X-shell to upload these files to our server
Mkdir/upload;cd/upload
Tar zxvf nagios-plugins-1.4.15.tar.gz
Tar zxvf nrpe-2.12.tar.gz
Rm-f *.gz
# environment Prepare
Yum-y install NET-SNMP net-snmp-utils openssl-devel gcc glibc glibc-common *gd*
#SELINUX
Vim/etc/selinux/config
Selinux=disabled
#IPTABLES
Service Iptables Stop
Chkconfig iptables off
Useradd Nagios
CD nagios-plugins-1.4.15
./configure--with-nagios-user=nagios--with-nagios-group=nagios
Make && make install
Cd.. /nrpe-2.12
./configure--enable-ssl--with-ssl-lib=/usr/lib/
Make all
Make Install-plugin && make Install-daemon && make Install-daemon-config
Chown-r Nagios:nagios/usr/local/nagios
Cp/usr/local/nagios/etc/nrpe.cfg/etc/nrpe.cfg
#allowed_hosts change to the Nagios server ' s IP address
Vim/etc/nrpe.cfg
allowed_hosts=10.0.0.145
#Three lines need to the change, you can use the set Nu to find them
Vim/etc/snmp/snmpd.conf
Line com2sec notconfiguser default Larryzhao
Line + Access Notconfiggroup "" Any noauth exact mib2 none None
Line view MIB2 included. Iso.org.dod.internet.mgmt.mib-2 FC
Service SNMPD Restart
Chkconfig snmpd on
#Start Nrpe Service
/usr/local/nagios/bin/nrpe-c/etc/nrpe.cfg-d
#To Check Nrpe work status
Ps-ef |grep Nrpe
#add Nrpe to Rc.local
Vim/etc/rc.d/rc.local
/usr/local/nagios/bin/nrpe-c/etc/nrpe.cfg-d
############################### e-Mail Notice ##########################################
Yum Install-y SendMail
Yum Install-y SENDMAIL-CF
M4/ETC/MAIL/SENDMAIL.MC >/ETC/MAIL/SENDMAIL.CF
Vi/etc/mail/local-host-names
Larryzhao.com
Vi/etc/mail/submit.cf
Find #Dj $w. foo.com
Djlarryzhao.com
Service SendMail Restart
Vim/usr/local/nagios/etc/objects/contacts.cfg
Define Contact{
Contact_Name Nagiosadmin
Use Generic-contact
Alias Nagios Admin
email [email protected],[email protected]
}
Vim/usr/local/nagios/etc/objects/commands.cfg
# ' notify-host-by-email ' command definition
Define Command{
Command_name Notify-host-by-email
command_line/usr/bin/printf "%b" "* * * * Nagios *****\n\nnotification Type: $NOTIFICATIONTYPE $\nhost: $HOSTNAME $\nstat E: $HOSTSTATE $\naddress: $HOSTADDRESS $\ninfo: $HOSTOUTPUT $\n\ndate/time: $LONGDATETIME $\n "| /bin/mail-s "* * $NOTIFICATIONTYPE $ Host Alert: $HOSTNAME $ is $HOSTSTATE $ * *" $CONTACTEMAIL $
}
# ' notify-service-by-email ' command definition
Define Command{
Command_name Notify-service-by-email
command_line/usr/bin/printf "%b" "* * * * Nagios *****\n\nnotification Type: $NOTIFICATIONTYPE $\n\nservice: $SERVICEDES C$\nhost: $HOSTALIAS $\naddress: $HOSTADDRESS $\nstate: $SERVICESTATE $\n\ndate/time: $LONGDATETIME $\n\nadditional Info:\n\n$serviceoutput$\n "| /bin/mail-s "* * $NOTIFICATIONTYPE $ Service Alert: $HOSTALIAS $/$SERVICEDESC $ is $SERVICESTATE $ * *" $CONTACTEMAIL $
}
This article is from the "Bright Corner" blog, please be sure to keep this source http://larryzhao.blog.51cto.com/1030646/1532981