Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1175210
  • 博文数量: 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:40:30


Nagios监控绘图之---cacti与npc一键安装脚本

        cacti和npc一键安装脚本,安装前一定要安装nagios,这个是把nagios中的数据在cacti中显示出来的。经过测试,实验是成功的。


点击(此处)折叠或打开

  1. #!/bin/bash
  2. ##
  3. #date 2013-05-09
  4. ##Auther Gavin
  5. ##Mail wkgbc456@163.com
  6. ##blog http://wkgbc.blog.chinaunix.net/
  7. ##
  8. CPATH=/var/www/html
  9. INSTALL_LOG=/tmp/install_log
  10. USER=root
  11. PASS=cisco
  12. HOST=127.0.0.1

  13. read -p "You select fist install,Input F,Reinstall Input R,Uninstall Input U, Exit Input other... " INSTALL
  14. case $INSTALL in
  15. f|F)
  16.   echo -e "Starting install ....."
  17.  ;;
  18. r|R)
  19. /etc/init.d/nagios stop
  20. /etc/init.d/nd2odb stop
  21. rm -rf /usr/local/spine/
  22. rm -rf /etc/init.d/ndo2db
  23. rm -rf $CPATH/cacti
  24. rm -rf $CPATH/nagios/bin/ndo*
  25. rm -rf $CPATH/nagios/etc/ndo*
  26. rm -rf $CAPTH/nagios/bin/{file*,log2*}
  27. rm -rf cacti-spine-0.8.8b
  28. rm -rf ndoutils-1.5.2
  29. rm -rf /usr/local/spine
  30. rm -rf /var/www/html/cacti/
  31. #rm -rf /var/www/html/nagios
  32. #cp -R /var/www/html/{nagios_bak,nagios}
  33. #chown -R nagios:nagcmd /var/www/html/nagios
  34. mysql -u$USER -p$PASS -e "drop database cacti;"
  35.  ;;
  36. u|U)
  37. /etc/init.d/nagios stop
  38. /etc/init.d/ndo2db stop
  39. rm -rf /usr/local/spine/
  40. rm -rf /etc/init.d/ndo2db
  41. rm -rf $CPATH/cacti
  42. rm -rf $CPATH/nagios/bin/ndo*
  43. rm -rf $CPATH/nagios/etc/ndo*
  44. rm -rf $CAPTH/nagios/bin/{file*,log2*}
  45. rm -rf cacti-spine-0.8.8b
  46. rm -rf ndoutils-1.5.2
  47. rm -rf /usr/local/spine
  48. rm -rf /var/www/html/cacti/
  49. mysql -u$USER -p$PASS -e "drop database cacti;"
  50.  exit 0
  51. ;;
  52. *)
  53.   exit 2
  54.   ;;
  55. esac



  56. ##########################Install Cacti#####################
  57. #if [ -f php-json-ext-1.2.1.tar.bz2 ];then
  58. #tar xvf php-json-ext-1.2.1.tar.bz2
  59. #cd php-json-ext-1.2.1
  60. #make clean
  61. #./configure
  62. #make
  63. #make install
  64. #cd ..
  65. #fi

  66. #cat /etc/php.d/

  67. if [ -f cacti-spine-0.8.8b.tar.gz ];then
  68. echo -e "Install cacti-spne-0.8b...." >>$INSTALL_LOG
  69. tar xzf cacti-spine-0.8.8b.tar.gz
  70. cd cacti-spine-0.8.8b
  71. make clean
  72. ./configure --prefix=/usr/local/spine
  73. [ $? == 0 ] && make || exit;
  74. [ $? == 0 ] && make install || exit;
  75. cp /usr/local/spine/etc/spine.conf.dist /usr/local/spine/etc/spine.conf
  76. sed -i 's/DB_User cactiuser/DB_User cacti/g' /usr/local/spine/etc/spine.conf
  77. sed -i 's/DB_Pass cactiuser/DB_Pass 123456/g' /usr/local/spine/etc/spine.conf

  78. #sed -i 's@DB_Pass.*$@DB_Pass cactiuser123@' /usr/local/spine/etc/spine.conf
  79. cd ../
  80. else
  81.   echo "cacti-spine isn't ...."
  82. fi


  83. echo -e "Install cacti-0.8b......" >>$INSTALL_LOG
  84. tar xzf cacti-0.8.8b.tar.gz
  85. mv cacti-0.8.8b $CPATH/cacti/
  86. #mysql -ucacti -p123456 cacti </$CPATH/cacti/cacti.sql
  87. tar xvf npc-2.0.4.tar.gz
  88. mv npc $CPATH/cacti/plugins/
  89. sed -i 's@$database_username = "cactiuser"@$database_username = "cacti"@g' $CPATH/cacti/include/config.php
  90. sed -i 's@$database_password = "cactiuser"@$database_password = "123456"@g' $CPATH/cacti/include/config.php
  91. chown -R nagios:nagcmd $CPATH/cacti/*


  92. ###########Configure Mysql#####################
  93. mysql -u$USER -p$PASS -e "create database cacti;"
  94. mysql -u$USER -p$PASS -e "grant all on cacti.* to cacti@localhost identified by '123456';"
  95. mysql -u$USER -p$PASS -e "flush privileges;"
  96. mysql -ucacti -p123456 cacti <$CPATH/cacti/cacti.sql
  97. #sed -i 's@ENGINE=MyISAM@@g' /data/admin/cacti/cacti.sql
  98. #sed -i '1 i\create database cacti;' /data/admin/cacti/cacti.sql

  99. ######################################33
  100. read -p "Please use URL Install cacti,then enter any key to continue... "


  101. echo -e "Install ndoutils......." >>$INSTALL_LOG
  102. tar xvf ndoutils-1.5.2.tar.gz
  103. cd ndoutils-1.5.2
  104.  ./configure --prefix=$CPATH/nagios LDFAGS=-L/usr/lib --with-mysql-inc=/usr/include/mysql/ --with-mysql-lib=/usr/lib/mysql/ --enable-mysql --disable-pgsql --with-ndo2db-user=nagios --with-ndo2db-group=nagios
  105. make
  106. make install
  107. make config
  108. cp config/ndo2db.cfg-sample $CPATH/nagios/etc/ndo2db.cfg
  109. cp config/ndomod.cfg-sample $CPATH/nagios/etc/ndomod.cfg
  110. cp daemon-init /etc/init.d/ndo2db
  111. chmod +x /etc/init.d/ndo2db
  112. #mysql -ucacti -p123456 cacti < db/mysql.sql

  113. ################Config ndo2db.cfg file######################
  114. sed -i 's@^db_prefix=nagios_@db_prefix=npc_@' $CPATH/nagios/etc/ndo2db.cfg
  115. sed -i 's/socket_type=unix/#socket_type=unix/g' $CPATH/nagios/etc/ndo2db.cfg
  116. sed -i 's/#socket_type=tcp/socket_type=tcp/g' $CPATH/nagios/etc/ndo2db.cfg
  117. sed -i 's/db_name=nagios/db_name=cacti/g' $CPATH/nagios/etc/ndo2db.cfg
  118. sed -i 's/db_user=ndouser/db_user=cacti/g' $CPATH/nagios/etc/ndo2db.cfg
  119. sed -i 's/db_pass=ndopassword/db_pass=123456/g' $CPATH/nagios/etc/ndo2db.cfg

  120. #################Config ndomod.cfg file#######################
  121. sed -i 's/#output_type=tcpsocket/output_type=tcpsocket/g' $CPATH/nagios/etc/ndomod.cfg
  122. sed -i 's/output_type=unixsocket/#output_type=unixsocket/g' $CPATH/nagios/etc/ndomod.cfg
  123. sed -i 's/#output=127.0.0.1/output=127.0.0.1/g' $CPATH/nagios/etc/ndomod.cfg
  124. sed -i 's@output=/var/www/html/nagios/var/ndo.sock@#output=/var/www/html/nagios/var/ndo.sock@g' $CPATH/nagios/etc/ndomod.cfg



  125. sed -i 's@\(.*broker_module=/somewhere/module2.o.*$\)@\1\nbroker_module='$CPATH'/nagios/bin/ndomod.o config_file='$CPATH'/nagios/etc/ndomod.cfg@' $CPATH/nagios/etc/nagios.cfg
  126. chown -R nagios:nagcmd $CPATH/nagios/etc/
  127. cd ..

  128. #########Reboot Service#################
  129. /etc/init.d/ndo2db restart
  130. sleep 1
  131. /etc/init.d/nagios restart
  132. sleep 5

  133. read -p "Plase any key to Configure mysql....."
  134. #exit;
  135. #################Mysql Setting#######################################
  136. mysql -u$USER -p$PASS -e "alter table cacti.npc_eventhandlers add long_output TEXT NOT NULL default '' after output;"
  137. mysql -u$USER -p$PASS -e "alter table cacti.npc_hostchecks add long_output TEXT NOT NULL default '' after output;"
  138. mysql -u$USER -p$PASS -e "alter table cacti.npc_hoststatus add long_output TEXT NOT NULL default '' after output;"
  139. mysql -u$USER -p$PASS -e "alter table cacti.npc_notifications add long_output TEXT NOT NULL default '' after output;"
  140. mysql -u$USER -p$PASS -e "alter table cacti.npc_servicechecks add long_output TEXT NOT NULL default '' after output;"
  141. mysql -u$USER -p$PASS -e "alter table cacti.npc_servicestatus add long_output TEXT NOT NULL default '' after output;"
  142. mysql -u$USER -p$PASS -e "alter table cacti.npc_statehistory add long_output TEXT NOT NULL default '' after output;"
  143. mysql -u$USER -p$PASS -e "alter table cacti.npc_systemcommands add long_output TEXT NOT NULL default '' after output;"
  144. #sed -i 's@ENGINE=MyISAM@@g' $CPATH/cacti/cacti.sql

  145. #########Reboot Service#################
  146. /etc/init.d/ndo2db restart
  147. sleep 1
  148. /etc/init.d/nagios restart




测试环境: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


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

随风飘云2014-05-02 15:26:53

文明上网,理性发言...