Cacti one-click installation Script V1.1

Source: Internet
Author: User
Tags chmod config flush gz file openssl snmp syslog rsyslog
01.#!/bin/bash
#function +++++++++++++cacti Auto Install scripts+++++++++++++++++++
#author Itnihao
#version 1.1
#date 2012-08-17 v1.0
#date 2012-08-18 v1.1 Update add syslog-ng content
#mail itnihao@qq.com
#www. bianceng.cn
#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 {
#rpm-E lrzsz&& yum-y Install lrzsz*
#["$?"!= "0"] && echo "Yum is badly,please check" && exit 1
For I in $ (rpm-q gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 li Bxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel Curl curl-devel E2 Fsprogs e2fsprogs-devel krb5-devel libidn libidn-devel OpenSSL openssl-devel bison bison-devel ReadLine readline-devel Li Libmcrypt-devel net-snmp-devel gcc gcc-c++ Apr apr-util postgresql-libs OpenSSL openssl-devel autoconf bmcrypt automake fiex* libxml* ncurses* libtool* libxslt libxslt-devel curl* bzip2* gd gd-devel freetype freetype-devel ' not Installed ' | awk ' {print $} ')
Do
Yum-y install $i;
Done
25.}
26.
27.
28.function Lamp {
29.yum-y install httpd mysql-server mysql php* net-snmp* rrdtool*
30.sed-i "s/;d ate.timezone =/date.timezone = asia\/chongqing/g"/etc/php.ini
#start Lamp Services
32.for name in httpd mysqld snmpd
A. Do
Service ${name} restart
Chkconfig--add ${name}
Chkconfig--level 345 ${name} on
It's done.
38.for name1 in Nfslock rpcbind
Do
Service ${name1} stop
Chkconfig--del ${name1}
Done.
Echo-e "<?php\nphpinfo ();\n?>" >/var/www/html/test.php
44.}
#add Php_type
#echo "AddType application/x-httpd-php. php" >>/etc/httpd/conf/httpd.conf
#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
#sed-i "s/directoryindex\ index.html\ index.html.var/directoryindex\ index.php\ index.html\ index.html.var/g"/etc /httpd/conf/httpd.conf
50.
#install cacti.
52.function Install_cacti {
53.CD ${path_soft}
54.[!-e cacti*.tar.gz]; Stats=$?
55.["$stats" = = 0] && echo-e "${red} There are not cacti*.tar.gz file${nc}" && wget--no-check-certifica Te 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.php
62.
#database Password setting
64.mysqladmin-uroot password ' Itnihao '
65.mysqladmin-uroot-pitnihao flush-privileges
66.mysqladmin-uroot-pitnihao Create cacti
67.mysql-uroot-pitnihao Cacti </var/www/html/cacti/cacti.sql
68.MYSQL-UROOT-PITNIHAO-E "Grant all on cacti.* to cacti@localhost identified by ' cacti123 '"
69.mysql-uroot-pitnihao-e "FLUSH Privileges"
70.
#add crontab.
72.chmod 777-r/var/www/html/cacti/rra
73.chmod 777-r/var/www/html/cacti/log
74.echo "*/5 * * * */usr/bin/php/var/www/html/cacti/poller.php >/dev/null 2&1" >/tmp/cron.cacti
75.crontab-l|sort|uniq >>/tmp/cron.cacti
76.crontab-uroot/tmp/cron.cacti && Rm-rf/tmp/cron.cacti
#setsebool-P httpd_unified=1
#chcon-T Httpd_sys_content_t/usr/local/rrdtool-r
79.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 are not cacti-spine*.tar.gz file${nc}" && wget--no-check-cer Tificate 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
#wget http://docs.cacti.net/_media/plugin:docs-v0.4-1.tgz.
#wget http://docs.cacti.net/_media/plugin:boost-v5.0-1.tgz.
#wget http://docs.cacti.net/_media/plugin:discovery-v1.5-1.tgz.
#wget http://docs.cacti.net/_media/plugin:monitor-v1.2-1.tgz.
#wget http://docs.cacti.net/_media/plugin:monitor-v1.3-1.tgz.
#wget http://docs.cacti.net/_media/plugin:mobile-latest.tgz
#wget http://docs.cacti.net/_media/plugin:settings-v0.7-1.tgz.
#wget http://docs.cacti.net/_media/plugin:syslog-v1.22-2.tgz
#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.tgz
#wget http://docs.cacti.net/_media/plugin:ntop-v0.2-1.tgz.
#wget http://docs.cacti.net/_media/plugin:domains-v0.1-1.tgz
#wget Http://docs.cacti.net/_media/userplugin:manage-0.6.2.zip
#wget Http://wotsit.thingy.com/haj/cacti/quicktree-0.2.zip.
#wget Http://www.network-weathermap.com/files/php-weathermap-0.97a.zip
108. #wget Http://docs.cacti.net/_media/plugin:timeshift-latest.zip
109. #wget Http://docs.cacti.net/_media/plugin:loginmod-latest.tgz
#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
A. Done
116.
117. For name1 in Boost discovery docs domains loginmod-latest Manage monitor Quicktree realtime settings syslog thold ti Meshift Weathermap
118. Do
119. Tar zxvf ${name1}*.tar.gz
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
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
$UDPServerRun 514
151. $ModLoad Ommysql
152. $template Cacti_syslog, INSERT into syslog_incoming (facility, priority, date, time, host, message) values (% syslogfacility%,
153.%syslogpriority%, '%timereported:::d ate-mysql% ', '%timereported:::d ate-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.
#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.EOF
212.}
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.
#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.
Public
231.com2sec mynetwork 127.0.0.1 Public
232.group Myrogroup v2c mynetwork
233.access myrogroup "" Any noauth prefix 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.