一键自动化安装nagios图形监控界面

声明

作者:昨夜星辰

博客:http://yestreenstars.blog.51cto.com/

本文由本人创作,如需转载,请注明出处,谢谢合作!

目的

一键自动化安装nagios图形监控界面

主要软件

OS: CentOS 6.2 32

nagios: 4.0.7

nagios-plugins: 2.0.3

nrpe: 2.15

pnp4nagios: 0.6.25

注意事项

我已经将以下配置过程中会用到的软件打包上传到云盘,读者可以直接从云盘下载并上传至/tmp目录。

http://yunpan.cn/cVLXDNhuhdgbR (提取码:53e7)

配置

#!/bin/bash
# 脚本名称:一键自动化安装nagios图形监控界面脚本
# 脚本描述:nagios+pnp4nagios
# 作者:昨夜星辰
# 创建时间:2015-04-10
# 修改时间:2015-04-10

if [ ! -d '/tmp/check_mk' ]
then
	echo '检测到你还没将软件包上传到/tmp目录,脚本即将终止,请上传后再执行脚本!'
	exit 1
fi

while read -p '请为nagiosadmin设置密码(用于登录nagios监控页面):' NAGIOSADMIN_PASSWORD
do
	if [ -n $NAGIOSADMIN_PASSWORD ]
	then
		break
	fi
done

echo -n '正在关闭iptables和SELinux...'
(
service iptables stop
chkconfig iptables off
setenforce 0
[ -f /etc/selinux/config ] && sed -i '/^SELINUX=/s/=.*/=disabled/' /etc/selinux/config
) &> /dev/null && echo '完成' || exit

echo -n '正在安装相关软件...'
(
yum -y groupinstall 'Development Tools'
yum -y install httpd-devel python-devel rrdtool rrdtool-perl perl-Time-HiRes gd gd-devel openssl openssl-devel php php-gd net-snmp expect
) &> /dev/null && echo '完成' || exit

echo -n '正在安装nagios...'
(
useradd nagios -M -s /sbin/nologin
gpasswd -a apache nagios
tar xzf /tmp/check_mk/nagios-4.0.7.tar.gz -C /usr/local/src/
cd /usr/local/src/nagios-4.0.7/
./configure
make all
make install
make install-init
make install-commandmode
make install-config
make install-webconf
) &> /dev/null && echo '完成' || exit

echo -n '正在安装nagios-plugins...'
(
tar xzf /tmp/check_mk/nagios-plugins-2.0.3.tar.gz -C /usr/local/src/
cd /usr/local/src/nagios-plugins-2.0.3/
./configure
make
make install
) &> /dev/null && echo '完成' || exit

echo -n '正在安装nrpe...'
(
tar xzf /tmp/check_mk/nrpe-2.15.tar.gz -C /usr/local/src/
cd /usr/local/src/nrpe-2.15/
./configure
make all
make install-plugin
make install-daemon
make install-daemon-config
) &> /dev/null && echo '完成' || exit

echo -n '正在启动httpd和nagios...'
(
service httpd start
chkconfig httpd on
service nagios start
chkconfig --add nagios
chkconfig nagios on
) &> /dev/null && echo '完成' || exit

echo -n '正在为nagiosadmin设置密码...'
(
expect << EOF
spawn htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
expect {
	":" {
		send "$NAGIOSADMIN_PASSWORD\n"
		exp_continue
	}
	expect eof
}
EOF
) &> /dev/null && echo '完成' || exit

echo -n '正在安装pnp4nagios...'
(
tar xzf /tmp/check_mk/pnp4nagios-0.6.25.tar.gz -C /usr/local/src/
cd /usr/local/src/pnp4nagios-0.6.25/
./configure
make all
make fullinstall
cp /usr/local/src/pnp4nagios-0.6.25/contrib/ssi/status-header.ssi /usr/local/nagios/share/ssi/
rm -f /usr/local/pnp4nagios/share/install.php
sed -i '/process_performance_data/s/0/1/' /usr/local/nagios/etc/nagios.cfg
echo '
#
# service performance data
#
service_perfdata_file=/usr/local/pnp4nagios/var/service-perfdata
service_perfdata_file_template=DATATYPE::SERVICEPERFDATA\tTIMET::$TIMET$\tHOSTNAME::$HOSTNAME$\tSERVICEDESC::$SERVICEDESC$\tSERVICEPERFDATA::$SERVICEPERFDATA$\tSERVICECHECKCOMMAND::$SERVICECHECKCOMMAND$\tHOSTSTATE::$HOSTSTATE$\tHOSTSTATETYPE::$HOSTSTATETYPE$\tSERVICESTATE::$SERVICESTATE$\tSERVICESTATETYPE::$SERVICESTATETYPE$
service_perfdata_file_mode=a
service_perfdata_file_processing_interval=15
service_perfdata_file_processing_command=process-service-perfdata-file

#
# host performance data starting with Nagios 3.0
# 
host_perfdata_file=/usr/local/pnp4nagios/var/host-perfdata
host_perfdata_file_template=DATATYPE::HOSTPERFDATA\tTIMET::$TIMET$\tHOSTNAME::$HOSTNAME$\tHOSTPERFDATA::$HOSTPERFDATA$\tHOSTCHECKCOMMAND::$HOSTCHECKCOMMAND$\tHOSTSTATE::$HOSTSTATE$\tHOSTSTATETYPE::$HOSTSTATETYPE$
host_perfdata_file_mode=a
host_perfdata_file_processing_interval=15
host_perfdata_file_processing_command=process-host-perfdata-file' >> /usr/local/nagios/etc/nagios.cfg
echo '
define command{
       command_name    process-service-perfdata-file
       command_line    /bin/mv /usr/local/pnp4nagios/var/service-perfdata /usr/local/pnp4nagios/var/spool/service-perfdata.$TIMET$
}

define command{
       command_name    process-host-perfdata-file
       command_line    /bin/mv /usr/local/pnp4nagios/var/host-perfdata /usr/local/pnp4nagios/var/spool/host-perfdata.$TIMET$
}' >> /usr/local/nagios/etc/objects/commands.cfg
echo '
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
}' >> /usr/local/nagios/etc/objects/templates.cfg
sed -i '/\buse\b/{s/linux-server/&,host-pnp/;s/local-service/&,srv-pnp/}' /usr/local/nagios/etc/objects/localhost.cfg
service npcd start
chkconfig --add npcd
chkconfig npcd on
) &> /dev/null && echo '完成' || exit

echo '安装完毕!'
echo '通过http://localhost/nagios可以访问nagios监控页面。'
echo '通过http://localhost/pnp4nagios可以直接访问图形监控页面。'



你可能感兴趣的:(图形,nagios,pnp4nagios)