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模式就快了;

猜你喜欢

转载自www.cnblogs.com/jzbgltb/p/10280756.html