前提:LAMP环境搭建完成,参考:http://note.t4x.org/code/configure-httpd-mysql-php/
PNP4NAGIOS+RRDTOOL:http://note.t4x.org/code/pnp4nagios-rrdtool-config/
备注:经过Centos6.4、Centos6.5、Centos7.0测试试用!
脚本:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
#!/bin/bash # Author:Byrd # Version:1.0 # Site:note.t4x.org # Contact:root#t4x.org #This script for Nagios-V3.5.1 PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin export PATH LANG="en_US.UTF-8" # Check if user is root if [ $UID != "0" ]; then echo "Error: You must be root to run this script, please use root to install Nagios3.5.1" exit 1 fi clear echo "=========================================================================" echo "INSTALL NAGIOS-V3.5.1" echo "=========================================================================" NagiosSoft=http://sourceforge.net/projects/nagios/files/nagios-3.x/nagios-3.5.1/nagios-3.5.1.tar.gz NagiosPls=http://nagios-plugins.org/download/nagios-plugins-2.0.3.tar.gz NagiosNrpe=http://sourceforge.net/projects/nagios/files/nrpe-2.x/nrpe-2.15/nrpe-2.15.tar.gz NagiosNrpV=nrpe-2.15 NagiosPve=nagios-plugins-2.0.3 NagiosVer=nagios-3.5.1 NagiosDir=/byrd/tools/nagios [ ! -d $NagiosDir ] && mkdir -p $NagiosDir if [ `cat /etc/selinux/config | grep SELINUX=disabled | wc -l` -eq 0 ];then sed -i s#SELINUX=enforcing#SELINUX=disabled#g /etc/selinux/config setenforce 0 useradd nagios groupadd nagcmd usermod -a -G nagcmd nagios usermod -a -G nagcmd daemon yum install ntpdate vim wget -y echo 'export LC_ALL=C' >> /etc/profile source /etc/profile echo '*/10 * * * * /usr/sbin/ntpdate time.nist.gov >/dev/null 2>&1' >>/var/spool/cron/root ntpdate time.nist.gov fi if [ ! -f $NagiosDir/$NagiosVer.tar.gz ];then cd $NagiosDir wget $NagiosSoft tar zxf $NagiosVer.tar.gz cd nagios ./configure --with-command-group=nagcmd --with-httpd-conf=/usr/local/apache/conf/extra make all make install RETVAL=$? make install-init make install-commandmode make install-config make install-webconf /usr/local/apache/bin/htpasswd -cb /usr/local/nagios/etc/htpasswd.users nagiosadmin admin123 sed -i 's#Include conf/extra/httpd-default.conf#Include conf/extra/httpd-default.conf\nInclude conf/extra/nagios.conf#g' /usr/local/apache/conf/httpd.conf /usr/local/apache/bin/apachectl -k restart /etc/init.d/nagios start else cd $NagiosDir tar zxf $NagiosVer.tar.gz cd nagios make clean ./configure --with-command-group=nagcmd --with-httpd-conf=/usr/local/apache/conf/extra make all make install RETVAL=$? make install-init make install-commandmode make install-config make install-webconf /usr/local/apache/bin/htpasswd -cb /usr/local/nagios/etc/htpasswd.users nagiosadmin admin123 sed -i 's#Include conf/extra/httpd-default.conf#Include conf/extra/httpd-default.conf\nInclude conf/extra/nagios.conf#g' /usr/local/apache/conf/httpd.conf /usr/local/apache/bin/apachectl -k restart /etc/init.d/nagios start fi if [ $RETVAL -eq 0 ];then echo "Nagios 3.5.1 Install Successful" else exit 1 fi clear echo "=========================================================================" echo "INSTALL NAGIOS-PLUGINS-2.0.3" echo "=========================================================================" if [ ! -f $NagiosDir/$NagiosPve.tar.gz ];then cd $NagiosDir yum install perl-devel -y wget $NagiosPls tar zxf $NagiosPve.tar.gz cd $NagiosPve ./configure --with-nagios-user=nagios --with-nagios-group=nagios --enable-perl-modules --with-mysql=/usr/local/mysql make && make install RETVALPls=$? else cd $NagiosDir yum install perl-devel -y tar zxf $NagiosPve.tar.gz cd $NagiosPve make clean ./configure --with-nagios-user=nagios --with-nagios-group=nagios --enable-perl-modules --with-mysql=/usr/local/mysql make && make install RETVALPls=$? fi if [ $RETVALPls -eq 0 ];then echo "$NagiosPve INSTALL SUCCESSFUL" else echo "$NagiosPve INSTALL FAILED" exit $RETVALPls fi if [ ! -f $NagiosDir/$NagiosNrpV.tar.gz ];then cd $NagiosDir wget $NagiosNrpe tar zxf $NagiosNrpV.tar.gz cd $NagiosNrpV ./configure make all make install-plugin make install-daemon make install-daemon-config else cd $NagiosDir tar zxf $NagiosNrpV.tar.gz cd $NagiosNrpV make clean ./configure make all make install-plugin make install-daemon make install-daemon-config fi if [ -f /usr/local/nagios/libexec/check_nrpe ];then echo "$NagiosNrpV INSTALL SUCCESSFUL" else echo "$NagiosNrpV INSTALL FAILED" echo 1 fi |
过程:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
[root@Nagios-Server ~]# uname -a Linux Nagios-Server 2.6.32-358.el6.x86_64 #1 SMP Fri Feb 22 00:31:26 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux [root@Nagios-Server ~]# echo 'export LC_ALL=C' >> /etc/profile [root@Nagios-Server ~]# source /etc/profile [root@Nagios-Server ~]# echo $LC_ALL C [root@Nagios-Server ~]# getenforce Enforcing [root@Nagios-Server ~]# sed -i s#SELINUX=enforcing#SELINUX=disabled#g /etc/selinux/config [root@Nagios-Server ~]# setenforce 0 [root@Nagios-Server ~]# cat /etc/selinux/config | grep SELINUX= # SELINUX= can take one of these three values: SELINUX=disabled [root@Nagios-Server ~]# yum install ntpdate -y [root@Nagios-Server ~]# echo '*/10 * * * * /usr/sbin/ntpdate time.nist.gov >/dev/null 2>&1' >>/var/spool/cron/root [root@Nagios-Server ~]# ntpdate time.nist.gov [root@Nagios-Server ~]# mkdir /byrd/tools/nagios -p [root@Nagios-Server nagios]# cd /byrd/tools/nagios/ [root@Nagios-Server nagios]# yum install wget -y [root@Nagios-Server nagios]# wget http://sourceforge.net/projects/nagios/files/nagios-3.x/nagios-3.5.1/nagios-3.5.1.tar.gz [root@Nagios-Server nagios]# tar zxf nagios-3.5.1.tar.gz [root@Nagios-Server nagios]# cd nagios [root@Nagios-Server nagios]# useradd nagios [root@Nagios-Server nagios]# groupadd nagcmd [root@Nagios-Server nagios]# usermod -a -G nagcmd nagios [root@Nagios-Server nagios]# usermod -a -G nagcmd daemon [root@Nagios-Server nagios]# id -n -G nagios nagios nagcmd [root@Nagios-Server nagios]# id -n -G daemon daemon bin adm lp nagcmd [root@Nagios-Server nagios]# ./configure --with-command-group=nagcmd --with-httpd-conf=/usr/local/apache/conf/extra [root@Nagios-Server nagios]# make all [root@Nagios-Server nagios]# make install [root@Nagios-Server nagios]# make install-init [root@Nagios-Server nagios]# make install-commandmode [root@Nagios-Server nagios]# make install-config [root@Nagios-Server nagios]# make install-webconf [root@Nagios-Server nagios]# /usr/local/apache/bin/htpasswd -cb /usr/local/nagios/etc/htpasswd.users nagiosadmin admin123 [root@Nagios-Server nagios]# sed -i 's#Include conf/extra/httpd-default.conf#Include conf/extra/httpd-default.conf\nInclude conf/extra/nagios.conf#g' /usr/local/apache/conf/httpd.conf [root@Nagios-Server nagios]# /usr/local/apache/bin/apachectl -k restart [root@Nagios-Server nagios]# /etc/init.d/nagios checkconfig [root@Nagios-Server nagios]# /etc/init.d/nagios start [root@Nagios-Server nagios]# cd .. [root@Nagios-Server nagios]# wget http://nagios-plugins.org/download/nagios-plugins-2.0.3.tar.gz [root@Nagios-Server nagios]# tar zxf nagios-plugins-2.0.3.tar.gz [root@Nagios-Server nagios]# cd nagios-plugins-2.0.3 [root@Nagios-Server nagios-plugins-2.0.3]# ./configure --with-nagios-user=nagios --with-nagios-group=nagios --enable-perl-modules --with-mysql=/usr/local/mysql [root@Nagios-Server nagios-plugins-2.0.3]# yum -y install perl-devel perl-CPAN [root@Nagios-Server nagios-plugins-2.0.3]# make && make install [root@Nagios-Server nagios-plugins-2.0.3]# cd .. [root@Nagios-Server nagios]# ll /usr/local/nagios/libexec/ | wc -l 61 [root@Nagios-Server nagios]# pwd /byrd/tools/nagios [root@Nagios-Server nagios]# wget http://sourceforge.net/projects/nagios/files/nrpe-2.x/nrpe-2.15/nrpe-2.15.tar.gz [root@Nagios-Server nagios]# tar zxf nrpe-2.15.tar.gz [root@Nagios-Server nagios]# cd nrpe-2.15 [root@Nagios-Server nrpe-2.15]# ./configure [root@Nagios-Server nrpe-2.15]# make all [root@Nagios-Server nrpe-2.15]# make install-plugin [root@Nagios-Server nrpe-2.15]# make install-daemon [root@Nagios-Server nrpe-2.15]# make install-daemon-config |
备注:
0 1 2 |
[root@Nagios-Server ~]# /etc/init.d/nagios start Starting nagios: done. [root@Nagios-Server ~]# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d |
软件:
nrpe:http://sourceforge.net/projects/nagios/files/nrpe-2.x/nrpe-2.15/
nagios:http://sourceforge.net/projects/nagios/
other:http://www.nagios.org/download/addons/
Cacti:http://note.t4x.org/system/cacti-snmp-rrdtool-config/SourceByrd's Weblog-https://note.t4x.org/code/infrastructure-monitoring-nagios-server-config/ SourceByrd's Weblog-https://note.t4x.org/code/infrastructure-monitoring-nagios-server-config/
申明:除非注明Byrd's Blog内容均为原创,未经许可禁止转载!详情请阅读版权申明!
Trackbacks