no time to ...
maybe sometime will release.
hope it can help somebody to save deploy time.
Code: Select all
#!/bin/sh
# config the yum for local mirror site (china local site)
cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
sed -i 's/^#baseurl/baseurl/g' /etc/yum.repos.d/CentOS-Base.repo
sed -i '/^mirrorlist/d' /etc/yum.repos.d/CentOS-Base.repo
sed -i 's/mirror.centos.org/mirrors.163.com/g' /etc/yum.repos.d/CentOS-Base.repo
yum clean all
yum check-update
# yum makecache
yum update -y
yum install vim wget -y
# disable selinux
sed -i '/^SELINUX=enforcing/a\SELINUX=disabled' /etc/selinux/config
sed -i 's/^SELINUX=enforcing/# SELINUX=enforcing/g' /etc/selinux/config
setenforce 0
# install mysql community server
cat > /etc/yum.repos.d/mysql-community.repo <<EOF
[mysql56-community]
name=MySQL 5.6 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/\$releasever/\$basearch/
enabled=1
gpgcheck=0
EOF
yum install mysql-community-server -y
systemctl enable mysqld.service
systemctl start mysqld.service
# mysql_secure_installation
mysqladmin -u root password dbadmin
# install nginx
cat > /etc/yum.repos.d/nginx.repo <<EOF
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/\$basearch/
gpgcheck=0
enabled=1
EOF
yum install nginx -y
systemctl enable nginx.service
systemctl start nginx.service
firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --reload
# install php-pfm
yum install -y php-fpm php-common php-cli php-gd php-ldap php-posix php-mbstring php-mysql php-snmp net-snmp net-snmp-utils openssl rrdtool
sed -i '/^;date.timezone/a\date.timezone = PRC' /etc/php.ini
sed -i '/^listen = 127.0.0.1:9000/a\listen = \/var\/run\/php-fpm\/php-fpm.sock' /etc/php-fpm.d/www.conf
sed -i 's/^listen = 127.0.0.1:9000/# listen = 127.0.0.1:9000/g' /etc/php-fpm.d/www.conf
if [ ! /var/run/php-fpm/php-fpm.sock ]; then
touch /var/run/php-fpm/php-fpm.sock
fi
chown -R apache:apache /var/run/php-fpm/php-fpm.sock
mkdir -p /var/lib/php/session
chown -R apache:apache /var/lib/php/session
systemctl enable php-fpm.service
systemctl start php-fpm.service
sed -i 's/index index.html index.htm/index index.php index.html index.htm/g' /etc/nginx/conf.d/default.conf
sed -i '/deny access/i\ # pass the PHP scripts to FastCGI server listening on unix socket' /etc/nginx/conf.d/default.conf
sed -i '/deny access/i\ #' /etc/nginx/conf.d/default.conf
sed -i '/deny access/i\ location ~ \.php$ {' /etc/nginx/conf.d/default.conf
sed -i '/deny access/i\ root /usr/share/nginx/html;' /etc/nginx/conf.d/default.conf
sed -i '/deny access/i\ fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;' /etc/nginx/conf.d/default.conf
sed -i '/deny access/i\ fastcgi_index index.php;' /etc/nginx/conf.d/default.conf
sed -i '/deny access/i\ fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;' /etc/nginx/conf.d/default.conf
sed -i '/deny access/i\ include fastcgi_params;' /etc/nginx/conf.d/default.conf
sed -i '/deny access/i\ }' /etc/nginx/conf.d/default.conf
sed -i '/deny access/i\ ' /etc/nginx/conf.d/default.conf
systemctl restart php-fpm.service
systemctl restart nginx.service
# install spine
mkdir /usr/src/cacti
cd /usr/src/cacti
wget -N http://www.cacti.net/downloads/spine/cacti-spine-1.1.3.tar.gz && tar zxvf cacti-spine-1.1.3.tar.gz
cd cacti-spine-1.1.3
yum install -y gcc gcc-c++ libtool make automake autoconf glibc net-snmp-devel openssl-devel unzip help2man dos2unix
yum install -y mysql-devel
aclocal
libtoolize --force
autoheader
autoconf
automake
./configure
make && make install
cp /usr/local/spine/etc/spine.conf.dist /usr/local/spine/etc/spine.conf
# install cacti
cd /usr/src/cacti
wget -N http://www.cacti.net/downloads/cacti-1.1.3.tar.gz && tar zxvf cacti-1.1.3.tar.gz -C /usr/share/nginx/html/
mv -f /usr/share/nginx/html/cacti-1.1.3/* /usr/share/nginx/html/
sed -i 's/\/cacti\//\//g' /usr/share/nginx/html/include/global.php
#sed -i 's/^\$url_path/# \$url_path/g' /usr/share/nginx/html/include/config.php
sed -i 's/\/cacti\//\//g' /usr/share/nginx/html/include/config.php
chown -R apache:apache /usr/share/nginx/html
# conf mysql for cacti
sed -i '/^\[mysqld_safe\]/i\ ' /etc/my.cnf
sed -i '/^\[mysqld_safe\]/i\# for cacti' /etc/my.cnf
sed -i '/^\[mysqld_safe\]/i\character_set_server=utf8mb4' /etc/my.cnf
sed -i '/^\[mysqld_safe\]/i\collation_server = utf8mb4_unicode_ci' /etc/my.cnf
sed -i '/^\[mysqld_safe\]/i\max_heap_table_size = 128M' /etc/my.cnf
sed -i '/^\[mysqld_safe\]/i\max_allowed_packet = 16777216' /etc/my.cnf
sed -i '/^\[mysqld_safe\]/i\tmp_table_size = 64M' /etc/my.cnf
sed -i '/^\[mysqld_safe\]/i\join_buffer_size = 64M' /etc/my.cnf
sed -i '/^\[mysqld_safe\]/i\innodb_buffer_pool_size = 512M' /etc/my.cnf
sed -i '/^\[mysqld_safe\]/i\innodb_doublewrite = OFF' /etc/my.cnf
sed -i '/^\[mysqld_safe\]/i\innodb_additional_mem_pool_size = 128M' /etc/my.cnf
sed -i '/^\[mysqld_safe\]/i\innodb_flush_log_at_timeout = 5' /etc/my.cnf
sed -i '/^\[mysqld_safe\]/i\innodb_read_io_threads = 32' /etc/my.cnf
sed -i '/^\[mysqld_safe\]/i\innodb_write_io_threads = 16' /etc/my.cnf
sed -i '/^\[mysqld_safe\]/i\ ' /etc/my.cnf
systemctl restart mysqld.service
# init mysql db for cacti
mysql_tzinfo_to_sql /usr/share/zoneinfo/ | mysql -u root -pdbadmin mysql
#mysql -u root -pdbadmin -e 'drop database `cacti`; '
#mysql -u root -pdbadmin -e 'CREATE DATABASE `cacti` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;'
mysql -u root -pdbadmin -e 'CREATE DATABASE `cacti`;'
mysql -u root -pdbadmin -e "CREATE USER 'cactiuser'@'localhost' IDENTIFIED BY 'cactiuser';"
mysql -u root -pdbadmin -e 'GRANT ALL PRIVILEGES ON `cacti` . * TO 'cactiuser'@'localhost';'
mysql -u root -pdbadmin -e 'GRANT SELECT ON mysql.time_zone_name TO cactiuser@localhost;'
mysql -u root -pdbadmin -e 'flush privileges;'
mysql -u cactiuser -pcactiuser cacti < /usr/share/nginx/html/cacti.sql
mkdir /usr/share/httpd && chown -R apache:apache /usr/share/httpd
touch /etc/cron.d/cacti
echo "*/5 * * * * apache /usr/bin/php /usr/share/nginx/html/poller.php > /dev/null 2>&1" > /etc/cron.d/cacti
systemctl restart mysqld.service
systemctl restart php-fpm.service
systemctl restart nginx.service