Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1172295
  • 博文数量: 150
  • 博客积分: 2739
  • 博客等级: 少校
  • 技术积分: 2392
  • 用 户 组: 普通用户
  • 注册时间: 2010-12-07 12:28
文章分类

全部博文(150)

文章存档

2015年(2)

2014年(16)

2013年(10)

2012年(58)

2011年(64)

分类: Python/Ruby

2014-04-27 22:36:33


Nagios监控绘图之--nagios一键安装脚本

        这个就不多说了,nagios只要懂linux的都知道的软件。这里留个一键安装脚本


点击(此处)折叠或打开

  1. #/bin/bash
  2. ##Auther Gavin
  3. ##Mail wkgbc456@163.com
  4. ##blog http://wkgbc.blog.chinaunix.net/

  5. # rpm -q httpd php gcc glibc glibc-common gd gd-devel

  6. #mount /dev/cdrom /media/cdrom
  7. #yum --disablerepo=\* --enablerepo=c5-media install -y httpd php gcc glibc glibc-common gd gd-devel net-snmp-* perl-DBI rrdtool rrdtool-devel
  8. #yum --disablerepo=\* --enablerepo=c5-media install -y xinetd mysql-server
  9. INSTALL_LOG=/tmp/install_log
  10. NPREFIX=/var/www/html/nagios

  11. read -p "You select fist install,Input F,Reinstall Input R,Uninstall Input U, Exit Input other... " INSTALL
  12. case $INSTALL in
  13. f|F)
  14. mount /dev/cdrom /media/cdrom
  15. yum --disablerepo=\* --enablerepo=c5-media install -y httpd php gcc glibc glibc-common gd gd-devel net-snmp-* perl-DBI rrdtool rrdtool-devel
  16. yum --disablerepo=\* --enablerepo=c5-media install -y xinetd mysql-server
  17. ;;
  18. r|R)
  19. /etc/init.d nagios stop
  20. rm -rf $NPREFIX
  21. rm -rf /etc/init.d/nagios
  22. rm -rf /etc/httpd/conf.d/nagios.conf
  23. rm -rf nagios-3.5.1 nagios-plugins-2.0 nagios-plugins-snmp nrpe-2.13
  24. rm -rf /etc/xinetd.d/nrpe
  25. cp /etc/{services.nagios_bak,services}
  26. /etc/init.d/httpd reload
  27. service xinetd restart
  28. ;;
  29. u|U)
  30. /etc/init.d nagios stop
  31. rm -rf $NPREFIX
  32. rm -rf $NPREFIX
  33. rm -rf /etc/init.d/nagios
  34. rm -rf /etc/httpd/conf.d/nagios.conf
  35. rm -rf nagios-3.5.1 nagios-plugins-2.0 nagios-plugins-snmp nrpe-2.13
  36. rm -rf /etc/xinetd.d/nrpe
  37. cp /etc/{services.nagios_bak,services}
  38. /etc/init.d/httpd reload
  39. service xinetd restart
  40.  exit 0
  41. ;;
  42. *)
  43.   exit 2
  44. ;;
  45. esac

  46. ################Install rrdtool####################
  47. #if [ -f rrdtool-1.4.7.tar.gz ];then
  48. #tar xvf rrdtool-1.4.7.tar.gz
  49. #cd rrdtool-1.4.7
  50. #make clean
  51. #./configure --prefix=/usr/local/rrdtool
  52. # [ $? == "0" ] && make || exit;
  53. # [ $? == "0" ] && make install || exit;
  54. #cd ..
  55. #else
  56. # echo "rrdtool don't install...">>$NPREFIX
  57. #fi

  58. ####################################################
  59. ##############Install NAGIOS Software###############
  60. useradd nagios
  61. groupadd nagcmd
  62. usermod -a -G nagcmd nagios
  63. usermod -a -G nagcmd apache

  64. if [ -f nagios-3.5.1.tar.gz ];then
  65. tar xvf nagios-3.5.1.tar.gz
  66. cd nagios
  67. make clean
  68. ./configure --prefix=$NPREFIX --with-nagios-user=nagios --with-nagios-group=nagios --with-command-group=nagcmd --with-command-user=nagios
  69.  [ $? == "0" ] && make all || exit ;
  70.  [ $? == "0" ] && make install || exit ;
  71.  [ $? == "0" ] && make install-init || exit ;
  72.  [ $? == "0" ] && make install-config || exit ;
  73.  [ $? == "0" ] && make install-commandmode || exit ;
  74.  [ $? == "0" ] && make install-webconf || exit ;
  75. cd ..
  76. else
  77.    echo "The nagios software isn't" >>$INSTALL_LOG
  78. fi
  79. echo -e "Input nagiosadmin Password: "
  80. htpasswd -bc $NPREFIX/etc/htpasswd.users nagiosadmin 123456


  81. #############Install nagios-Plugin##################

  82. if [ -f nagios-plugins-2.0.tar.gz ];then
  83. tar xvf nagios-plugins-2.0.tar.gz
  84. cd nagios-plugins-2.0
  85. make clean
  86. ./configure --prefix=$NPREFIX/ --with-nagios-user=nagios --with-nagios-group=nagios
  87.  [ $? == "0" ] && make || exit;
  88.  [ $? == "0" ] && make install || exit;
  89. cd ..
  90. else
  91.   echo "nagios-plugins Software isn't...." >>$INSTALL_LOG
  92.   exit;
  93. fi


  94. ##############Install-nagios-plugins-snmp###########

  95. if [ -f nagios-plugins-snmp-0.6.0.tgz ];then
  96.  tar xvf nagios-plugins-snmp-0.6.0.tgz
  97.  cd nagios-plugins-snmp
  98.  make clean
  99.  ./configure --prefix=$NPREFIX
  100.  [ $? == "0" ] && make || exit;
  101.  [ $? == "0" ] && make install || exit;
  102. cd ..
  103. else
  104.   echo "nagios-plugins-snmp configure failure.." >>$INSTALL_LOG
  105.   exit;
  106. fi

  107. #############Restart nagios Server################
  108. echo "Start nagios Server...."
  109. chkconfig nagios on
  110. service nagios restart
  111. service httpd restart
  112. sleep 2

  113. if ps -ef|grep nagios;then
  114.   echo "nagios Successfull"
  115.   echo "Nagios Successfull....">>$INSTALL_LOG
  116. else
  117.   echo "Nagios Failure....">>$INSTALL_LOG
  118.   exit;
  119. fi



  120. #####################################################
  121. ##############Install NRPE Software##################
  122. if [ -f nrpe-2.13.tar.gz ];then
  123. tar xvf nrpe-2.13.tar.gz
  124. cd nrpe-2.13
  125. make clean
  126. ./configure --prefix=$NPREFIX
  127. [ $? == "0" ] && make all || exit;
  128. [ $? == "0" ] && make install-plugin || exit;
  129. [ $? == "0" ] && make install-daemon || exit;
  130. [ $? == "0" ] && make install-daemon-config || exit;
  131. cd ..
  132. else
  133.   echo "nrpe don't install">>$INSTALL_LOG && exit;
  134. fi

  135.  
  136. ####nrpe set##################
  137. if grep "check_nrpe" $NPREFIX;then
  138.    echo "It do nothing....";
  139. else
  140. cp $NPREFIX/etc/objects/{commands.cfg,commands.cfg.bak}
  141. cat>>$NPREFIX/etc/objects/commands.cfg<<EOF
  142. ##nrpe monning
  143. define command{
  144.     command_name check_nrpe
  145.     command_line $NPREFIX/libexec/check_nrpe -H \$HOSTADDR# -c \$ARG1$
  146. }
  147. EOF
  148. fi

  149. ##nrpe server_configure
  150. rm -rf /etc/xinetd.d/nrpe
  151. cat >>/etc/xinetd.d/nrpe<<EOF
  152. service nrpe
  153. {
  154.     flags        = REUSE
  155.     socket_type    = stream
  156. port        = 5666
  157.     wait        = no
  158.     user        = nagios
  159. group        = nagios
  160.     server        = $NPREFIX/bin/nrpe
  161.     server_args     = -c $NPREFIX/etc/nrpe.cfg --inetd
  162.     log_on_failure += USERID
  163.     disable        = no
  164.     only_from    =127.0.0.1
  165. }
  166. EOF

  167. ##add nrep port
  168. cp /etc/{services,services.nagios_bak}
  169. if grep "5666" /etc/services;then
  170.   echo "It do nothing....";
  171. else
  172. echo "nrpe        5666/tcp            #nrpe" >>/etc/services
  173. fi

  174. ###Reboot NRPE Server
  175. service xinetd restart
  176. sleep 2;
  177. if netstat -ntlup|grep 5666;then
  178.    echo "NRpe configure Ok..">>$INSTALL_LOG
  179. else
  180.    echo "Nrpe congigure failure" && exit
  181. fi



其他一键安装脚本,测试环境Centos 5.5

点击(此处)折叠或打开

  1. cacti与npc一键安装脚本链接:http://blog.chinaunix.net/uid-25046147-id-4228848.html

  2. nagios一键安装脚本:http://blog.chinaunix.net/uid-25046147-id-4228845.html

  3. nrpe一键安装:http://blog.chinaunix.net/uid-25046147-id-4228843.html

  4. pnp4nagios一键安装脚本:http://blog.chinaunix.net/uid-25046147-id-4228835.html

  5. 一键安装LAMP:http://blog.chinaunix.net/uid-25046147-id-4226114.html


阅读(7521) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~