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