Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1363352
  • 博文数量: 632
  • 博客积分: 2778
  • 博客等级: 大尉
  • 技术积分: 3387
  • 用 户 组: 普通用户
  • 注册时间: 2012-05-31 09:09
个人简介

123

文章分类

全部博文(632)

文章存档

2014年(36)

2013年(33)

2012年(563)

分类: LINUX

2014-04-14 11:32:37

原文地址:批量部署Cacti监控系统 作者:railon

本文转载自:

背景:公司总共有十几个机房,每个机房都要部署一台监控系统

思路:一台一台去安装肯定太慢,也麻烦,更累。写一个或者多个部署脚本,指安装和配置监控系统

分三个脚本来实现

  1. 监控系统环境安装脚本
  2. 监控系统安装脚本
  3. 监控系统配置脚本
  4. 监控系统数据库脚本

一、监控系统部署

1.监控系统环境安装脚本

  1. #!/bin/bash
  2. cd /root/CentOS
  3. echo "cd /root/CentOS"

  4. sleep 3
  5. echo "Install SNMP Server..."
  6. rpm -ivh net-snmp-5.3.1-24.el5.i386.rpm net-snmp-utils-5.3.1-24.el5.i386.rpm net-snmp-devel-5.3.1-24.el5.i386.rpm net-snmp-perl-5.3.1-24.el5.i386.rpm beecrypt-devel-4.1.2-10.1.1.i386.rpm elfutils-devel-0.125-3.el5.i386.rpm lm_sensors-devel-2.10.0-3.1.i386.rpm lm_sensors-2.10.0-3.1.i386.rpm elfutils-devel-static-0.125-3.el5.i386.rpm

  7. sleep 3
  8. echo "Install php-snmp..."
  9. rpm -ivh php-snmp-5.1.6-20.el5.i386.rpm

  10. cd /root/monitor/rrd
  11. echo "cd /root/monitor/rrd"
  12. sleep 3
  13. echo "Install RRDTool..."
  14. rpm -ivh perl-rrdtool-1.2.23-1.el5.rf.i386.rpm rrdtool-1.2.23-1.el5.rf.i386.rpm rrdtool-devel-1.2.23-1.el5.rf.i386.rpm

  15. sleep 3
  16. echo "Install Syslog-NG..."
  17. rpm -ivh syslog-ng-2.1.4-1.el5.i386.rpm

  18. sleep 3
  19. echo "Copy Configure Files..."
  20. mv /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf.bak
  21. cp /root/monitor/snmpd.conf /etc/snmp/

  22. sleep 3
  23. echo "Set the file +x..."
  24. chmod +x /etc/rc.d/init.d/syslog-ng

  25. sleep 3
  26. chkconfig --level 3 snmpd on
  27. service snmpd restart

  28. sleep 3
  29. cd /root/monitor/rrd
  30. sleep 3
  31. tar xzvf cacti-spine-0.8.7a.tar.gz
  32. sleep 3
  33. cd cacti-spine-0.8.7a
  34. sleep 3
  35. ./configure
  36. sleep 3
  37. make
  38. sleep 3
  39. make install

  40. #sleep 3
  41. #echo "Install Nessus Security..."
  42. #rpm -ivh /root/monitor/Nessus-3.2.1-es5.i386.rpm

