博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
CentOS 一键安装Cacti 1.2.3脚本
阅读量:4041 次
发布时间:2019-05-24

本文共 9050 字,大约阅读时间需要 30 分钟。

CentOS 一键安装Cacti 1.2.3脚本

转自:https://blog.51cto.com/11434894/2396817?source=dra

#!/bin/bash

echo “this script requires git”

yum install -y git

echo “This script will download all Cacti dependecies and download the chosen cacti version from the cacti github”

echo “Dont forget to support cacti @ cacti.net!”

echo “set selinux to disabled”

setenforce 0
sed -i ‘s/enforcing/disabled/g’ /etc/selinux/config /etc/selinux/config

#Download chosen release

echo "here are some of the current cacti release versions \n
release/1.2.3
release/1.2.2
release/1.2.1
release/1.2.0
"

echo “which release would you like to download ? Hit enter for latest”

read version

if [ “$version” == “” ]

then
git clone https://github.com/Cacti/cacti.git

else

yum install -y wget unzip
wget https://github.com/Cacti/cacti/archive/release/$version.zip
unzip v e r s i o n m v c a c t i − r e l e a s e − version mv cacti-release- versionmvcactireleaseversion cacti
fi

echo “will you be using the spine poller enter 1 for yes 2 for no”

read answer
if [ $answer == “1” ]
then
##Download packages needed for spine
yum install -y gcc mysql-devel net-snmp-devel autoconf automake libtool dos2unix help2man
echo “downloading and compling spine”
git clone https://github.com/Cacti/spine.git
cd spine
./bootstrap
./configure
make
make install
chown root:root /usr/local/spine/bin/spine
chmod u+s /usr/local/spine/bin/spine
cd …

else

echo “spine dependecies will not be installed”
fi

echo “On Centos systems we need to enable EPEL repos”

yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm -y
yum install yum-utils -y
yum-config-manager --enable remi-php72

echo “Downloading PHP modules needed for Cacti install”

yum install -y rrdtool mariadb-server net-snmp-utils net-snmp snmpd php php-mysql php-snmp php-xml php-mbstring php-json php-gd php-gmp php-zip php-ldap php-mc php-posix

###Start services

systemctl enable httpd

systemctl enable mariadb
systemctl start mariadb
systemctl start httpd

####Open Port 80 and 443 on firewalld

echo “Open http and https ports on firewalld”

firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --zone=public --add-port=443/tcp --permanent
firewall-cmd --reload

##Timezone settings needed for cacti

echo "Enter your PHP time zone i.e America/Toronto Default is US/Central "
read timezone
if [ $timezone == “” ]
then

echo “date.timezone =” US/Central >> /etc/php.ini

else

echo “date.timezone =” $timezone >> /etc/php.ini

fi

echo “Where would you like to install cacti default location is /var/www/html hit enter for default location”

read location
if [$location = “”]
then

location="/var/www/html"

mv cacti /var/www/html

else
mv cacti $location
fi

#Create cacti user and change permission of directory

echo “Which user would you like to run Cacti under (Default is www-data) hit enter for default”
read user
if [$user = “”]
then
user=“apache”
echo “cacti will be run under apache”
chown -R apache:apache $location/cacti
else
useradd $user
chown -R u s e r : user: user:user $location/cacti
fi

#assign permissions for cacti installation

chown -R apache:apache $location/cacti/resource/snmp_queries/

chown -R apache:apache $location/cacti/resource/script_server/
chown -R apache:apache $location/cacti/resource/script_queries/
chown -R apache:apache $location/cacti/scripts/
chown -R apache:apache $location/cacti/cache/boost/
chown -R apache:apache $location/cacti/cache/mibcache/
chown -R apache:apache $location/cacti/cache/realtime/
chown -R apache:apache $location/cacti/cache/spikekill/
touch $location/cacti/log/cacti.log
chmod 777 $location/cacti/log/cacti.log
chown -R apache:apache $location/cacti/log/
cp $location/cacti/include/config.php.dist $location/cacti/include/config.php

##Create database

echo “would you like to customize the database name and user ? hit enter for defaults”
read customize

if [[ $customize = “” ]]

then

mysql -uroot <<MYSQL_SCRIPT

CREATE DATABASE cacti DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
GRANT ALL PRIVILEGES ON cacti.* TO ‘cacti’@‘localhost’ IDENTIFIED BY ‘cacti’; ;
GRANT SELECT ON mysql.time_zone_name TO cacti@localhost;
USE mysql;
ALTER DATABASE cacti CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
FLUSH PRIVILEGES;
MYSQL_SCRIPT

#pre populate cacti db

mysql -u root cacti < $location/cacti/cacti.sql
mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root mysql

sed -i -e ‘s@^ d a t a b a s e t y p e . ∗ @ database_type.*@ databasetype.@database_type = “mysql”;@g’ /var/www/html/cacti/include/config.php

sed -i -e ‘s@^ d a t a b a s e d e f a u l t . ∗ @ database_default.*@ databasedefault.@database_default = “cacti”;@g’ /var/www/html/cacti/include/config.php
sed -i -e ‘s@^ d a t a b a s e h o s t n a m e . ∗ @ database_hostname.*@ databasehostname.@database_hostname = “127.0.0.1”;@g’ /var/www/html/cacti/include/config.php
sed -i -e ‘s@^ d a t a b a s e u s e r n a m e . ∗ @ database_username.*@ databaseusername.@database_username = “cacti”;@g’ /var/www/html/cacti/include/config.php
sed -i -e ‘s@^ d a t a b a s e p a s s w o r d . ∗ @ database_password.*@ databasepassword.@database_password = “cacti”;@g’ /var/www/html/cacti/include/config.php
sed -i -e ‘s@^ d a t a b a s e p o r t . ∗ @ database_port.*@ databaseport.@database_port = “3306”;@g’ /var/www/html/cacti/include/config.php
sed -i -e ‘s@^ d a t a b a s e s s l . ∗ @ database_ssl.*@ databasessl.@database_ssl = “false”;@g’ /var/www/html/cacti/include/config.php
sed -i -e ‘s@^// u r l p a t h @ url_path@ urlpath@url_path@g’ /var/www/html/cacti/include/config.php

