LVS-NAT負載均衡PHP應用(Wordpress、Discuz)

来源:https://www.cnblogs.com/jzbgltb/archive/2019/01/17/10280756.html
-Advertisement-
Play Games

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環境的共用存儲,負責存儲用戶上傳的資源, ...


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


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 1、安裝VM Tools VMware Workstation VM Reinstall VMware Tools 2、Linux不休眠 3、修改IP地址(靜態)與DNS 4、重啟網路服務 5、永久關閉防火牆和Selinux 6、重啟Linux 7、註意事項 (1)查看虛擬機網關與IP地址範圍 (2 ...
  • 秒級隨機值-常用方法: 上面的srand((unsigned)time(NULL));表示給rand()產生隨機值的種子. 其中(unsigned)time(NULL)則將當前時間轉為一個正整數,也就是說,如果我們如果在小於1秒之內多次運行該代碼,則隨機值都是相同的. 編譯運行-如下圖所示,可以看到 ...
  • 1.netstat -nap | grep 埠號 2.第一種的可以查看埠號對應的pid,但是會出現pid為空的情況,這種時候用:lsof -i:埠號 3.根據pid查看埠號 netstat -nap | grep 進程pid 4.查看pid ps aux | grep 進程名 ps -ef ...
  • 環境: HelperA64開發板 Linux3.10內核 時間:2019.01.17 目標:PCF8563實時時鐘驅動的使用 問題:因為pcf8563的驅動是linux內核自帶的,網上也有很多分析的方法,之後再深入分析下pcf的驅動,寫驅動,得首先使用它。 1.以前各大廠商都會有自己的arm架構代碼 ...
  • 如果按照上一篇記錄的那樣,只有本公司的人或者自己才能使用驅動。想寫出一個通用的驅動程式,讓其他應用程式來無縫移植,需要使用現成的驅動——輸入子系統。 /drivers/input/input.c #define EV_SYN 0x00 //同步類#define EV_KEY 0x01 //按鍵類#d ...
  • 在學校里使用校園網,難免會受到限制,比如無論有線網路還是無線網路必須使用客戶端,輸入帳號密碼才行,博主的情況就是這樣,一直苦於Ubuntu 16.04無法連接有線網路,這次由於需要用,所以嘗試各種辦法解決了這個問題。 ...
  • 一 基礎準備 參考《002.Ceph安裝部署》文檔部署一個基礎集群。 二 擴展集群 2.1 擴展架構 需求:添加Ceph元數據伺服器node1。然後添加Ceph Monitor和Ceph Manager node2,node3以提高可靠性和可用性。 2.2 添加元數據(metadata)伺服器 提示 ...
  • 1 #include <linux/module.h> 2 #include <linux/kernel.h> 3 #include <linux/fs.h> 4 #include <linux/init.h> 5 #include <linux/delay.h> 6 #include <linux ...
一周排行
    -Advertisement-
    Play Games
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...