Simple case for load balancing of two Web servers with Lvs-nat

Source: Internet
Author: User
Tags phpinfo

write in front: If this article is fortunate enough to be seen by a friend and found wrong, I hope to criticize. If you do not understand the place, we would like to discuss together.


Case topology diagram

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/4B/6B/wKioL1Qr7wKQvEOsAAGJSJ4upk0858.jpg "title=" Figure 1 "alt = "Wkiol1qr7wkqveosaagjsj4upk0858.jpg"/>

Configuring Host 1

Installing Ipvsadm

# yum-y Install ipvsadm# ipvsadm-a-T 10.170.2.80:80-s rr# ipvsadm-a-t 10.170.2.80:80-r 192.168.3.101-m# ipvsadm-a -T 10.170.2.80:80-r 192.168.3.102-m# echo 1 >/proc/sys/net/ipv4/ip_forward

Configuring Subjects 2 and 3

Compiling and installing apr-1.5.0

# Tar XF apr-1.5.0.tar.bz2# cd apr-1.5.0#./configure--prefix=/usr/local/apr# make && make install

Compiling and installing apr-util-1.5.3

# tar XF apr-util-1.5.3.tar.bz2 # cd apr-util-1.5.3 #./configure--prefix=/usr/local/apr-util--WITH-APR=/USR/LOCAL/APR /# make && make install

Compiling and installing httpd-2.4.9

# tar XF httpd-2.4.9.tar.bz2 # cd httpd-2.4.9#./configure--prefix=/usr/local/apache--sysconfdir=/etc/httpd24-- Enable-so--enable-ssl--enable-cgi--enable-rewrite--with-zlib--with-pcre--with-apr=/usr/local/apr--with-apr- Util=/usr/local/apr-util--enable-modules=most--enable-mpms-shared=all--with-mpm=event# make && make Insta ll

Modify the httpd Master profile to set the path of the PID file

# vim/etc/httpd24/httpd.conf

Add a line below the ServerRoot "/usr/local/apache" line:

Pidfile "/var/run/httpd.pid"

SysV Service Script/etc/rc.d/init.d/httpd24 is provided, this file needs to be created

# VIM/ETC/RC.D/INIT.D/HTTPD24
#!/bin/bash## httpd        startup script for the  apache http server## chkconfig: - 85 15# description: apache  is a world wide web server.  it is used to serve  #        html files and cgi.# processname:  httpd# config: /etc/httpd/conf/httpd.conf# config: /etc/sysconfig/httpd#  Pidfile: /var/run/httpd.pid# source function library.  /etc/rc.d/init.d/functionsif [ -f /etc/sysconfig/httpd ]; then         . /etc/sysconfig/httpdfi# 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/apache/bin/apachectlhttpd=${httpd-/usr/local/apache/bin/httpd}prog=httpdpidfile=${pidfile-/var/run/ Httpd.pid}lockfile=${lockfile-/var/lock/subsys/httpd}retval=0start ()  {         echo -n $ "starting  $prog: "          lang= $HTTPD _lang daemon --pidfile=${pidfile}  $httpd   $OPTIONS         RETVAL=$?         echo        [  $RETVAL  =  0 ] && touch ${lockfile}         return  $RETVAL}stop ()  {  echo -n $ "stopping  $prog: "    killproc -p ${pidfile} -d 10  $httpd   retval=$?  echo  [   $RETVAL  = 0 ] && rm -f ${lockfile} ${pidfile}}reload ()  {    echo -n $ "reloading  $prog: "     if  ! lang= $HTTPD _lang  $httpd   $OPTIONS  -t >&/dev/null; then         retval=$?        echo $ "not  reloading due to&Nbsp;configuration syntax error "        failure $" not  reloading  $httpd  due to configuration syntax error "     else        killproc -p ${pidfile}  $httpd  - hup        retval=$?    fi     echo}# see how we were called.case  "$"  in  start)    start  ;;   stop)   stop  ;;   status)         status -p ${pidfile}  $httpd   RETVAL=$?  ;;   restart)   stop  start  ;;   condrestart)   if [ -f ${pidfile} ] ; then     stop    start  fi  ;;   reload)         reload  ;;   graceful|help|configtest|fullstatus)    $apachectl  [email protected]   retval=$?  ;;   *)   echo $ "usage:  $prog  {start|stop|restart|condrestart|reload|status| Fullstatus|graceful|help|configtest} "  exit 1esacexit  $RETVAL
# chmod +X/ETC/RC.D/INIT.D/HTTPD24 # chkconfig--add httpd24# chkconfig httpd24 on

Start the HTTP24 service and test

# service HTTPD24 Start

Add different pages on host 2 and host 3

Host 2

# vim/usr/local/apache/htdocs/test.html 

Host 3

# vim/usr/local/apache/htdocs/test.html 

Type 10.170.2.80/test.html in the browser and refresh to get different results

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/4B/6B/wKioL1Qr7UCxB_xVAAC5Sn8-TVw411.jpg "title=" Figure 2 "alt = "Wkiol1qr7ucxb_xvaac5sn8-tvw411.jpg"/>

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/4B/6B/wKioL1Qr7VGDDAnWAAC6xwTd4C0262.jpg "title=" Figure 3 "alt = "Wkiol1qr7vgddanwaac6xwtd4c0262.jpg"/>

