|
1、架构设计图

2、设计说明
1. 基础架构为LAMP环境,采用keepalived实现zabbix服务器高可用,保证主server的mysql或者httpd宕掉后能切换到从server。
2、数据库做主主同步,保证两边服务器数据的一致性,实现数据库的高可用。
3、采用unison同步软件保证不管修改那台服务器配置,zabbix配置目录及web目录内容的一致,实现文件双向同步。
3、网络环境
zabbix01:192.168.8.117
zabbix02:192.168.8.118
vip:192.168.8.111
4、软件版本
OS:CentOS release 6.9 X86_64
MYSQL:Percona-Server-5.6
NGINX:tengine-2.2.0
PHP: php-7.0.16
ZABBIX:zabbix3.2.6
ZLIB:zlib-1.2.11
OPENSSL:openssl-1.0.2
PCRE:pcre-8.39
CAML:ocaml-3.10.2
UNISON:unison-2.13.16
INOTIFY-TOOLS:inotify-tools-3.13
5、基础调试
yum update
yum groupinstall '开发工具'
vim /etc/selinux/config
selinux=disabled
:wq
iptables -F
/etc/init.d/iptables save
/etc/init.d/iptables stop
chkconfig iptables off
/etc/init.d/postfix stop && chkconfig postfix off
yum install gcc gcc-c++ libxml2 libxml2-devel libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libmcrypt libmcrypt-devel openssl-devel bzip2-devel recode-devel openldap openldap-devel net-snmp net-snmp-devel libcurl-devel libcurl vim wget ntp jemalloc -y
reboot
6、LNMP环境安装
安装pcre
tar xf pcre-8.39.tar.gz
cd pcre-8.39
./configure --prefix=/usr/local/pcre/ && make && make install
openssl安装
tar xf openssl-1.0.2.tar.gz
cd openssl-1.0.2
./config enable-shared --prefix=/usr/local/openssl/ && make && make test && make install
zlib安装
tar xf zlib-1.2.11.tar.gz
cd zlib-1.2.11
./configure --prefix=/usr/local/zlib && make &&make install
nginx安装
groupadd web
useradd -s /sbin/nologin -g web web
tar xf tengine-2.2.0.tar.gz
./configure --prefix=/usr/local/nginx --user=web --group=web --with-pcre=/root/pcre-8.39 --with-openssl=/root/openssl-1.0.2 --with-zlib=/root/zlib-1.2.11 --with-file-aio --with-http_gzip_static_module --with-http_realip_module --with-http_stub_status_module
make && make install
vim /etc/init.d/nginx
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /etc/nginx/nginx.conf
# config: /etc/sysconfig/nginx
# pidfile: /var/run/nginx.pid
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
nginx="/usr/local/nginx/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx
make_dirs() {
# make required directories
user=`$nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -`
if [ -z "`grep $user /etc/passwd`" ]; then
useradd -M -s /bin/nologin $user
fi
options=`$nginx -V 2>&1 | grep 'configure arguments:'`
for opt in $options; do
if [ `echo $opt | grep '.*-temp-path'` ]; then
value=`echo $opt | cut -d "=" -f 2`
if [ ! -d "$value" ]; then
# echo "creating" $value
mkdir -p $value && chown -R $user $value
fi
fi
done
}
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
make_dirs
echo -n $"Starting $prog: "
daemon $nginx -c $NGINX_CONF_FILE
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
configtest || return $?
stop
sleep 1
start
}
reload() {
configtest || return $?
echo -n $"Reloading $prog: "
killproc $nginx -HUP
RETVAL=$?
echo
}
force_reload() {
restart
}
configtest() {
$nginx -t -c $NGINX_CONF_FILE
}
rh_status() {
status $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit 2
esac
chkconfig nginx on
ln -s /usr/local/nginx/sbin/nginx /usr/local/bin/nginx
chmod +x /etc/init.d/nginx
php安装
tar xf php-7.0.16.tar.gz
cd php-7.0.16
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-bz2 --with-curl --enable-ftp --enable-sockets --disable-ipv6 --with-gd --with-jpeg-dir=/usr/local --with-png-dir=/usr/local --with-freetype-dir=/usr/local --enable-gd-native-ttf --with-iconv-dir=/usr/local/lib/libconv --enable-mbstring --enable-calendar --with-gettext --with-libxml-dir=/usr/local --with-zlib --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --enable-dom --enable-xml --enable-fpm --with-libdir=lib64 --enable-bcmath --enable-zip --enable-pcntl --enable-exif --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-opcache --enable-session --enable-mbregex --with-fpm-user=vagrant --with-fpm-group=nogroup --enable-wddx --with-mcrypt --enable-gd-native-ttf --enable-gd-jis-conv --with-openssl --with-zlib=/usr --with-recode=/usr --with-xmlrpc --enable-inline-optimization --disable-debug --disable-rpath --with-ldap
make
make test
make install
vim /etc/init.d/php-fpm
#! /bin/sh
### BEGIN INIT INFO
# Provides: php-fpm
# Required-Start: $remote_fs $network
# Required-Stop: $remote_fs $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts php-fpm
# Description: starts the PHP FastCGI Process Manager daemon
### END INIT INFO
prefix=/usr/local/php
exec_prefix=${prefix}
php_fpm_BIN=${exec_prefix}/sbin/php-fpm
php_fpm_CONF=${prefix}/etc/php-fpm.conf
php_fpm_PID=${prefix}/var/run/php-fpm.pid
php_opts="--fpm-config $php_fpm_CONF --pid $php_fpm_PID"
wait_for_pid () {
try=0
while test $try -lt 35 ; do
case "$1" in
'created')
if [ -f "$2" ] ; then
try=''
break
fi
;;
'removed')
if [ ! -f "$2" ] ; then
try=''
break
fi
;;
esac
echo -n .
try=`expr $try + 1`
sleep 1
done
}
case "$1" in
start)
echo -n "Starting php-fpm "
$php_fpm_BIN --daemonize $php_opts
if [ "$?" != 0 ] ; then
echo " failed"
exit 1
fi
wait_for_pid created $php_fpm_PID
if [ -n "$try" ] ; then
echo " failed"
exit 1
else
echo " done"
fi
;;
stop)
echo -n "Gracefully shutting down php-fpm "
if [ ! -r $php_fpm_PID ] ; then
echo "warning, no pid file found - php-fpm is not running ?"
exit 1
fi
kill -QUIT `cat $php_fpm_PID`
wait_for_pid removed $php_fpm_PID
if [ -n "$try" ] ; then
echo " failed. Use force-quit"
exit 1
else
echo " done"
fi
;;
status)
if [ ! -r $php_fpm_PID ] ; then
echo "php-fpm is stopped"
exit 0
fi
PID=`cat $php_fpm_PID`
if ps -p $PID | grep -q $PID; then
echo "php-fpm (pid $PID) is running..."
else
echo "php-fpm dead but pid file exists"
fi
;;
force-quit)
echo -n "Terminating php-fpm "
if [ ! -r $php_fpm_PID ] ; then
echo "warning, no pid file found - php-fpm is not running ?"
exit 1
fi
kill -TERM `cat $php_fpm_PID`
wait_for_pid removed $php_fpm_PID
if [ -n "$try" ] ; then
echo " failed"
exit 1
else
echo " done"
fi
;;
restart)
$0 stop
$0 start
;;
reload)
echo -n "Reload service php-fpm "
if [ ! -r $php_fpm_PID ] ; then
echo "warning, no pid file found - php-fpm is not running ?"
exit 1
fi
kill -USR2 `cat $php_fpm_PID`
echo " done"
;;
*)
echo "Usage: $0 {start|stop|force-quit|restart|reload|status}"
exit 1
;;
esac
chmod +x /etc/init.d/php-fpm
chkconfig php-fpm on
ln -s /usr/local/php/bin/php /usr/local/bin/php
ln -s /usr/local/php/bin/php-config /usr/local/bin/php-config
ln -s /usr/local/php/bin/phpize /usr/local/bin/phpize
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
cp php.ini-development /usr/local/php/etc/php.ini
ln -s /user/local/php/etc/php.ini /etc
vim www.conf
将user和group替换为web
nginx和php整合
cat /user/local/nginx/conf/nginx.conf
mysql安装
tar xf Percona-Server-5.6.33-79.0-r2084bdb-el6-x86_64-bundle.tar
yum localinstall Percona-Server-*
/etc/init.d/mysql start
ps_tokudb_admin --enable -uroot
更改数据引擎
vim /etc/my.cnf
在[mysqld]下添加
default-storage-engine=TokuDB
:wq
/etc/init.d/mysql restart
mysql> show engines;
+--------------------+---------+----------------------------------------------------------------------------+--------------+------+------------+
| Engine | Support | Comment | Transactions | XA | Savepoints |
+--------------------+---------+----------------------------------------------------------------------------+--------------+------+------------+
| PERFORMANCE_SCHEMA | YES | Performance Schema | NO | NO | NO |
| CSV | YES | CSV storage engine | NO | NO | NO |
| MyISAM | YES | MyISAM storage engine | NO | NO | NO |
| BLACKHOLE | YES | /dev/null storage engine (anything you write to it disappears) | NO | NO | NO |
| MEMORY | YES | Hash based, stored in memory, useful for temporary tables | NO | NO | NO |
| TokuDB | DEFAULT | Percona TokuDB Storage Engine with Fractal Tree(tm) Technology | YES | YES | YES |
| MRG_MYISAM | YES | Collection of identical MyISAM tables | NO | NO | NO |
| ARCHIVE | YES | Archive storage engine | NO | NO | NO |
| InnoDB | YES | Percona-XtraDB, Supports transactions, row-level locking, and foreign keys | YES | YES | YES |
| FEDERATED | NO | Federated MySQL storage engine | NULL | NULL | NULL |
+--------------------+---------+----------------------------------------------------------------------------+--------------+------+------------+
10 rows in set (0.03 sec)
chkconfig mysql on
启动服务
/etc/init.d/nginx restart
/etc/ini.d/php-fpm restart
7、安装zabbix(zabbix01和zabbix02相同)
groupadd -g 201 zabbix
useradd -g zabbix -u 201 -s /sbin/nologin zabbix
tar xf zabbix-3.2.6.tar.gz
cd zabbix-3.2.6
./configure --prefix=/usr/local/zabbix --enable-server --enable-proxy --enable-agent --with-mysql=/usr/bin/mysql_config --with-net-snmp --with-libcurl --with-ldap --with-libxml2
make && make install
创建并导入数据(注意顺序)
mysql -e "create database zabbix default charset utf8;"
mysql -e "grant all on zabbix.* to zabbix@localhost identified by 'zabbix';"
mysql -uzabbix -pzabbix zabbix |
|
|