yum -y install lrzsz
yum -y install httpd httpd-devel php php-devel
yum -y install gcc gcc-c++ openssl openssl-devel gd gd-devel
/usr/sbin/useradd nagios
/usr/sbin/groupadd nagcmd
/usr/sbin/usermod -G nagcmd nagios
/usr/sbin/usermod -G nagcmd apache
#install nagios server
[ ! -d /data0/soft/nagios ] && mkdir -p /data0/soft/nagios
cd !$
wget
tar zxvf nagios-3.2.1.tar.gz
cd nagios-3.2.1
./configure --with-nagios-user=nagios --with-nagios-group=nagios --with-command-group=nagcmd --prefix=/usr/local/nagios
make all
make install
make install-init
make install-config
make install-commandmode
cd ..
#install nagios plugin
[ ! -d /data0/soft/nagios ] && mkdir /data0/soft/nagios
cd !$
wget
tar -zxvf nagios-plugins-1.4.15.tar.gz
cd nagios-plugins-1.4.15
./configure --with-nagios-user=nagios --with-nagios-group=nagcmd --prefix=/usr/local/nagios
make && make install
cd ..
chown nagios.nagcmd /usr/local/nagios
chown -R nagios.nagcmd /usr/local/nagios/libexec
cat > /etc/httpd/conf.d/nagios.conf << \EOF
##config web
#setting for nagios 20111009
#setting by keke
ScriptAlias /nagios/cgi-bin /usr/local/nagios/sbin
Options ExecCGI
AllowOverride None
Order allow,deny
Allow from all
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd
Require valid-user
Alias /nagios /usr/local/nagios/share
Options None
AllowOverride None
Order allow,deny
Allow from all
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd
Require valid-user
EOF
sed -i 's/#ServerName 127.0.0.1:80/g' /etc/httpd/conf/httpd.conf
service httpd restart
/usr/bin/htpasswd -b -c /usr/local/nagios/etc/htpasswd test keke123
#/usr/local/nagios/etc/cgi.cfg test replase nagiosadmin
sed -i 's/nagiosadmin/test/g' /usr/local/nagios/etc/cgi.cfg
ln -s /usr/local/nagios/bin/nagios /bin/nagios
ln -s /usr/local/nagios/etc/nagios.cfg /etc/nagios.cfg
sed -i 's@#cfg_dir=/usr/local/nagios/etc/servers@cfg_dir=/usr/local/nagios/etc/servers@g' /usr/local/nagios/etc/nagios.cfg
mkdir /usr/local/nagios/etc/servers
cat > /usr/local/nagios/etc/servers/loclhost001.cfg <<\EOF
define host{
use linux-server
host_name localhost001
alias localhost_001
address 127.0.0.1
}
define service{
use generic-service
host_name localhost001
service_description check_ping
check_command check_ping!100.0,20%!200.0,50%
max_check_attempts 5
normal_check_interval 1
}
EOF
rs=$(/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg|tail -n 1|awk '{print $3}')
if [ "$rs" = "okay" ];then
service nagios restart
echo -e "[ \033[1;32m"Nagios Start Success\!"\033[0m ]"
else
echo -e "[ \033[1;031m"Nagios CfgFile ERROR"\033[0m ]"
fi
#install Nrpe
[ ! -d /data0/soft/nagios ] && mkdir /data0/soft/nagios
cd !$
wget http://sourceforge.net/projects/nagios/files/nrpe-2.x/nrpe-2.8.1/nrpe-2.8.1.tar.gz/download?use_mirror=ncu
tar -zxvf nrpe-2.8.1.tar.gz
cd nrpe-2.8.1
./configure --enable-command-args
make all
make install-plugin
make install-daemon
make install-daemon-config
make install-xinetd
sed -i 's/allowed_hosts=127.0.0.1/allowed_hosts=,127.0.0.1,194.168.0.86/g' /usr/local/nagios/etc/nrpe.cfg
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
rs=$(/usr/local/nagios/libexec/check_nrpe -H localhost)
if [[ "$rs" =~ '^NRPE v' ]];then
echo -e "[ \033[1;32m"$rs Install Success\!"\033[0m ]"
else
echo -e "[ \033[1;031m"NRPE Install ERROR"\033[0m ]"
fi
阅读(1109) | 评论(5) | 转发(0) |