LVS-NAT负载均衡PHP应用(Wordpress、Discuz)
1 实验拓扑
2 需求
- RS-01和RS-02对外提供WEB服务。
- RS-01搭建LAMP,PHP通过http模块方式提供。
- RS-02搭建LAMP,PHP通过fpm方式提供。
- RS-01和RS-02之间的关系。
- RS-01对外提供NFS服务,作为两个LAMP环境的共享存储,负责存储用户上传的资源,例如:图片、文档等。
- RS-02对外提供Mariadb服务,作为两台LAMP环境的共享数据库,负责存储用户的帖子、文字等。
- 对外提供的域名为www.example.com
建议现将下面的文章全部浏览完成,再做实验。
3 软件版本
本次使用root用户进行安装,软件全部在每台设备的/root/目录下
apr-1.6.3.tar.bz2
apr-util-1.6.1.tar.bz2
Discuz_X3.1_SC_UTF8.zip
httpd-2.4.6.tar.bz2
mariadb-5.5.46-linux-x86_64.tar.gz
phpMyAdmin-4.0.10.20-all-languages.zip
wordpress-4.7.4-zh_CN.tar.gz
php-5.3.27.tar.gz
4 VS配置
一共部署了3个软件,wordpress、discuz、phpMyAdmin;
wordpress和discuz工作在rr模式下也可以正常的访问网页不会出现session超时的现象,可以访问速度非常慢;如果将模式改为sh或者删除一个rs主机,速度就快起来了;
phpMyAdmin工作在rr模式下会提示session超时;
sysctl -w net.ipv4.ip_forward=1
yum -y install ipvsadm
ipvsadm -A -t 10.207.51.113:80 -s rr
ipvsadm -a -t 10.207.51.113:80 -r 10.0.0.101:80 -m
ipvsadm -a -t 10.207.51.113:80 -r 10.0.0.102:80 -m
5 RS_01部署NFS
因为NFS是共享存储,RS-01和RS-02都需要使用,所以提前部署。
yum install -y rpcbind nfs-utils &&\
echo '/nfsdata/wordpress 10.0.0.0/24(rw,sync,root_squash,all_squash,anonuid=48,anongid=48)' >/etc/exports &&\
echo '/nfsdata/discuz 10.0.0.0/24(rw,sync,root_squash,all_squash,anonuid=48,anongid=48)' >>/etc/exports &&\
mkdir -p /nfsdata/wordpress &&\
mkdir -p /nfsdata/discuz &&\
systemctl start rpcbind &&\
systemctl start nfs &&\
systemctl enable rpcbind &&\
systemctl enable nfs
[root@rs_01 ~]# showmount -e
Export list for rs_01:
/nfsdata/discuz 10.0.0.0/24
/nfsdata/wordpress 10.0.0.0/24
注意:要确保RS-01和RS-02上的apache用户的UID和GID都是48
6 RS_02部署Mariadb
因为Mariadb是共享数据库,RS-01和RS-02都需要使用,所以提前部署。
tar -xf mariadb-5.5.46-linux-x86_64.tar.gz -C /usr/local/ &&\
cd /usr/local/ &&\
useradd -r -M -s /sbin/nologin mysql &&\
ln -sv mariadb-5.5.46-linux-x86_64 mysql &&\
chown -R mysql.mysql mysql/ &&\
mkdir /databases &&\
cd mysql/ &&\
\cp support-files/my-huge.cnf /etc/my.cnf &&\
sed -i "/\[mysqld\]/a datadir = /databases\ninnodb_file_per_table = on\nskip_name_resolve = on" /etc/my.cnf &&\
./scripts/mysql_install_db --user=mysql --datadir=/databases --basedir=/usr/local/mysql &&\
touch /var/log/mysqld.log &&\
chown mysql:mysql /var/log/mysqld.log &&\
echo 'PATH=$PATH:/usr/local/mysql/bin' > /etc/profile.d/mariadb.sh &&\
source /etc/profile.d/mariadb.sh &&\
echo 'MANPATH_MAP /usr/local/apache2/bin /usr/local/apache2/man' >>/etc/man_db.conf && \
manpath &&\
ln -sv /usr/local/mysql/include /usr/include/mysql &&\
echo '/usr/local/mysql/lib/' > /etc/ld.so.conf.d/mariadb.conf &&\
ldconfig &&\
\cp support-files/mysql.server /etc/init.d/mysqld &&\
chkconfig --add mysqld &&\
chkconfig --list mysqld &&\
sleep 3 &&\
service mysqld start
----------------------------------------------------------------------------------------------
mysql -h127.0.0.1 -uroot
CREATE DATABASE wordpress;
CREATE DATABASE discuz;
SET PASSWORD FOR 'root'@'127.0.0.1' = PASSWORD('123123');
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('123123');
CREATE USER 'wordpress'@'10.0.0.%' IDENTIFIED BY '123123';
CREATE USER 'wordpress'@'127.0.0.1' IDENTIFIED BY '123123';
GRANT ALL ON wordpress.* TO 'wordpress'@'127.0.0.1';
GRANT ALL ON wordpress.* TO 'wordpress'@'10.0.0.%';
CREATE USER 'discuz'@'10.0.0.%' IDENTIFIED BY '123123';
CREATE USER 'discuz'@'127.0.0.1' IDENTIFIED BY '123123';
GRANT ALL ON discuz.* TO 'discuz'@'127.0.0.1';
GRANT ALL ON discuz.* TO 'discuz'@'10.0.0.%';
exit
7 RS_01
7.1 部署HTTP
vim /etc/sysconfig/httpd
# Configuration file for the httpd service.
#
# The default processing model (MPM) is the process-based
# 'prefork' model. A thread-based model, 'worker', is also
# available, but does not work with some modules (such as PHP).
# The service must be stopped before changing this variable.
#
HTTPD=/usr/local/apache2/bin/httpd
#
# To pass additional options (for instance, -D definitions) to the
# httpd binary at startup, set OPTIONS here.
#
#OPTIONS=
#
# By default, the httpd process is started in the C locale; to
# change the locale in which the server runs, the HTTPD_LANG
# variable can be set.
#
#HTTPD_LANG=C
#
# By default, the httpd process will create the file
# /usr/local/apache2/logs/httpd.pid in which it records its process
# identification number when it starts. If an alternate location is
# specified in httpd.conf (via the PidFile directive), the new
# location needs to be reported in the PIDFILE.
#
#PIDFILE=/usr/local/apache2/logs/httpd.pid
------------------------------------------------------------------------------------
vim /etc/rc.d/init.d/httpd
#!/bin/bash
#
# httpd Startup script for the Apache HTTP Server
#
# chkconfig: - 85 15
# description: The Apache HTTP Server is an efficient and extensible \
# server implementing the current HTTP standards.
# processname: httpd
# config: /etc/httpd/httpd.conf
# config: /etc/sysconfig/httpd
# pidfile: /usr/local/apache2/logs/httpd.pid
#
### BEGIN INIT INFO
# Provides: httpd
# Required-Start: $local_fs $remote_fs $network $named
# Required-Stop: $local_fs $remote_fs $network
# Should-Start: distcache
# Short-Description: start and stop Apache HTTP Server
# Description: The Apache HTTP Server is an extensible server
# implementing the current HTTP standards.
### END INIT INFO
# Source function library.
. /etc/rc.d/init.d/functions
if [ -f /etc/sysconfig/httpd ]; then
. /etc/sysconfig/httpd
fi
# Start httpd in the C locale by default.
HTTPD_LANG=${HTTPD_LANG-"C"}
# This will prevent initlog from swallowing up a pass-phrase prompt if
# mod_ssl needs a pass-phrase from the user.
INITLOG_ARGS=""
# Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server
# with the thread-based "worker" MPM; BE WARNED that some modules may not
# work correctly with a thread-based MPM; notably PHP will refuse to start.
# Path to the apachectl script, server binary, and short-form for messages.
apachectl=/usr/local/apache2/bin/apachectl
httpd=${HTTPD-/usr/local/apache2/bin/httpd}
prog=httpd
pidfile=${PIDFILE-/usr/local/apache2/logs/httpd.pid}
lockfile=${LOCKFILE-/var/lock/subsys/httpd}
RETVAL=0
STOP_TIMEOUT=${STOP_TIMEOUT-10}
# The semantics of these two functions differ from the way apachectl does
# things -- attempting to start while running is a failure, and shutdown
# when not running is also a failure. So we just do it the way init scripts
# are expected to behave here.
start() {
echo -n $"Starting $prog: "
LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch ${lockfile}
return $RETVAL
}
# When stopping httpd, a delay (of default 10 second) is required
# before SIGKILLing the httpd parent; this gives enough time for the
# httpd parent to SIGKILL any errant children.
stop() {
status -p ${pidfile} $httpd > /dev/null
if [[ $? = 0 ]]; then
echo -n $"Stopping $prog: "
killproc -p ${pidfile} -d ${STOP_TIMEOUT} $httpd
else
echo -n $"Stopping $prog: "
success
fi
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
}
reload() {
echo -n $"Reloading $prog: "
if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then
RETVAL=6
echo $"not reloading due to configuration syntax error"
failure $"not reloading $httpd due to configuration syntax error"
else
# Force LSB behaviour from killproc
LSB=1 killproc -p ${pidfile} $httpd -HUP
RETVAL=$?
if [ $RETVAL -eq 7 ]; then
failure $"httpd shutdown"
fi
fi
echo
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status -p ${pidfile} $httpd
RETVAL=$?
;;
restart)
stop
start
;;
condrestart|try-restart)
if status -p ${pidfile} $httpd >&/dev/null; then
stop
start
fi
;;
force-reload|reload)
reload
;;
graceful|help|configtest|fullstatus)
$apachectl $@
RETVAL=$?
;;
*)
echo $"Usage: $prog {start|stop|restart|condrestart|try-restart|force-reload|reload|status|fullstatus|graceful|help|configtest}"
RETVAL=2
esac
exit $RETVAL
---------------------------------------------------------------------------
chmod +x /etc/init.d/httpd &&\
yum groupinstall -y "Development tools" && \
yum install -y expat-devel openssl-devel pcre-devel && \
tar -xf apr-1.6.3.tar.bz2 && \
tar -xf apr-util-1.6.1.tar.bz2 && \
tar -xf httpd-2.4.6.tar.bz2 && \
cd apr-1.6.3/ && \
./configure -prefix=/usr/local/apr-1.6.3 && \
make && make install && \
cd ../apr-util-1.6.1/ && \
./configure -prefix=/usr/local/apr-unil-1.6.1 --with-apr=/usr/local/apr-1.6.3 && \
make && make install && \
cd ../httpd-2.4.6/ && \
cp -r ../apr-1.6.3 ./srclib/apr && \
cp -r ../apr-util-1.6.1 ./srclib/apr-util && \
./configure --prefix=/usr/local/apache2 \
--with-apr=/usr/local/apr-1.6.3 \
--with-apr-util=/usr/local/apr-unil-1.6.1 \
--with-included-apr \
--sysconfdir=/etc/httpd \
--enable-so \
--enable-mpms-shared=all \
--enable-mods-shared=all \
--with-mpm=prefork && \
make && \
make install && \
chmod 755 /etc/init.d/httpd && \
chkconfig --add httpd && \
chkconfig --level 3 httpd on && \
echo "export PATH=$PATH:/usr/local/apache2/bin" > /etc/profile.d/apache2.sh && \
source /etc/profile.d/apache2.sh && \
sed -i -e "/\/opt\/sbin/a MANPATH_MAP /usr/local/apache2/bin /usr/local/apache2/man" /etc/man_db.conf && \
manpath && \
ln -sv /usr/local/apache2/include /usr/include/httpd && \
echo "/usr/local/apache2/lib" > /etc/ld.so.conf.d/httpd.conf && \
ldconfig && \
sed -i "s#User daemon#User apache#g" /etc/httpd/httpd.conf && \
sed -i "s#Group daemon#Group apache#g" /etc/httpd/httpd.conf && \
sed -ri "s#^\#(ServerName www.example.com:80)#\1#g" /etc/httpd/httpd.conf &&\
groupadd -g 48 apache && \
useradd -u 48 -g 48 -M -s /sbin/nologin apache && \
sleep 3 && \
service httpd start
7.2 PHP
yum install -y zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel libiconv-devel freetype-devel libpng-devel gd-devel libcurl-devel libxslt-devel libxslt-devel openssl-devel libmcrypt-devel libtool-ltdl-devel gcc gcc-c++ && \
tar -xf php-5.3.27.tar.gz && \
cd php-5.3.27 && \
useradd -r -M -s /sbin/nologin php && \
./configure --prefix=/usr/local/php \
--sysconfdir=/etc \
--with-apxs2=/usr/local/apache2/bin/apxs \
--with-mysql=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-iconv-dir=/usr/local/libiconv \
--with-libxml-dir=/usr \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--enable-xml \
--disable-rpath \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--with-curl \
--enable-mbregex \
--enable-mbstring \
--with-mcrypt \
--with-openssl \
--with-gd \
--enable-gd-native-ttf \
--with-openssl \
--with-mhash \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-soap \
--enable-short-tags \
--enable-static \
--with-xsl \
--enable-ftp \
--with-config-file-path=/etc \
--with-config-file-scan-dir=/etc/php.d && \
make && \
make install && \
echo 'PATH=$PATH:/usr/local/php/bin' > /etc/profile.d/php.sh && \
source /etc/profile.d/php.sh && \
sed -i -e "/\/opt\/sbin/a MANPATH_MAP /usr/local/php/bin /usr/local/php/man" /etc/man_db.conf && \
manpath && \
ln -sv /usr/local/php/include /usr/include/php && \
cp php.ini-production /etc/php.ini && \
sed -i -r 's#^;(date.timezone =)#\1 Asia/Shanghai#g' /etc/php.ini && \
chown -R php:php /etc/php.ini && \
chown -R php:php /usr/local/php && \
sed -i 's#DirectoryIndex index.html#DirectoryIndex index.html index.php#g' /etc/httpd/httpd.conf && \
sed -i "/<IfModule mime_module>/a \ \ \ \ AddType application/x-httpd-php .php\n AddType applicaiton/x-httpd-php-source .phps" /etc/httpd/httpd.conf && \
sed -i "s#/usr/local/apache2/htdocs#/data/www#g" /etc/httpd/httpd.conf &&\
sleep 3 &&\
service httpd restart
7.3 Wordpress
mkdir -p /data/www/ &&\
tar -xf wordpress-4.7.4-zh_CN.tar.gz -C /data/www/ &&\
cp -r /data/www/wordpress/wp-content/* /nfsdata/wordpress/ &&\
mv /data/www/wordpress/wp-content /data/www/wordpress/wp-content.bak &&\
mkdir /data/www/wordpress/wp-content &&\
chown -R apache: /data/www/wordpress/ &&\
mount --bind /nfsdata/wordpress /data/www/wordpress/wp-content &&\
cd /data/www/ &&\
cp wordpress/wp-config-sample.php wordpress/wp-config.php &&\
sed -i 's#database_name_here#wordpress#g' wordpress/wp-config.php &&\
sed -i 's#username_here#wordpress#g' wordpress/wp-config.php &&\
sed -i 's#password_here#123123#g' wordpress/wp-config.php &&\
sed -i 's#localhost#10.0.0.102#g' wordpress/wp-config.php &&\
chown -R apache:apache /data/www/wordpress/ &&\
service httpd restart
在浏览器中输入下面的链接安装wordpress
http://10.0.0.101/wordpress/wp-admin/setup-config.php
在本次环境中,使用上面这个链接安装是不对的,要使用最后绑定给VIP的域名(www.example.com)来安装wordpress,不要直接使用RS-01的IP来安装,具体原因见下文,此处假定使用了上面的安装方式;
正确安装方式:将www.example.com临时解析为10.0.0.101;然后执行安装http://www.example.com/wordpress/wp-admin/setup-config.php
8 RS-02
8.1 HTTP
vim /etc/sysconfig/httpd
# Configuration file for the httpd service.
#
# The default processing model (MPM) is the process-based
# 'prefork' model. A thread-based model, 'worker', is also
# available, but does not work with some modules (such as PHP).
# The service must be stopped before changing this variable.
#
HTTPD=/usr/local/apache2/bin/httpd
#
# To pass additional options (for instance, -D definitions) to the
# httpd binary at startup, set OPTIONS here.
#
#OPTIONS=
#
# By default, the httpd process is started in the C locale; to
# change the locale in which the server runs, the HTTPD_LANG
# variable can be set.
#
#HTTPD_LANG=C
#
# By default, the httpd process will create the file
# /usr/local/apache2/logs/httpd.pid in which it records its process
# identification number when it starts. If an alternate location is
# specified in httpd.conf (via the PidFile directive), the new
# location needs to be reported in the PIDFILE.
#
#PIDFILE=/usr/local/apache2/logs/httpd.pid
------------------------------------------------------------------------------
vim /etc/rc.d/init.d/httpd
#!/bin/bash
#
# httpd Startup script for the Apache HTTP Server
#
# chkconfig: - 85 15
# description: The Apache HTTP Server is an efficient and extensible \
# server implementing the current HTTP standards.
# processname: httpd
# config: /etc/httpd/httpd.conf
# config: /etc/sysconfig/httpd
# pidfile: /usr/local/apache2/logs/httpd.pid
#
### BEGIN INIT INFO
# Provides: httpd
# Required-Start: $local_fs $remote_fs $network $named
# Required-Stop: $local_fs $remote_fs $network
# Should-Start: distcache
# Short-Description: start and stop Apache HTTP Server
# Description: The Apache HTTP Server is an extensible server
# implementing the current HTTP standards.
### END INIT INFO
# Source function library.
. /etc/rc.d/init.d/functions
if [ -f /etc/sysconfig/httpd ]; then
. /etc/sysconfig/httpd
fi
# Start httpd in the C locale by default.
HTTPD_LANG=${HTTPD_LANG-"C"}
# This will prevent initlog from swallowing up a pass-phrase prompt if
# mod_ssl needs a pass-phrase from the user.
INITLOG_ARGS=""
# Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server
# with the thread-based "worker" MPM; BE WARNED that some modules may not
# work correctly with a thread-based MPM; notably PHP will refuse to start.
# Path to the apachectl script, server binary, and short-form for messages.
apachectl=/usr/local/apache2/bin/apachectl
httpd=${HTTPD-/usr/local/apache2/bin/httpd}
prog=httpd
pidfile=${PIDFILE-/usr/local/apache2/logs/httpd.pid}
lockfile=${LOCKFILE-/var/lock/subsys/httpd}
RETVAL=0
STOP_TIMEOUT=${STOP_TIMEOUT-10}
# The semantics of these two functions differ from the way apachectl does
# things -- attempting to start while running is a failure, and shutdown
# when not running is also a failure. So we just do it the way init scripts
# are expected to behave here.
start() {
echo -n $"Starting $prog: "
LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch ${lockfile}
return $RETVAL
}
# When stopping httpd, a delay (of default 10 second) is required
# before SIGKILLing the httpd parent; this gives enough time for the
# httpd parent to SIGKILL any errant children.
stop() {
status -p ${pidfile} $httpd > /dev/null
if [[ $? = 0 ]]; then
echo -n $"Stopping $prog: "
killproc -p ${pidfile} -d ${STOP_TIMEOUT} $httpd
else
echo -n $"Stopping $prog: "
success
fi
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
}
reload() {
echo -n $"Reloading $prog: "
if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then
RETVAL=6
echo $"not reloading due to configuration syntax error"
failure $"not reloading $httpd due to configuration syntax error"
else
# Force LSB behaviour from killproc
LSB=1 killproc -p ${pidfile} $httpd -HUP
RETVAL=$?
if [ $RETVAL -eq 7 ]; then
failure $"httpd shutdown"
fi
fi
echo
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status -p ${pidfile} $httpd
RETVAL=$?
;;
restart)
stop
start
;;
condrestart|try-restart)
if status -p ${pidfile} $httpd >&/dev/null; then
stop
start
fi
;;
force-reload|reload)
reload
;;
graceful|help|configtest|fullstatus)
$apachectl $@
RETVAL=$?
;;
*)
echo $"Usage: $prog {start|stop|restart|condrestart|try-restart|force-reload|reload|status|fullstatus|graceful|help|configtest}"
RETVAL=2
esac
exit $RETVAL
------------------------------------------------------------------------------------
chmod +x /etc/init.d/httpd &&\
yum groupinstall -y "Development tools" && \
yum install -y expat-devel openssl-devel pcre-devel && \
tar -xf apr-1.6.3.tar.bz2 && \
tar -xf apr-util-1.6.1.tar.bz2 && \
tar -xf httpd-2.4.6.tar.bz2 && \
cd apr-1.6.3/ && \
./configure -prefix=/usr/local/apr-1.6.3 && \
make && make install && \
cd ../apr-util-1.6.1/ && \
./configure -prefix=/usr/local/apr-unil-1.6.1 --with-apr=/usr/local/apr-1.6.3 && \
make && make install && \
cd ../httpd-2.4.6/ && \
cp -r ../apr-1.6.3 ./srclib/apr && \
cp -r ../apr-util-1.6.1 ./srclib/apr-util && \
./configure --prefix=/usr/local/apache2 \
--with-apr=/usr/local/apr-1.6.3 \
--with-apr-util=/usr/local/apr-unil-1.6.1 \
--with-included-apr \
--sysconfdir=/etc/httpd \
--enable-so \
--enable-mpms-shared=all \
--enable-mods-shared=all \
--with-mpm=prefork && \
make && \
make install && \
chmod 755 /etc/init.d/httpd && \
chkconfig --add httpd && \
chkconfig --level 3 httpd on && \
echo "export PATH=$PATH:/usr/local/apache2/bin" > /etc/profile.d/apache2.sh && \
source /etc/profile.d/apache2.sh && \
sed -i -e "/\/opt\/sbin/a MANPATH_MAP /usr/local/apache2/bin /usr/local/apache2/man" /etc/man_db.conf && \
manpath && \
ln -sv /usr/local/apache2/include /usr/include/httpd && \
echo "/usr/local/apache2/lib" > /etc/ld.so.conf.d/httpd.conf && \
ldconfig && \
sed -i "s#User daemon#User apache#g" /etc/httpd/httpd.conf && \
sed -i "s#Group daemon#Group apache#g" /etc/httpd/httpd.conf && \
sed -ri "s#^\#(ServerName www.example.com:80)#\1#g" /etc/httpd/httpd.conf &&\
groupadd -g 48 apache && \
useradd -u 48 -g 48 -M -s /sbin/nologin apache && \
sleep 3 && \
service httpd start
8.2 PHP
yum install -y zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel libiconv-devel freetype-devel libpng-devel gd-devel libcurl-devel libxslt-devel libxslt-devel openssl-devel libmcrypt-devel libtool-ltdl-devel gcc gcc-c++ &&\
useradd -r -M -s /sbin/nologin php &&\
tar -xf php-5.3.27.tar.gz &&\
cd php-5.3.27 &&\
./configure \
--prefix=/usr/local/php \
--sysconfdir=/etc/ \
--with-mysql=/usr/local/mysql \
--with-pdo-mysql=mysqlnd \
--with-iconv-dir=/usr/local/libiconv \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir=/usr \
--enable-xml \
--disable-rpath \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--with-curl \
--enable-mbregex \
--enable-fpm \
--enable-mbstring \
--with-mcrypt \
--with-openssl \
--with-gd \
--enable-gd-native-ttf \
--with-openssl \
--with-mhash \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-soap \
--enable-short-tags \
--enable-static \
--with-xsl \
--with-fpm-user=php \
--with-fpm-group=php \
--enable-ftp \
--with-config-file-path=/etc \
--with-config-file-scan-dir=/etc/php.d &&\
make &&\
make install &&\
echo 'PATH=$PATH:/usr/local/php/bin' > /etc/profile.d/php.sh &&\
source /etc/profile.d/php.sh &&\
sed -i "/\/opt\/sbin/a MANPATH_MAP /usr/local/php/bin /usr/local/php/man" /etc/man_db.conf &&\
manpath &&\
ln -sv /usr/local/php/include /usr/include/php &&\
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm &&\
chmod +x /etc/init.d/php-fpm &&\
chkconfig --add php-fpm &&\
cp php.ini-production /etc/php.ini &&\
sed -i -r 's#^(pdo_mysql.default_socket=)#\1/usr/local/mysql/mysql.sock#g' /etc/php.ini && \
sed -i -r 's#^;(date.timezone =)#\1 Asia/Shanghai#g' /etc/php.ini &&\
mv /etc/php-fpm.conf.default /etc/php-fpm.conf &&\
chown php:php /etc/php.ini &&\
chown -R php:php /usr/local/php &&\
sed -i "s#/usr/local/apache2/htdocs#/data/www#g" /etc/httpd/httpd.conf &&\
sed -i 's#DirectoryIndex index.html#DirectoryIndex index.html index.php#g' /etc/httpd/httpd.conf &&\
sed -i 's#^\#LoadModule proxy_module modules/mod_proxy.so#LoadModule proxy_module modules/mod_proxy.so#g' /etc/httpd/httpd.conf &&\
sed -i 's#^\#LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so#LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so#g' /etc/httpd/httpd.conf &&\
sed -i "/<IfModule mime_module>/a \ \ \ \ AddType application/x-httpd-php .php\n AddType applicaiton/x-httpd-php-source .phps" /etc/httpd/httpd.conf &&\
echo -e 'ProxyRequests Off\nProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/data/www/$1' >> /etc/httpd/httpd.conf &&\
sleep 3 &&\
service php-fpm start
service httpd restart
8.3 Wordpress
其实将RS-01的wordpress目录复制过来就行,然后为/data/wordpress/wp-content并挂在共享存储,最后更改一下属主属组为apache,
如果挂在不上需要查看网络原因,可以先安装nfs-utils,然后使用showmount -e 10.0.0.101命令查看可挂载的目录
yum install -y rpcbind &&\
systemctl start rpcbind &&\
systemctl enable rpcbind &&\
mkdir -p /data/www/ &&\
tar -xf wordpress-4.7.4-zh_CN.tar.gz -C /data/www/ &&\
mv /data/www/wordpress/wp-content /data/www/wordpress/wp-content.bak &&\
mkdir /data/www/wordpress/wp-content &&\
chown -R apache: /data/www/wordpress/ &&\
mount -t nfs -o bg,timeo=300,soft,retrans=50,rsize=180000,wsize=180000,rw,noexec,sync 10.0.0.101:/nfsdata/wordpress /data/www/wordpress/wp-content/ &&\
cd /data/www/ &&\
cp wordpress/wp-config-sample.php wordpress/wp-config.php &&\
sed -i 's#database_name_here#wordpress#g' wordpress/wp-config.php &&\
sed -i 's#username_here#wordpress#g' wordpress/wp-config.php &&\
sed -i 's#password_here#123123#g' wordpress/wp-config.php &&\
sed -i 's#localhost#10.0.0.102#g' wordpress/wp-config.php &&\
chown -R apache:apache /data/www/wordpress/
9 故障解决
部署完RS-01的LAMP环境之后,挂载了共享存储作为wordpress的用户上传文件的目录,并且安装了wordpress,然后测试登录,发布文章,发现没问题。
部署完RS-02的LAMP环境之后,挂载了共享存储作为wordpress的用户上传文件的目录,并且安装了wordpress(和RS-01使用的是一个mariadb,RS-02不用再次创建表,支持读取RS-01创建的表),测试登录,发现总是直接跳转到RS-01上(在浏览器里输入10.0.0.102,只要一点击登录或者浏览文章,URL就跳转到了10.0.0.101),而且通过抓包发现了下面这种情况,而且通过查看数据库,发现wordpress数据库中很多表的字段里面都写了RS-01的地址。所以无法实现最初的需求;
下面是解决问题过程中,测试先安装RS-02,然后安装RS-01时抓的报文,这里作为示例
最后解决的方法
上一次部署的时候,我是输入http://10.0.0.101/wordpress/wp-admin/setup-config.php进行安装的。
这回我是输入http://www.example.com/wordpress/wp-admin/setup-config.php进行安装的。
此时www.example.com 对应RS-01的地址10.0.0.101。
部署完成后,发布文档,上传文件。没有问题
将www.example.com对应RS-02的地址10.0.0.102。
查看之前发布的文章,查看之前上传的文件。发布新的文章,都没有问题。
最后配置LVS-NAT。将www.example.com对应LVS的VIP地址,10.207.51.113,调度方式选择成RR(没有选择SH)。
访问www.example.com登录wordpress。发布文章,查看之前的文章,上传的文件。没有问题。
并且session没有问题(这个不清楚为什么,选择的是RR,竟然没有出问题,但是访问速度非常的慢;一旦将模式改为SH或者删除一台主机就访问速度就快了;)
此时收的到的报文
通过查看wordpress创建的表,发现在很多表的字段中,wordpress程序会绑定安装的时候使用的URL,之前绑定了成了http://10.0.0.101/wordpress所以会出现跳转的情况
10 phpMyAdmin
配置比较简单,参考我之前的文章即可;
之后又部署了phpMyAdmin之后,使用LVS-NAT模式,调度方式使用RR,发现每点击几次个页面,或者刷新几次,就会出现出现session过期的情况,更换调度方式为SH后解决问题;
因为Connection: Keep-Alive的原因,所以不是刷新一次就切换一台服务器,如果Connection: closed,就会变成刷新一次换一个服务器了;
11 Discuz
配置比较简单,此处略
最后安装了Discuz,这个软件就不存在wordpres绑定URL的情况;而且这个软件也是在调度模式为RR的时候没有问题,担仍然是很慢,换成SH模式就快了;
LVS-NAT负载均衡PHP应用(Wordpress、Discuz)的更多相关文章
- LVS搭建负载均衡(一)NAT模型
应用场景:LVS配置负载均衡方式之一:nat 测试环境: 测试步骤: 1. 在主机lvs上安装ipvsadm lvs~]# yum install ipvsadm -y lvs~]# ipvsadm ...
- LVS+keepalived负载均衡
背景: 随着你的网站业务量的增长你网站的服务器压力越来越大?需要负载均衡方案!商业的硬件如F5又太贵,你们又是创业型互联公司如何有效节约成本,节省不必要的浪费?同时实现商业硬件一样的高 ...
- LVS+nginx负载均衡知识点1
lvs+nginx负载均衡 1 学习目标 掌握什么是负载均衡及负载均衡的作用和意义. 了解lvs负载均衡的三种模式. 了解lvs-DR负载均衡部署方法. 掌握nginx实现负载均衡的方法. ...
- lvs+nginx负载均衡
1 学习目标 掌握什么是负载均衡及负载均衡的作用和意义. 了解lvs负载均衡的三种模式. 了解lvs-DR负载均衡部署方法. 掌握nginx实现负载均衡的方法. 掌握lvs+nginx负载 ...
- linux 负载均衡配置 keepalive lvs 使用nginx转发 CentOS7 搭建LVS+keepalived负载均衡
最近希望能够配置一下负载均衡,在虚拟机上面,但是网上找了很多资料很零散,对于不了解的人,很多不够详细,最近终于做好了,把具体的步骤写下来,方便各位网友查阅学习 这个实验需要安装nginx如果没有安装过 ...
- MySQL 高可用:mysql+Lvs+Keepalived 负载均衡及故障转移
系统信息: mysql主库 mysql从库 VIP 192.168.1.150 mysql 主主同步都设置 auto-increment-offset,auto-increment-increment ...
- 搞懂分布式技术10:LVS实现负载均衡的原理与实践
搞懂分布式技术10:LVS实现负载均衡的原理与实践 浅析负载均衡及LVS实现 原创: fireflyc 写程序的康德 2017-09-19 负载均衡 负载均衡(Load Balance,缩写LB)是一 ...
- lvs+ipvsadm负载均衡
使用LVS实现负载均衡原理及安装配置详解 负载均衡集群是 load balance 集群的简写,翻译成中文就是负载均衡集群.常用的负载均衡开源软件有nginx.lvs.haproxy,商业的硬件负载均 ...
- 搭建LVS+Keepalived负载均衡集群
这两天学习了LVS+Keepalived负载均衡的搭建.网上的教程非常多,可是动起手来遇到不少问题. 如今把自己的搭建过程以及遇到的一些问题给分享下. 硬件环境: Macbook 8G内存.250G ...
- LVS实现负载均衡原理及安装配置
LVS实现负载均衡原理及安装配置 负载均衡集群是 load balance 集群的简写,翻译成中文就是负载均衡集群.常用的负载均衡开源软件有nginx.lvs.haproxy,商业的硬件负载均衡设备F ...
随机推荐
- bzoj 3824: [Usaco2014 Dec]Guard Mark【状压dp】
设f[s]为已经从上到下叠了状态为s的牛的最大稳定度,转移的话枚举没有在集合里并且强壮度>=当前集合牛重量和的用min(f[s],当前放进去的牛还能承受多种)来更新,高度的话直接看是否有合法集合 ...
- 笔记——malloc、free、不同数据类型操作、.pyc文件、python安装第三方包、验证一个网站的所有链接有效性
C — malloc( ) and free( ) C 语言中使用malloc( )函数申请的内存空间,为什么一定要使用free释放? **malloc()函数功能:是从堆区申请一段连续的空间,函数结 ...
- [POI2009]Kon
Description 火车沿途有N个车站,告诉你从每一站到每一站的人数,现在查票员只能查K次票,每次查票可以控制目前在车上的所有乘客的车票.求一个查票方案,使得控制的不同的乘客尽量多. (显然对同一 ...
- 对比度受限的自适应直方图均衡化(CLAHE)
直方图均衡化(HE)是一种很常用的直方图类方法,基本思想是通过图像的灰度分布直方图确定一条映射曲线,用来对图像进行灰度变换,以达到提高图像 对比度的目的.该映射曲线其实就是图像的累计分布直方图(CDF ...
- 【LeetCode 33】Search in Rotated Sorted Array
Search in Rotated Sorted Array 分段有序的数组,二分查找返回下标,没有返回-1 数组有序之后经过 rotated, 比如:6 1 2 3 4 5 or 5 6 7 8 ...
- python_one-day
python入门_(1) 作者:_晓冬 归档:学习笔记 2017/9/9 目 录 第1章 练习... 1 1.1 格式化输出... 1 1.2 流程控制if..else. 1 1.3 流程控制whi ...
- subprocess模块和sys模块
1.import sys # sys.path # sys.argv # 用来接收python解释器执行py文件后跟的参数#例如:python cp.py argv1 argv2 arg3#sys.a ...
- DOM,javascript,Web API之间的关系——onclick 引起的思考与调研
平时习惯了用js操作dom树来与html页面进行交互,基本都是通过web API接口实现的,最近看闭包和原生js的知识点比较多,昨天无意中看到了onclick中的this指向问题,遂用native j ...
- javascript实现弹层效果
首先,需要有一个按钮来模拟登录: <button id="btnLogin"class="login-btn">登录</button> ...
- Node.js——body方式提交数据
引入核心模块 http,利用其 api(http.createServer) 返回一个 http.server 实例,这个实例是继承于net.Server,net.Server 也是通过net.cre ...