cacti 1.1.3, nginx with php-fpm on centos 7

Post support questions that directly relate to Linux/Unix operating systems.

Moderators: Developers, Moderators

Post Reply
nationals
Cacti User
Posts: 76
Joined: Wed Aug 27, 2008 5:21 am
Location: China
Contact:

cacti 1.1.3, nginx with php-fpm on centos 7

Post by nationals »

just post the code after tested all.

no time to ...

maybe sometime will release.

hope it can help somebody to save deploy time.
Capture.JPG
Capture.JPG (67.83 KiB) Viewed 3988 times

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
nationals
Cacti User
Posts: 76
Joined: Wed Aug 27, 2008 5:21 am
Location: China
Contact:

Re: cacti 1.1.3, nginx with php-fpm on centos 7

Post by nationals »

Code: Select all

# check if Centos/Redhat Release
if [ ! -f /etc/redhat-release ]; then 
    echo This is not Centos/Redhat Release Linux.
	echo It is not supported!
	echo Exit...
	echo
	exit
fi

# check if CentOS Release
if [ `cat /etc/redhat-release| awk '{ print $1 }'` != "CentOS" ]; then
	echo
	echo The installed release is `cat /etc/redhat-release| awk '{ print $1 }'`
	echo but not CentOS.
	echo This is only support for CentOS release.
	echo Please run it under the CentOS release.
	echo Exit...
	echo
	exit
fi

# check if CentOS Release 7
if [ `cat /etc/redhat-release| awk '{ print $4 }'| awk -F . '{ print $1 }'` != "7" ]; then
	echo
	echo The installed release version is `cat /etc/redhat-release| awk '{ print $3 }'`
	echo but not 7.x.
	echo This is only support for CentOS release 7.x.
	echo Please run it under the CentOS release 7.x.
	echo Exit...
	echo
	exit
fi
1602886
Posts: 4
Joined: Tue May 23, 2017 8:24 pm

Re: cacti 1.1.3, nginx with php-fpm on centos 7

Post by 1602886 »

First of all thank you for your scripts, use this script to save the deployment time, but also met some problems during the deployment process.Please answer.
After running the script will be an error as the attachment, and need to manually perform "/ usr/bin/PHP/usr/share/nginx/HTML/the poller. PHP" generated graphics and data can't be done.
Now I temporarily use spine and set to 1 minute to get the data, the current normal.
My OS environment: CentOS Linux release 7.3.1611 (Core)
Cacti1.1.7 spine1.1.7
Attachments
test1.png
test1.png (113.61 KiB) Viewed 3535 times
test.png
test.png (123.53 KiB) Viewed 3535 times
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest