Chinaunix首页 | 论坛 | 博客
  • 博客访问: 280119
  • 博文数量: 76
  • 博客积分: 1414
  • 博客等级: 中尉
  • 技术积分: 702
  • 用 户 组: 普通用户
  • 注册时间: 2011-12-14 21:05
文章分类

全部博文(76)

文章存档

2013年(8)

2012年(68)

我的朋友

分类: LINUX

2012-04-12 22:45:15


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) |
0

上一篇:printf

下一篇:整合nagios与cacti

给主人留下些什么吧!~~

hnkeyang2012-04-15 22:40:02

虾米小: 。。嘎嘎~不错的文章啊,转一下不介意吧~~.....

虾米小2012-04-15 20:39:51

。。嘎嘎~不错的文章啊,转一下不介意吧~~

星期五啦2012-04-14 12:19:20

这和貌似已经有过了吧

夏冰软件2012-04-13 16:59:02

写的不错,支持一下

校长的马夹2012-04-13 12:59:02

很好用,谢谢了~