echo “default database setup with following details”

echo “database name cacti\n
database username cacti\n
database password cacti”

else

echo “enter db name”

read customdbname
echo “enter db user”
read customdbuser
echo “enter db password”
read customdbpassword

mysql -u root <<MYSQL_SCRIPT

CREATE DATABASE $customdbname;
GRANT ALL PRIVILEGES ON c u s t o m d b n a m e . ∗ T O ′ customdbname.* TO ' customdbname.TOcustomdbuser’@‘localhost’ IDENTIFIED BY ‘$customdbpassword’;
GRANT SELECT ON mysql.time_zone_name TO $customdbuser@localhost;
ALTER DATABASE $customdbname CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
FLUSH PRIVILEGES;
MYSQL_SCRIPT

echo “Pre-populating cacti DB”

mysql -u root $customdbname < $location/cacti/cacti.sql
mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root mysql

sed -i -e ‘s@^ d a t a b a s e t y p e . ∗ @ database_type.*@ databasetype.@database_type = “mysql”;@g’ KaTeX parse error: Expected group after '^' at position 48: …p sed -i -e 's@^̲database_default.@ d a t a b a s e d e f a u l t = ′ database_default = ' databasedefault=customdbname’;@g’ KaTeX parse error: Expected group after '^' at position 48: …p sed -i -e 's@^̲database_hostname.@$database_hostname = “127.0.0.1”;@g’ KaTeX parse error: Expected group after '^' at position 48: …p sed -i -e 's@^̲database_username.@ d a t a b a s e u s e r n a m e = ′ database_username = ' databaseusername=customdbuser’;@g’ KaTeX parse error: Expected group after '^' at position 48: …p sed -i -e 's@^̲database_password.@ d a t a b a s e p a s s w o r d = ′ database_password = ' databasepassword=customdbpassword’;@g’ KaTeX parse error: Expected group after '^' at position 48: …p sed -i -e 's@^̲database_port.*@ d a t a b a s e p o r t = " 3306 " ; @ g ′ " database_port = "3306";@g' " databaseport="3306";@g"location"/cacti/include/config.php

sed -i -e ‘s@^ d a t a b a s e s s l . ∗ @ database_ssl.*@ databasessl.@database_ssl = “false”;@g’ " l o c a t i o n " / c a c t i / i n c l u d e / c o n f i g . p h p s e d − i − e ′ s @ / / location"/cacti/include/config.php sed -i -e 's@^// location"/cacti/include/config.phpsedies@//url_path@$url_path@g’ $location/cacti/include/config.php

fi

###Adding recomended PHP settings

sed -e ‘s/max_execution_time = 30/max_execution_time = 60/’ -i /etc/php.ini
sed -e ‘s/memory_limit = 128M/memory_limit = 400M/’ -i /etc/php.ini

echo “Applying recommended DB settings”

echo "
innodb_file_format = Barracuda
character_set_client = utf8mb4
max_allowed_packet = 16777777
join_buffer_size = 32M
innodb_file_per_table = ON
innodb_large_prefix = 1
innodb_buffer_pool_size = 250M
innodb_additional_mem_pool_size = 90M
innodb_flush_log_at_trx_commit = 2
" >> /etc/my.cnf.d/server.cnf

echo “this script can download the following plugins monitor,thold would you like to install them ?

type yes to download hit enter to skip”
read plugins
if [ $plugins == “yes” ]
then
git clone https://github.com/Cacti/plugin_thold.git
git clone https://github.com/Cacti/plugin_monitor.git
mv plugin_thold thold
mv plugin_monitor monitor
chown -R u s e r : user: user:user thold
chown -R u s e r : user: user:user monitor
mv thold $location/cacti/plugins
mv monitor $location/cacti/plugins
else
echo “plugins will not be installed”
fi

touch /etc/cron.d/$user

echo "*/5 * * * * $user php KaTeX parse error: Expected 'EOF', got '&' at position 41: … > /dev/null 2>&̲1" > /etc/cron.…user

echo “refreshing services”

systemctl restart httpd
systemctl restart mariadb

echo “Installation completed !”

转载地址:http://hnodi.baihongyu.com/

你可能感兴趣的文章
Android系统构架
查看>>
Android 跨应用程序访问窗口知识点总结
查看>>
各种排序算法的分析及java实现
查看>>
SSH框架总结(框架分析+环境搭建+实例源码下载)
查看>>
js弹窗插件
查看>>
自定义 select 下拉框 多选插件
查看>>
js判断数组内是否有重复值
查看>>
js获取url链接携带的参数值
查看>>
gdb 调试core dump
查看>>
gdb debug tips
查看>>
arm linux 生成火焰图
查看>>
linux和windows内存布局验证
查看>>
linux insmod error -1 required key invalid
查看>>
linux kconfig配置
查看>>
linux不同模块completion通信
查看>>
linux printf获得时间戳
查看>>
C语言位扩展
查看>>
linux dump_backtrace
查看>>
linux irqdebug
查看>>
git 常用命令
查看>>