自动化安装Cacti(1.0.1/2/3)脚本

举报
kaliarch 发表于 2022/03/12 10:00:54 2022/03/12
【摘要】 ​​自动化安装Cacti(1.0.1/2/3)脚本​​​​一、目的​​​1.1 监控目的​​目前我们已经有zabbix监控系统,但是有客户需求需要流量报表,因此应此类客户的需求,部署Cacti流量监控系统,来监控客户服务器或交换机端口,为客户提供流量报表截图。​​1.2 本文目的​​快速部署Cacti流量监控系统,为后期相关工程师部署此系统提供借鉴与参考。​​​二、理论基础​​​2.1 相关...

自动化安装Cacti(1.0.1/2/3)脚本

一、目的

1.1 监控目的

目前我们已经有zabbix监控系统,但是有客户需求需要流量报表,因此应此类客户的需求,部署Cacti流量监控系统,来监控客户服务器或交换机端口,为客户提供流量报表截图。

1.2 本文目的

快速部署Cacti流量监控系统,为后期相关工程师部署此系统提供借鉴与参考。

二、理论基础

2.1 相关理论

Cacti是用php语言实现一套基于PHP,MySQL,SNMP及RRDTool开发的网络流量监测图形分析工具snmp服务获取数据,然后用rrdtool​​储存和更新数据,当用户需要查看数据的时候用rrdtool​​生成图表呈现给用户。

2.2 拓扑架构


​github地址​

#!/bin/bash
#Date 2017/2/14
#mail xuel@51idc.com
[ $(id -u) != "0" ] && echo "Error: You must be root to run this script" && exit 1
export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
sed -i "s/SELINUX=enforcing/SELINUX=disabled/"  /etc/selinux/config
setenforce 0
which  ntpdate
if [ $? -eq 0 ];then
    /usr/sbin/ntpdate time1.aliyun.com
    echo "*/5 * * * * /usr/sbin/ntpdate -s time1.aliyun.com">>/var/spool/cron/root  
else
    yum install ntpdate -y
    /usr/sbin/ntpdate time1.aliyun.com
    echo "*/5 * * * * /usr/sbin/ntpdate -s time1.aliyun.com">>/var/spool/cron/root  
fi
clear
echo "####################################################"
echo "#       Auto Install Cacti.                       ##"
echo "#       Press Ctrl + C to cancel                  ##"
echo "#       Any key to continue                       ##"
echo "####################################################"
echo "(1) Install Cacti-1.0.1"
echo "(2) Install Cacti-1.0.2"
echo "(3)Install  Cacti-1.0.3"
echo "(4) EXIT"
read -p "Please input your choice:" NUM
case $NUM in 
1)
    URL="http://www.cacti.net/downloads/cacti-1.0.1.tar.gz"
    VER=cacti-1.0.1
;;
2)
    URL="http://www.cacti.net/downloads/cacti-1.0.2.tar.gz"
    VER=cacti-1.0.2
;;
3)
    URL="http://www.cacti.net/downloads/cacti-1.0.3.tar.gz"
    VER=cacti-1.0.3
;;
4)
    echo -e "\033[41;37m You choice channel! \033[0m" && exit 0
;;
*)
    echo -e "\033[41;37m Input Error! Place input{1|2|3} \033[0m" && exit 1
;;
esac
clear
echo -e "\033[32m You choice install $VER.Install\033[0m"
echo -e "\033[5m Press any key to start install $VER... \033[0m"
read -n 1
################################################################
TDIR=/tools
IP=`ifconfig eth0 | grep "inet addr" | awk -F"[: ]+" '{print $4}'`
yum remove php* -y
rpm -Uvh http://mirror.webtatic.com/yum/el6/latest.rpm
ls /etc/yum.repos.d/webtatic.repo
if [ $? -eq 0 ];then
    yum -y install `yum list|grep php55w|awk '{printf ("%s ",$1)}'` --skip-broken
fi
service php-fpm start /tmp/php-install.log 2>&1
STAT=`echo $?`
PORT=`netstat -lntup|grep php-fpm|wc -l`
if [ $STAT -eq 0 ] && [ $PORT -eq 1 ];then
    echo -e "\033[32m PHP is install success! \033[0m"
else
    echo -e "\033[32m PHP install file.please check /tmp/php-install.log \033[0m"
fi
############################################################
yum install httpd net-snmp net-snmp-devel net-snmp-utils rrdtool -y
if [ -d /var/www/html ];then
    cd /var/www/html
else
    mkdir -p /var/www/html && cd /var/www/html