Compiling and installing php-5.4.26

# Tar XF php-5.4.26.tar.bz2# cd php-5.4.26#./configure--prefix=/usr/local/php--with-mysql=mysqlnd--with-openssl-- With-mysqli=mysqlnd--enable-mbstring--with-freetype-dir--with-jpeg-dir--with-png-dir--with-zlib-- WITH-LIBXML-DIR=/USR--enable-xml--enable-sockets--with-apxs2=/usr/local/apache/bin/apxs--with-mcrypt--with-con Fig-file-path=/etc--with-config-file-scan-dir=/etc/php.d--with-bz2--enable-maintainer-zts# make && do in Stall

Provide a configuration file for PHP

# CP Php.ini-production/etc/php.ini

Edit the httpd configuration file to support PHP

# vim/etc/httpd24/httpd.conf
Add the following two lines below the AddType application/x-gzip. GZ tgz Line: AddType application/x-httpd-php. Phpaddtype application/ X-httpd-php-source. Phps DirectoryIndex index.html This line to: DirectoryIndex index.php index.html

Add a test page to host 2 and host 3

Host 2

# vim/usr/local/apache/htdocs/index.php 

Host 3

# vim/usr/local/apache/htdocs/index.php 

Restart the HTTPD24 service for Host 2 and host 3

# Service HTTPD24 Restart

Type 10.170.2.80 in the browser, refresh to get different results

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/4B/69/wKiom1Qr8n-DnJGHAAEFGjzRLDk932.jpg "title=" Figure 4 "alt = "Wkiom1qr8n-dnjghaaefgjzrldk932.jpg"/>

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/4B/69/wKiom1Qr8ryxE35bAAENfyx4ht4669.jpg "title=" Figure 5 "alt = "Wkiom1qr8ryxe35baaenfyx4ht4669.jpg"/>


Configuring host 4

Compiling and installing mariadb-5.5.36

# tar XF mariadb-5.5.36-linux-x86_64.tar.gz-c/usr/local# cd/usr/local/# ln-sv mariadb-5.5.36-linux-x86_64/mysql# Mkdi r-pv/mysql/data# groupadd-r mysql# useradd-g mysql-s/sbin/nologin-m-d/mysql/data-r mysql# chown-r mysql:mysql/ mysql# Chown-r Mysql:mysql/mysql/data

To provide a configuration file for the database:

# CD mysql# mkdir/etc/mysql# chown-r root.mysql./*# cp support-files/my-large.cnf/etc/mysql/my.cnf Modify File/etc/mysql/my.c NF file content, add a line under Thread_concurrency = 8 line: DataDir =/mysql/data

Provide a SysV startup script for the database and set it to boot:

# CP support-files/mysql.server/etc/init.d/mysqld# chkconfig--add mysqld# chkconfig mysqld on

Initialize the database and start the database:

# echo "Export Path=/usr/local/mysql/bin: $PATH" >/etc/profile.d/mysql.sh# source/etc/profile.d/mysql.sh # echo "/ Usr/local/mysql/lib ">/etc/ld.so.conf.d/mysql.conf# ldconfig# ln-sv/usr/local/mysql/include//usr/include/mysql # scripts/mysql_install_db--user=mysql--datadir=/mysql/data/#/etc/init.d/mysqld start

Create a database and authorize:

MariaDB [(None)]> CREATE DATABASE discuz; MariaDB [(None)]> GRANT all on discuz.* to [e-mail protected] ' 192.168.3.% ' identified by ' dscpass '; MariaDB [(None)]> FLUSH privileges;

Start the NFS sharing service

# useradd-u discuz# vim/etc/exports/var/www/html 192.168.3.0/24 (rw,no_root_squash) #/etc/init.d/rpcbind start#/ Etc/init.d/nfs start#/etc/init.d/nfslock Start

Unzip the DISCUZ_X2.5_SC_GBK to/var/www/html and modify the permissions

# unzip Discuz_x2.5_sc_gbk.zip. # CD upload# chmod-r go+w config# chmod-r go+w data# chmod-r go+w uc_*

Build a test environment and test

Related configuration on Host 2 and host 3

# useradd-u discuz# mount-f NFS 192.168.3.36:/var/www/html/usr/local/apache/htdocs

Type 10.170.2.80/upload in the browser to get the Installation Discuz forum page

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/4B/69/wKiom1Qr9grC4-qbAAP1ZIPKE04192.jpg "title=" Figure 6 "alt = "Wkiom1qr9grc4-qbaap1zipke04192.jpg"/>

Click "I agree"-click "Next"-click "Next"-based on the database authorization information, fill in "Install Database Contents" and then click "Next"-after the successful installation of the database, click on "Temporarily not open" on the displayed page to get the forum page

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/4B/69/wKiom1Qr97ODB0QjAAGWxZRhRn4356.jpg "title=" Figure 7 "alt = "Wkiom1qr97odb0qjaagwxzrhrn4356.jpg"/>


Simple case for load balancing of two Web servers with Lvs-nat

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.