2.监控系统安装脚本

  1. #!/bin/bash
  2. #
  3. # Create by kevin
  4. # Data 2009-04-28
  5. # Mail kevinadmin@sohu.com
  6. #

  7. if [ ! -e /www ]; then
  8. mkdir /www
  9. fi

  10. if [ -e /www ]; then
  11. echo "Copy the Cacti files..."
  12. sleep 2
  13. cp -r /root/monitor/cacti/* /www/
  14. sleep 2
  15. cp -r /root/monitor/cacti-plugin-arch/* /www/
  16. sleep 2
  17. cp -r /root/monitor/cactiez/* /www/

  18. sleep 2
  19. # Configure the syslog-NG
  20. echo "Congfiure the syslog-NG..."
  21. cp /root/monitor/sbin/syslogtomysql /sbin/
  22. chmod +x /sbin/syslogtomysql

  23. sleep 2
  24. echo "Configure the syslog-ng..."
  25. mv /etc/rc.d/init.d/syslog-ng /etc/rc.d/init.d/syslog-ng.bak
  26. mv /etc/rc.d/init.d/network /etc/rc.d/init.d/network.bak

  27. sleep 2
  28. cp /root/monitor/etc/rc.d/init.d/* /etc/rc.d/init.d/
  29. chmod +x /etc/rc.d/init.d/flow-capture /etc/rc.d/init.d/cacti_rrdsvc
  30. chmod +x /etc/rc.d/init.d/network /etc/rc.d/init.d/syslog-ng

  31. sleep 2
  32. cp /root/monitor/etc/logrotate.d/cacti /etc/logrotate.d/
  33. cp /root/monitor/etc/mail/relay-domains /etc/mail/

  34. sleep 2
  35. mv /etc/syslog-ng/syslog-ng.conf /etc/syslog-ng/syslog-ng.bak
  36. cp /root/monitor/etc/syslog-ng/syslog-ng.conf /etc/syslog-ng/

  37. sleep 2
  38. echo "Copy the Cacti Plugins files..."
  39. cp -r /root/monitor/plugins/* /www/plugins/
  40. fi

  41. sleep 2

  42. echo "Auto Create Database and other configure...."
  43. /root/monitor/automysql.sh

  44. sleep 2

  45. if [ -e /www/plugins/syslog ]; then

  46. echo "Import the SQL file to the Database..."
  47. mysql -u root --password=cactipasswd monitor < /www/cacti.sql
  48. mysql -u root --password=cactipasswd monitor < /www/pa.sql
  49. mysql -u root --password=cactipasswd monitor < /www/cacti-changes.sql
  50. mysql -u root --password=cactipasswd syslog < /www/plugins/syslog/syslog.sql
  51. mysql -u root --password=cactipasswd syslog < /www/syslog-changes.sql
  52. mysql -u root --password=cactipasswd monitor < /www/plugins/monitor/monitor.sql
  53. mysql -u root --password=cactipasswd monitor < /www/plugins/update/update.sql
  54. mysql -u root --password=cactipasswd monitor < /www/plugins/thold/thold.sql
  55. mysql -u root --password=cactipasswd monitor < /www/plugins/boost/boost_sql_myisam.sql
  56. mysql -u root --password=cactipasswd monitor < /www/plugins/boost/boost_sql_memory.sql
  57. mysql -u root --password=cactipasswd monitor < /www/plugins/realtime/realtime.sql
  58. mysql -u root --password=cactipasswd monitor < /www/plugins/discovery/discover.sql
  59. mysql -u root --password=cactipasswd monitor < /www/plugins/wmi/wmi.sql
  60. mysql -u root --password=cactipasswd monitor < /www/plugins/aggregate/aggregate.sql
  61. mysql -u root --password=cactipasswd monitor < /www/plugins/routerconfigs/routerconfigs.sql
  62. mysql -u root --password=cactipasswd monitor < /www/plugins/flowview/flowview.sql
  63. mysql -u root --password=cactipasswd monitor < /www/plugins/mactrack/mactrack.sql
  64. fi

  65. sleep 2

  66. echo "Auto Modified the Cacti about the connect the Database..."
  67. /root/monitor/automodify.sh

  68. sleep 2
  69. echo "Start the syslog-NG service..."
  70. chkconfig --level 345 syslog-ng on
  71. chkconfig --level 2345 syslog off
  72. service syslog-ng restart

3.监控系统配置脚本

  1. #!/bin/bash
  2. if [ -e /www ]; then

  3. echo "modify the config.php file"
  4. sed -i '27s/cacti/monitor/' /www/include/config.php

  5. sed -i '29s/cactiuser/cactiuser/' /www/include/config.php

  6. sed -i '30s/CactiMadeEZ/cactipasswd/' /www/include/config.php

  7. echo "modify the global.php file"
  8. sed -i '35s/cacti/monitor/' /www/include/global.php

  9. sed -i '37s/cactiuser/cactiuser/' /www/include/global.php

  10. sed -i '38s/cactiuser/cactipasswd/' /www/include/global.php

  11. echo "modify the syslog config.php file"
  12. sed -i '4s/syslog/syslog/' /www/plugins/syslog/config.php

  13. sed -i '6s/cactiuser/cactiuser/' /www/plugins/syslog/config.php

  14. sed -i '7s/CactiMadeEZ/cactipasswd/' /www/plugins/syslog/config.php

  15. echo "modify the syslogtomysql file"
  16. sed -i '8s/cactiuser/cactiuser/' /sbin/syslogtomysql
  17. sed -i '8s/CactiMadeEZ/cactipasswd/' /sbin/syslogtomysql

  18. echo "modify spine configure file"
  19. sed -i '32s/cacti/monitor/' /usr/local/spine/etc/spine.conf
  20. sed -i '33s/cactiuser/cactiuser/' /usr/local/spine/etc/spine.conf
  21. sed -i '34s/cactiuser/cactipasswd/' /usr/local/spine/etc/spine.conf
  22. fi

4.监控系统数据库脚本

  1. #!/usr/bin/expect -f
  2. set user "root"
  3. set passwd "hxwhb.com"
  4. set timeout 60
  5. set cmd "mysql>"
  6. spawn mysqladmin -u root password hxwhb.com
  7. spawn mysql -u $user -p
  8. expect "Enter password:"
  9. send "$passwd\r"
  10. sleep 3
  11. expect "$cmd"
  12. send "create database monitor;\r"
  13. expect "$cmd"
  14. sleep 3
  15. send "grant all privileges on monitor.* to cactiuser@localhost identified by 'cactipasswd';\r"
  16. expect "$cmd"
  17. sleep 3
  18. send "flush privileges;\r"
  19. expect "$cmd"
  20. sleep 3
  21. send "create database syslog;\r"
  22. expect "$cmd"
  23. sleep 3
  24. send "grant all privileges on syslog.* to cactiuser@localhost identified by 'cactipasswd';\r"
  25. expect "$cmd"
  26. send "flush privileges;\r"
  27. expect "$cmd"
  28. send "\q\r"


二、监控系统配置

1.把monitor.tar.gz上传到/root目录下面解压

   
tar xzvf monitor.tar.gz
cd monitor.tar.gz
./autoinstall.sh
./automodify.sh
./automysql.sh

如果没有报错,cacti和插件的安装配置就完成了。

2.设置crontab

   
*/1 * * * * php /www/poller.php

三、Cacti配置

1.设置cacti执行的进程数量

   
Setting-->general--->snmp defaults ---> 设置为 version 2 rpnode@cgc 保存
Setting-->general--->path 把rrdtool等路径设置好 保存

2.删除原来的模板

   
cacti_graph_template_host_mib_-_logged_in_users.xml
cacti_graph_template_host_mib_-_cpu_utilization.xml
cacti_data_query_win_services.xml

3.导入以下模板

组合模板:

4.导入前面删除的三个模板

   
cacti_graph_template_host_mib_-_logged_in_users.xml
cacti_graph_template_host_mib_-_cpu_utilization.xml
cacti_data_query_win_services.xml

5.设置discovery
Settings——>misc

Discovery

Discovery

6.建立discovery模板
Graph——discovery template

Discovery-template

Discovery-template

Cacti服务器安装完成


四、Cacti被监控服务器配置(windows)

1.安装snmp服务
添加删除——-windows组件—如图

install-snmp

install-snmp

2.配置SNMP

Services.msc—snmp服务

configure-SNMP

configure-SNMP

重启snmp服务就可以了

Cacti服务器和客户端安装配置完成

官方参考文档:

1.

2.






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