fi
wget -c -O /var/www/html/$VER.tar.gz  http://www.cacti.net/downloads/$VER.tar.gz
tar -zxvf $VER.tar.gz
mv $VER cacti
cd cacti
chown -R apache.root *
useradd cacti
echo "cacti" | passwd --stdin cacti
echo "*/1 * * * * /usr/bin/php /var/www/html/cacti/poller.php >/dev/null 2>&1">>/var/spool/cron/root
service httpd start 
chkconfig httpd on 
###################################################################
SNMPFILE=/etc/snmp/snmpd.conf
if [ -f "$SNMPFILE" ]
        then
        cp $SNMPFILE /etc/snmp/snmpd.conf.bak
fi
cat > $SNMPFILE << EOF
com2sec notConfigUser  default       public
group   notConfigGroup v1           notConfigUser
group   notConfigGroup v2c           notConfigUser
view    systemview    included   .1
view    systemview    included   .1.3.6.1.2.1.1
view    systemview    included   .1.3.6.1.2.1.25.1.1
access  notConfigGroup ""      any       noauth    exact  all  none none
view all    included  .1                               80
syslocation Unknown (edit /etc/snmp/snmpd.conf)
syscontact Root <root@localhost> (configure /etc/snmp/snmp.local.conf)
dontLogTCPWrappersConnects yes
proc mountd
proc ntalkd 4
nstall httpd mysql-server php php-mysql php-snmp mysql-devel httpd-devel net-snmp net-snmp-devel
 net-snmp-utils rrdtoolproc senmail 10 1
exec echotest /bin/echo hello world
disk / 10000
EOF
###############################################################
rpm -ivh http://repo.mysql.com//mysql57-community-release-el6-8.noarch.rpm
if [ -d /scripts ];then
    cd /scripts
else
    /bin/mkdir /scripts && cd /scripts
fi
wget -r -np -nd -l1 -A.rpm http://101.227.67.205/share/MySQL5.7/
yum install mysql-community* -y
chkconfig mysqld on
service mysqld start
SQLPWD=`grep 'temporary password' /var/log/mysqld.log|cut -d" " -f11|sed s/[[:space:]]//g`
SQLNEW="WWW.51idc.com"
echo $SQLNEW
mysql -uroot "-p$SQLPWD" --connect-expired-password -e "alter user 'root'@'localhost' identified by \""$SQLNEW"\";"
mysql -uroot "-p$SQLNEW" -e "create database cacti character set utf8;"
mysql -uroot "-p$SQLNEW" cacti</var/www/html/cacti/cacti.sql
mysql -uroot "-p$SQLNEW" -e "CREATE USER 'cacti'@'localhost' IDENTIFIEDBY \""$SQLNEW"\";"
mysql -uroot "-p$SQLNEW" -e "grant all privileges on cacti.* to cacti@'localhost' identified by \""$SQLNEW"\";"
mysql -uroot "-p$SQLNEW" -e "grant select on mysql.time_zone_name to 'cacti'@'localhost';"
mysql -uroot "-p$SQLNEW" -e "flush privileges;"
/usr/bin/mysql_tzinfo_to_sql /usr/share/zoneinfo|mysql -uroot -p"$SQLNEW" mysql
cat>>/etc/my.cnf<<EOF
max_heap_table_size=100M
max_allowed_packet=16777216
tmp_table_size=64M
join_buffer_size=64M
innodb_buffer_pool_size=458M
innodb_doublewrite=OFF
innodb_flush_log_at_timeout=4
innodb_read_io_threads=32
innodb_write_io_threads=16
EOF
PHPCONF=/var/www/html/cacti/include/config.php
if [ -f $PHPCONF ];then
cat >$PHPCONF<<EOF
<?php
\$database_type = "mysql";
\$database_default = "cacti";
\$database_hostname = "localhost";
\$database_username = "cacti";
\$database_password = "$SQLNEW";
\$database_port = "3306";
?>
EOF
fi
clear
service mysqld restart
#############################################################
/etc/init.d/iptables status >/dev/null 2>&1
if [ $? -eq 0 ];then
    iptables -I INPUT -p tcp --dport 80 -j ACCEPT &&
#iptables -I INPUT -p tcp --dport 3306 -j ACCEPT && 
    service iptables save >/dev/null 2>&1
    /etc/init.d/iptables restart
else
    echo -e "\033[32m iptables is stopd\033[0m"
fi
clear
echo -e "\033[42;37m MySql Username:root Password:$SQLNEW \033[0m"
echo -e "\033[42;37m URL:http://$IP/cacti \033[0m"
echo -e "\033[42;37m $VER is Install Success,Username:Admin Password:admin \033[0m"

【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。