01.#!/bin/bash 02.#function +++++++++++++cacti auto install scripts+++++++++++++++++++ 03.#author itnihao 04.#version 1.1 05.#date 2012-08-17 v1.006.#date 2012-08-18 v1.1更新增加syslog-ng等内容07.#mail itnihao@qq.com 08.#www.bianceng.cn 09.#source http://code.google.com/p/auto-task-pe/ 10. 11.green='\e[0;32m' 12.red='\e[0;31m' 13.blue='\e[0;36m' 14.blue1='\e[5;31m' 15.NC='\e[0m' 16.path_soft=$(pwd) 17. 18.function base { 19. #rpm -e lrzsz&& yum -y install lrzsz* 20. #[ "$?" != "0" ] && echo "yum is badly,please check" && exit 1 21. for i in $(rpm -q gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5-devel libidn libidn-devel openssl openssl-devel bison bison-devel readline readline-devel libmcrypt libmcrypt-devel net-snmp-devel gcc gcc-c++ apr apr-util postgresql-libs openssl openssl-devel autoconf automake fiex* libxml* ncurses* libtool* libxslt libxslt-devel curl* bzip2* gd gd-devel freetype freetype-devel libpng*|grep 'not installed' | awk '{print $2}') 22. do 23. yum -y install $i; 24. done 25.} 26. 27. 28.function lamp { 29.yum -y install httpd mysql-server mysql php* net-snmp* rrdtool* 30.sed -i "s/;date.timezone =/date.timezone = Asia\/Chongqing/g" /etc/php.ini 31.#start lamp services 32.for name in httpd mysqld snmpd 33. do 34. service ${name} restart 35. chkconfig --add ${name} 36. chkconfig --level 345 ${name} on 37. done 38.for name1 in nfslock rpcbind 39. do 40. service ${name1} stop 41. chkconfig --del ${name1} 42. done 43. echo -e "<?php\nphpinfo();\n?>">/var/www/html/test.php 44.} 45. 46.#add php_type 47.#echo "AddType application/x-httpd-php .php" >>/etc/httpd/conf/httpd.conf 48.#sed -i "s/AddType\ application\/x-gzip\ \.gz\ \.tgz/AddType\ application\/x-gzip\ \.gz\ \.tgz\ AddType\ application\/x-httpd-php\ .php/g" /etc/httpd/conf/httpd.conf 49.#sed -i "s/DirectoryIndex\ index.html\ index.html.var/DirectoryIndex\ index.php\ index.html\ index.html.var/g" /etc/httpd/conf/httpd.conf 50. 51.#install cacti 52.function install_cacti { 53.cd ${path_soft} 54.[ ! -e cacti*.tar.gz ]; stats=$? 55.[ "$stats" == 0 ] && echo -e "${red} there is not cacti*.tar.gz file${NC}" && wget --no-check-certificate http://www.cacti.net/downloads/cacti-0.8.8a.tar.gz 56.tar zxvf cacti*.tar.gz 57.cp -rf cacti-0.8.8a /var/www/html/cacti 58.restorecon -R -v '/var/www/html/cacti' 59.chown apache.apache -R /var/www/html/cacti/ 60.sed -i "s/\$database_username\ =\ \"cactiuser\"/\$database_username\ =\ \"cacti\"/g" /var/www/html/cacti/include/config.php 61.sed -i "s/\$database_password\ =\ \"cactiuser\"/\$database_password\ =\ \"cacti123\"/g" /var/www/html/cacti/include/config.php62.63.#database password setting64.mysqladmin -uroot password 'itnihao'65.mysqladmin -uroot -pitnihao flush-privileges66.mysqladmin -uroot -pitnihao create cacti67.mysql -uroot -pitnihao cacti </var/www/html/cacti/cacti.sql68.mysql -uroot -pitnihao -e "grant all on cacti.* to cacti@localhost identified by 'cacti123'"69.mysql -uroot -pitnihao -e "FLUSH PRIVILEGES"70.71.#add crontab72.chmod 777 -R /var/www/html/cacti/rra73.chmod 777 -R /var/www/html/cacti/log74.echo "*/5 * * * * /usr/bin/php /var/www/html/cacti/poller.php > /dev/null 2&1" >/tmp/cron.cacti75.crontab -l|sort|uniq >> /tmp/cron.cacti76.crontab -uroot /tmp/cron.cacti && rm -rf /tmp/cron.cacti77.#setsebool -P httpd_unified=178.#chcon -t httpd_sys_content_t /usr/local/rrdtool -R79.echo -e "${green}++++++++++++++++++++++++cacti installed OK,path is http://ip/cacti++++++++++++++++++++${NC}" 80. 81.} 82.83.function plugin { 84.cd ${path_soft}/plugin 85.[ ! -e cacti-spine-0.8.8a.tar.gz ]; stats=$? 86.[ "$stats" == 0 ] && echo -e "${red} there is not cacti-spine*.tar.gz file${NC}" && wget --no-check-certificate http://www.cacti.net/downloads/spine/cacti-spine-0.8.8a.tar.gz 87.tar zxvf cacti-spine-0.8.8a.tar.gz 88.cd cacti-spine-0.8.8a 89../configure 90.make && make install 91.cd ../92.mv /usr/local/spine/etc/spine.conf.dist /usr/local/spine/etc/spine.conf 93.#wget http://docs.cacti.net/_media/plugin:docs-v0.4-1.tgz 94.#wget http://docs.cacti.net/_media/plugin:boost-v5.0-1.tgz 95.#wget http://docs.cacti.net/_media/plugin:discovery-v1.5-1.tgz 96.#wget http://docs.cacti.net/_media/plugin:monitor-v1.2-1.tgz 97.#wget http://docs.cacti.net/_media/plugin:monitor-v1.3-1.tgz 98.#wget http://docs.cacti.net/_media/plugin:mobile-latest.tgz 99.#wget http://docs.cacti.net/_media/plugin:settings-v0.7-1.tgz 100.#wget http://docs.cacti.net/_media/plugin:syslog-v1.22-2.tgz 101.#wget http://docs.cacti.net/_media/plugin:thold-v0.4.9-3.tgz 102.#wget http://docs.cacti.net/_media/plugin:clog-v1.7-1.tgz103.#wget http://docs.cacti.net/_media/plugin:ntop-v0.2-1.tgz 104.#wget http://docs.cacti.net/_media/plugin:domains-v0.1-1.tgz 105.#wget http://docs.cacti.net/_media/userplugin:manage-0.6.2.zip 106.#wget http://wotsit.thingy.com/haj/cacti/quicktree-0.2.zip 107.#wget http://www.network-weathermap.com/files/php-weathermap-0.97a.zip 108.#wget http://docs.cacti.net/_media/plugin:timeshift-latest.zip109.#wget http://docs.cacti.net/_media/plugin:loginmod-latest.tgz 110.#wget http://docs.cacti.net/_media/plugin:realtime-v0.5-2.tgz 111. 112. for name in `ls|sed -e "s/plugin://g" -e "s/.tgz//g"` 113. do 114. mv plugin:${name}.tgz ${name}.tar.gz 115. done 116. 117. for name1 in boost discovery docs domains loginmod-latest manage monitor quicktree realtime settings syslog thold timeshift weathermap 118. do 119. tar zxvf ${name1}*.tar.gz120. mv ${name1} /var/www/html/cacti/plugins/ 121. done 122. chown apache.apache -R /var/www/html/cacti/plugins 123.} 124.125.function config_apache { 126.cat >> /etc/httpd/conf/httpd.conf << EOF 127.Alias /cacti "/var/www/html/cacti" 128.<Directory "/var/www/html/cacti"> 129. Options -Indexes MultiViews -FollowSymLinks 130. DirectoryIndex index.php 131. AllowOverride None 132. Order allow,deny 133. Allow from all 134.</Directory> 135.<Directory /var/www/html/cacti/plugin/weathermap> 136. <Files editor.php> 137. Order Deny,Allow 138. Deny from all 139. Allow from 127.0.0.1 140. </Files> 141.</Directory> 142.EOF 143.} 144. 145.function syslog { 146.#syslog_mysql 147.yum install -y rsyslog rsyslog-mysql 148.cat >> /etc/rsyslog.conf << EOF 149.$ModLoad imudp.so 150.$UDPServerRun 514 151.$ModLoad ommysql 152.$template cacti_syslog,"INSERT INTO syslog_incoming(facility, priority, date, time, host, message) values (%syslogfacility%, 153.%syslogpriority%, '%timereported:::date-mysql%', '%timereported:::date-mysql%', '%HOSTNAME%', '%msg%')", SQL 154.*.* >localhost,syslog,cacti_log,cacti_log_pass;cacti_syslog 155.EOF 156.sed -i "s/SYSLOGD_OPTIONS=\"-c 4\"/SYSLOGD_OPTIONS=\"-c 4 -r -m 1\"/g" /etc/sysconfig/rsyslog 157.chkconfig rsyslog on 158.service rsyslog restart 159. 160.#syslog_database 161.mysqladmin -uroot -pitnihao create syslog 162.mysql -uroot -pitnihao syslog </var/www/html/cacti/plugins/syslog/syslog.sql 163.mysql -uroot -pitnihao -e "grant all on syslog.* to cacti_log@localhost identified by 'cacti_log_pass'"164.mysql -uroot -pitnihao -e "FLUSH PRIVILEGES" 165. 166.#cacti_syslog 167.sed -i "s/use_cacti_db = true;/use_cacti_db = false;/g" /var/www/html/cacti/plugins/syslog/config.php 168.sed -i "s/syslogdb_username = 'cactiuser'/syslogdb_username = 'cacti_log'/g" /var/www/html/cacti/plugins/syslog/config.php 169.sed -i "s/syslogdb_password = 'cactiuser'/syslogdb_password = 'cacti_log_pass'/g" /var/www/html/cacti/plugins/syslog/config.php 170.#client_syslog or rsyslog 171.#echo "*.* @192.168.16.200" >> /etc/syslog.conf 172.#echo "*.* @192.168.16.200" >> /etc/rsyslog.conf 173.} 174. 175.function syslog_ng { 176.service rsyslog stop 177.chkconfig --del rsyslog 178.service syslog stop 179.chkconfig --del syslog 180.cd ${path_soft}/syslog 181.182.#############################download#################################### 183.#wget wget http://dl.fedoraproject.org/pub/epel/6/x86_64/libnet-1.1.5-1.el6.x86_64.rpm 184.#wget http://dl.fedoraproject.org/pub/epel/6/x86_64/eventlog-0.2.12-1.el6.x86_64.rpm 185.#wget ftp://fr2.rpmfind.net/linux/epel/6/x86_64/syslog-ng-3.2.5-3.el6.x86_64.rpm 186.#wget http://dl.fedoraproject.org/pub/epel/6/x86_64/syslog-ng-libdbi-3.2.5-3.el6.x86_64.rpm 187.######################################################################## 188.rpm -ivh libnet-1.1.5-1.el6.x86_64.rpm 189.rpm -ivh eventlog-0.2.12-1.el6.x86_64.rpm 190.rpm -ivh syslog-ng-3.2.5-3.el6.x86_64.rpm 191.rpm -ivh libdbi-0.8.3-3.1.el6.x86_64.rpm 192.rpm -ivh syslog-ng-libdbi-3.2.5-3.el6.x86_64.rpm 193. 194.cat >> /etc/syslog-ng/syslog-ng.conf << EOF 195.source s_rsc { 196. unix-stream("/dev/log"); 197. udp(ip("192.168.16.200") port(514)); 198.}; 199.200.#destination r_mesg { file("/var/log/warn");}; 201. 202.destination d_mysql { 203. program("mysql -ucacti_log -pcacti_log_pass syslog < /var/log/mysql.pipe");204. pipe("/var/log/mysql.pipe" 205. template("INSERT INTO syslog_incoming (host, facility, priority, status, date, time, seq, message) VALUES( '\$FULLHOST', '\$FACILITY', '\$PRIORITY', '\$STATUS', '\$YEAR-\$MONTH-\$DAY', '\$HOUR:\$MIN:\$SEC','\$SEQ', '\$MESSAGE' );\n") 206. template-escape(yes)); 207.}; 208. 209.log { source(s_rsc); destination(d_mysql); }; 210.log { source(s_sys); destination(d_mysql); }; 211.EOF212.} 213. 214.function client_config { 215.#client syslog-ng,you should install syslog-ng 216.cat >> /etc/syslog-ng/syslog-ng.conf << EOF 217.destination d_udp {udp("192.168.16.200" port(514));}; 218.log { source(s_sys); destination(d_udp);}; 219.EOF 220. 221.#client_syslog or rsyslog 222.#rhel5.X use syslog 223.echo "*.* @192.168.16.200" >> /etc/syslog.conf 224.#rhel6.X use rsyslog 225.echo "*.* @192.168.16.200" >> /etc/rsyslog.conf 226. 227.#clietn snmpd configuration 228.sed -i s"/^/#/g" /etc/snmp/snmpd.conf 229.cat >> /etc/snmp/snmpd.conf << EOF 230.com2sec mynetwork 192.168.16.200 public 231.com2sec mynetwork 127.0.0.1 public 232.group MyROGroup v2c mynetwork 233.access MyROGroup "" any noauth prefix all none none 234.view all included .1 80 235.EOF 236.} 237. 238.function main { 239.base 240.lamp 241.install_cacti 242.plugin 243.config_apache 244.syslog 245.#syslog_ng 246.#client_config 247.} 248. 249.main
以上是小编为您精心准备的的内容,在的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索http
, conf
, media
, wget
, cacti
, plugin
ng1.3+
cacti一键安装中文版、cacti一键安装、nagios cacti一键安装、openvpn一键安装脚本、ss一键安装脚本,以便于您获取更多的相关知识。
时间: 2024-11-05 14:48:10