centos7一键安装cacti_1.2.16版本

#!/bin/bash
#hanzb自学一键搭建cacti
#本安装方案适合centos7版本,采用LAMP。
#把脚本放置到系统里面,需要chmod +x 脚本名  赋予权限,然后bash 脚本即可或者./脚本

cd
setenforce 0         
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux  
yum install wget -y
yum install ntpdate -y  
systemctl start ntpdate 
systemctl enable ntpdate
ntpdate ntp1.aliyun.com
echo "59 23 * * *    ntpdate ntp1.aliyun.com" > /var/spool/cron/root
yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm -y
yum install yum-utils -y
yum-config-manager --enable remi-php72
yum install -y httpd
systemctl start httpd
systemctl enable httpd
systemctl stop firewalld
systemctl disable firewalld
touch /etc/httpd/conf.d/cacti.conf
cat <<EOF> /etc/httpd/conf.d/cacti.conf
<VirtualHost *:443>
        DocumentRoot "/var/www/html/cacti"
        Alias /cacti    /var/www/html/cacti
        <Directory /var/www/html/cacti/>
                <IfModule mod_authz_core.c>
                        Allow from all
                        Require all granted
                </IfModule>
        </Directory>
</VirtualHost>
EOF
yum install -y php php-common php-bcmath php-cli \
php-mysqlnd php-gd php-gmp php-intl \
php-json php-ldap php-mbstring \
php-pdo php-pear php-snmp php-process \
php-xml php-zip
sed -i 's/;date.timezone =/date.timezone = Asia\/shanghai/g' /etc/php.ini
sed -i 's/memory_limit = 128M/memory_limit = 800M/g' /etc/php.ini
sed -i 's/max_execution_time = 30/max_execution_time = 60/g' /etc/php.ini
yum install -y rrdtool
yum install -y net-snmp net-snmp-utils
mv autocacti/cacti-latest.tar.gz /tmp/
cd /tmp
#此处因为我自己已经提前下载好包,所以注释掉了wget,没有下载的可以去掉#。
#wget https://www.cacti.net/downloads/cacti-latest.tar.gz
tar -zxvf cacti-latest.tar.gz
mv -v cacti-1.2.16 /var/www/html/cacti
chown -R apache:apache /var/www/html/
cd
#下一步有些版本不需要,可能会报错,但是不会影响结果。
#mv -v /var/www/html/cacti/include/config.php-dist /var/www/html/cacti/include/config.php  2>/dev/null
sed -i "s/\$database_username = 'cactiuser';/\$database_username = 'cacti';/g" /var/www/html/cacti/include/config.php
sed -i "s/\$database_password = 'cactiuser';/\$database_password = 'cacti';/g" /var/www/html/cacti/include/config.php
#从Cacti 1.2.16开始,您可以选择使用传统的Crontab条目,或者使用可选的cactid单位文件和服务器来运行您的Cacti轮询器。
cat <<EOF> /etc/cron.d/cacti
*/5 * * * * apache php /var/www/html/cacti/poller.php &>/dev/null
EOF
touch /etc/sysconfig/cactid
cp -p /var/www/html/cacti/service/cactid.service /etc/systemd/system
systemctl enable cactid
systemctl start cactid
systemctl status cactid
yum install -y autoconf automake libtool dos2unix help2man openssl-devel mariadb-devel net-snmp-devel
openssl-devel mariadb-devel net-snmp-devel

mv autocacti/cacti-spine-latest.tar.gz /tmp/
cd /tmp
#此处因为我自己已经提前下载好包,所以注释掉了wget,没有下载的可以去掉#。
#wget https://www.cacti.net/downloads/spine/cacti-spine-latest.tar.gz
tar -zxvf cacti-spine-latest.tar.gz
cd cacti-spine-1.2.16/
./bootstrap
./configure --with-reentrant
make
make install
chown root:root /usr/local/spine/bin/spine
chmod +s /usr/local/spine/bin/spine
mv -v /usr/local/spine/etc/spine.conf.dist /usr/local/spine/etc/spine.conf
sed -i "s/DB_User       cactiuser/DB_User       cacti/g" /usr/local/spine/etc/spine.conf
sed -i "s/DB_Pass       cactiuser/\DB_Pass       cacti/g" /usr/local/spine/etc/spine.conf
cat << EOF >/etc/yum.repos.d/MariaDB.repo
[mariadb]
name = MariaDB
baseurl = http://mirrors.aliyun.com/mariadb/yum/10.1/centos7-amd64/
gpgkey =  http://mirrors.aliyun.com/mariadb/yum/RPM-GPG-KEY-MariaDB
gpgcheck = 1
EOF
cd

#初始化mariadb密码为123456.创建数据库cacti,账号密码同为cacti。
yum -y install MariaDB-server MariaDB-client 
systemctl enable mariadb
systemctl start mariadb
echo -e "\ny\n123456\n123456\ny\nn\ny\ny\n" | /usr/bin/mysql_secure_installation
mysql_tzinfo_to_sql /usr/share/zoneinfo/ | mysql -uroot -p123456 mysql
mysql -uroot -p123456 -e 'create database if not exists cacti;use cacti; source /var/www/html/cacti/cacti.sql;' 
mysql -e "CREATE USER 'cacti'@'localhost' IDENTIFIED BY 'cacti';" -uroot -p123456
mysql -e "GRANT ALL PRIVILEGES ON cacti.* TO 'cacti'@'localhost';"  -uroot -p123456
mysql -e "GRANT SELECT ON mysql.time_zone_name TO 'cacti'@'localhost';" -uroot -p123456
mysql -e 'ALTER DATABASE cacti CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;' -uroot -p123456
mysql -e 'FLUSH PRIVILEGES;' -uroot -p123456
#mysql -ucacti -pcacti  cacti --default-character-set=utf8 < /var/www/html/cacti/cacti.sql

cat <<EOF>>/etc/my.cnf.d/server.cnf
character_set_serve =utf8mb4
character_set_clien =utf8mb4
max_allowed_packe=16777216
tmp_table_size=60M
join_buffer_size=120M
innodb_file_format=Barracuda
innodb_large_prefix=1
innodb_buffer_pool_size=1000M
innodb_additional_mem_pool_size=80M
innodb_flush_log_at_timeout=3
innodb_read_io_threads=32
innodb_write_io_threads=16
innodb_io_capacity=5000
innodb_io_capacity_max=10000
max_heap_table_size=60M
collation_server=utf8mb4_unicode_ci
log-error                      = /var/log/mysql/mysql-error.log
log-queries-not-using-indexes  = 1
slow-query-log                 = 1
slow-query-log-file            = /var/log/mysql/mysql-slow.log
EOF
systemctl restart httpd
systemctl restart mariadb
#插件包我也提前下载好了,没有下载的可以去官网下载 #安装插件 cd
/root/autocacti tar -zxvf plugin_cycle-4.1.tar.gz tar -zxvf plugin_monitor-2.5.tar.gz tar -zxvf plugin_syslog-3.1.tar.gz tar -zxvf plugin_thold-1.5.2.tar.gz mv -v plugin_cycle-4.1 /var/www/html/cacti/plugins/cycle mv -v plugin_monitor-2.5 /var/www/html/cacti/plugins/monitor mv -v plugin_syslog-3.1 /var/www/html/cacti/plugins/syslog mv -v plugin_thold-1.5.2 /var/www/html/cacti/plugins/thold mv -v /var/www/html/cacti/plugins/syslog/config.php.dist /var/www/html/cacti/plugins/syslog/config.php cd

 

posted @ 2021-01-22 09:20  韩邯  阅读(1279)  评论(0编辑  收藏  举报