配置监控服务器(Nagios服务器)
1、安装所需的软件(nagios、nagios-plugins、nrpe)
wget
wget
wget
2、安装nagios与nagios-plugins
1)nagios与nagios-plugins的安装
查看:http://hi.baidu.com/9812658/blog/item/ae3632edd4f5afe2ce1b3e0e.html
2)安装nrpe
tar -zxvf nrpe-2.12.tar.gz && cd nrpe-2.12
./configure --enable-ssl --with-ssl-lib (前提是已经安装了openssl与openssl-devel)
make all && make install-plugin && make install-daemon && make install-daemon-config
3)配置nrpe
#在commands.cfg中定义nrpe这个外部构件
vi /usr/local/nagios/etc/nagios.cfg,打开下面这一行
cfg_file=/usr/local/nagios/etc/objects/commands.cfg
vi /usr/local/nagios/etc/objects/commands.cfg,增加如下一行
#check nrpe
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
启动nrpc,并测试
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
echo '/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d &> /dev/null' >> /etc/rc.local
netstat -atulnp | grep 'nrpe'
tcp 0 0 0.0.0.0:5666 0.0.0.0:* LISTEN 3308/nrpe
/usr/local/nagios/libexec/check_nrpe -H 192.168.1.188 #linux客户端的IP地址:192.168.1.188
NRPE v2.12
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
service nagios restart
配置ips
cat /usr/local/nagios/libexec/ip_conn.sh
#!/bin/sh
#if [ $# -ne 2 ]
#then
# echo "Usage:$0 -w num1 -c num2"
#exit 3
#fi
ip_conns=`netstat -an | grep tcp | grep EST | wc -l`
if [ $ip_conns -lt $1 ]
then
echo "OK -connect counts is $ip_conns"
exit 0
fi
if [ $ip_conns -gt $1 -a $ip_conns -lt $2 ]
then
echo "Warning -connect counts is $ip_conns"
exit 1
fi
if [ $ip_conns -gt $2 ]
then
echo "Critical -connect counts is $ip_conns"
exit 2
fi
赋予权限和主组
chown nagios:nagios /usr/local/nagios/libexec/*
chmod u+x /usr/local/nagios/libexec/ip_conn.sh
配置监控mysql主从复制
操作步骤:1、在主数据库服务器增加一个用户,给予较低的权限,操作为
mysql > grant Replication client on *.* to 'nagios'@'%' identified by 'nagios';
mysql> flush privileges;
2、登陆从服务器验证一下,看是否正常。操作为
mysql -unagios -pnagios -e "show slave stutas\G"
3、在从服务器安装 nrpe,然后在配置文件nrpe.cfg加入一行
command[check_mysql_slave]=/usr/local/nrpe/libexec/check_mysql_slave
4、编写脚本/usr/local/nrpe/libexec/check_mysql_slave(这是监控其作用的核心),其内容如下
#!/bin/sh
declare -a slave_is
slave_is=($(/usr/local/mysql/bin/mysql -h127.0.0.1 -unagios -pnagios -e "show slave status\G"|grep Running |awk '{print $2}'))
if [ "${slave_is[0]}" = "Yes" -a "${slave_is[1]}" = "Yes" ]
then
echo "OK -slave is running"
exit 0
else
echo "Critical -slave is error"
exit 2
fi
5、手动运行这个脚本,观察输出。
发现如果是2个yes输出为ok 否则输出为Critical
6、执行
check_nrpe -H 192.168.99.102 -c check_mysql_slave
重新启动辅助数据库服务器的nrpe
重启主服务器的nagios
阅读(2521) | 评论(0) | 转发(0) |