tar jxf nagios-cn-3.2.3.tar.bz2 解压nagios
cd nagios-cn-3.2.3
./configure –-enable-embedded-perl 编译
make all
make install
make install-init
make install-commandmode
make install-config
make install-webconf
yum install mysql-devel openssl-devel -y 编译所需软件包
tar zxf nagios-plugins-1.4.15.tar.gz nagios 插件安装
cd nagios-plugins-1.4.15
./configure —with-nagios-user=nagios —with-nagios-group=nagios
--enable-extra-opts —enable-libtap —enable-perl-modules
Make && make install
cp -r localhost.cfg hosts.cfg
vi /usr/local/nagios/etc/objects/hosts.cfg
去掉service部分,只留下想要的的hosts部分
define host{
use linux-server ; 给网络设备用的
host_name Desktop5
alias nagios
address 192.168.0.5
2d_coords 100,200
3d_coords 100,200,100
}
define hostgroup{
hostgroup_name linux-servers ; The name of the hostgroup
alias Linux Servers ; Long name of the group
members * ; Comma separated list of hosts that belong to this group
}
如下图:
cp -r localhost.cfg services.cfg
vi /usr/local/nagios/etc/objects/services.cfg
去掉hosts部分,只留下想要的的service部分
define servicegroup{
servicegroup_name 系统负荷检查
alias 负荷检查
members Desktop5,进程总数,Desktop5,登录用户数,Desktop5,根分区,Desktop5,交换空间利用率
}
define servicegroup{
servicegroup_name 全部联通性检查
alias 联通性检查
members Desktop5,PING
}
监控主机设定
tar zxf nrpe-2.12.tar.gz
cd nrpe-2.12
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make all
make install-plugin
/usr/local/nagios/libexec/check_nrpe -H 192.168.0.1
NRPE v2.12
#如看到如下输出说明连接正常
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
service nagios reload
#检测无误后重载 nagios
Nagios 整合飞信
http://www.it-adv.net/ 下载 fetion 主程序与支持库
步骤
(1)IP:192.168.0.85:
cd ~
lftp 127.0.0.1
cd /pub/docs/nagios
get fetion cenos54X64_20101113.rar
cd /pub/docs
get rarlinux-3.8.0.tar.gz
cp fetion /usr/local/nagios/libexec
cd /usr/local/nagios/libexec
chmod +x fetion
chown nagios.nagios fetion
(2)执行 /usr/local/nagios/libexec/fetion
出现没有/lib/ld-linux.so
yum install /lib/ld-linux.so.2 -y
cd /usr/local/nagios/libexec/
./fetion
cd ~
tar zxf rarlinux-3.8.0.tar.gz -C /opt/
cd /opt/rar/unrar
/opt/rar/unrar x cenos54X64_20101113.rar(可能会出错,需要安装以下的包,然后重新执行此步。)yum install libstdc++.so.6
(3) cd ~
lftp 192.168.0.254
cd /pub/docs/nagios
get linuxso_20111113.tar.gz
tar zxf linuxso_20111113.tar.gz -C /usr/local/lib(将库文件放到/usr/local/ib中。ldconfig /usr/local/lib使其生效。)
cd /usr/local/lib
ls 会有4个so文件。
chmod +x *
需要的时候可能需要安装: yum install libgssapi_krb5.so.2 libz.so.1 zlib文件。
ldconfig /usr/local/lib
/usr/local/nagios/libexec/fetion 7执行成功。
(4)vi /etc/ld.so.conf.d/mysql-x86_64.conf
/usr/lib64/mysql
(5) vi fetion.conf
/usr/local/lib
ldconfig
(6) su - nagios
/usr/local/nagios/libexec/fetion --mobile=158029XXXXX --pwd=XXXXXX(飞信密码) --to=15802955XXXX --msg-utf8="hello"
然后你去/usr/local/nagios/libexec找到1509154xxxx.jpg,然后将其复制到桌面,查看其验证码,然后写上去,你就会在1509154xxxx收到一个由mobile=1509154xxxx发来的信息哦!)
你第一次用验证码,第二次就不用验证码。
实验五:
fetion 与 nagios 配置
步骤(1)cd /usr/local/nagios/libexec/
vi fetion.sh
/usr/local/nagios/libexec/fetion --mobile=158029XXXXX --pwd=qqXXXXX --to="$1" --msg-utf8="$2" > /dev/null
(2) chmod +x fetion.sh
chown ngios.nagios fetion.sh
su - nagios
cd /usr/local/nagios/libexec/
./fetion.sh 1509154xxxx "hello" (测试给1509154xxxx发送小心“hello“)
此时因为你重新调用的程序,需要重新找到验证码并输入.....
然后就可以收到信息喽......
(3) cd /usr/local/nagios/etc/objects/
vi templates.cfg
Generic contact definition template - This is NOT a real contact, just a template!
define contact{
name generic-contact ; The name of this contact template
.
.
.
service_notification_commands notify-service-by-email,notify-service-by-fetion ; send service notifications via email
host_notification_commands notify-host-by-email,notify-host-by-fetion ; send host notifications via email
..........................
}
(4) vi /usr/local/nagios/etc/objects/commands.cfg
增加以下内容:
# 'notify-host-by-fetion' command definition
define command{
command_name notify-host-by-fetion
command_line $USER1$/fetion.sh $CONTACTPAGER$ "$NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$"
}