Two Web servers implement Load Balancing + FastCGI module + MySQL implement distributed architecture Operating System: RedHat5.8 test environment preparation: three servers Server1IP: 172.16.2.1 install: apacheNFS
Two Web servers implement Load Balancing + FastCGI module + MySQL implement distributed architecture
Operating System: RedHat 5.8
Test Environment preparation: Three servers 1 IP Address: 172.16.2.1 installation: apache NFSServer 2 IP Address: 172.16.2.2 installation: apache DNS Server 3 IP Address: 172. 16 .. 2.3 installation: php mysql
The experiment diagram is as follows::
650) this. width = 650; "border = 0>
Working principle:1. When the client requests the DNS on www.tast.com 2 and Server 2, the requests will be forwarded to 172.16.2.1 and 172.16.2.2 through polling. If the request is a static page web service, the results will be returned directly customer, if it is a dynamic page, it will be transferred to php parsing on server 3 4. If you need to use database data, access the database through the database interface. 5. The results are returned to the front-end web6 after Php resolution. The Web returns the results to the customer.
Procedure1. configure server 1 to install and configure apache and NFS 2, configure server 2 to install and configure apache and DNS3, and configure server 3 to install and configure mysql and php 4. Summary Note: This test only provides you with a way of thinking. You can configure it in this way. Different requirements, operating systems, and software versions vary with your actual needs, the configuration process may be slightly different, but the principles are all figured out. I hope you don't forget to think about it while doing the experiment. If you do not think about it, you will understand the principle, we can build services that suit our needs.
Process:
1. configure server 1
1.1 configure the compiling and installation environmentIn this test, each software is compiled and installed, so each server must first configure the compiling and installation environment to ensure the installation of these two groups.
- Development Tools
- Development Libraries
- #yum -y groupinstall "Development Libraries"
1.2 install httpd 2.4.2
- # Yum-y install pcre-devel resolve Dependencies
- # Tar xf httpd-2.4.2.tar.bz2
- # Cd httpd-2.4.2
- # Less INSTALL view installation instructions
- $./Configure-- Prefix=PREFIX
- $ Make
- $ Make install
- $ PREFIX/bin/apachectl start
- #./Configure-- Prefix=/Usr/local/apache-- Sysconfdir=/Etc/httpd
- -- Enable-so -- enable-rewrite -- with-zlib -- with-pcre
- -- With-apr=/Usr/local/apr-- With-apr-util=/Usr/local/apr-util
- -- Enable-modules=Most-- Enable-ssl-- Enable-modules-shared=Most
- # Make & make install
1.3 modify the main configuration file of httpd and set the path of its Pid File
- # Vim/etc/httpd. conf
- Add idFile "/var/run/httpd. pid"
1.4 provide the SysV service script. The content is as follows:
# Vim/Etc/rc. d/init. d/httpd
- #! /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/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=""
- # SetHTTPD=/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/apachectl
- Httpd=$ {HTTPD-/usr/local/apache/bin/httpd}
- Prog=Httpd
- Pidfile=$ {PIDFILE-/var/run/httpd. pid}
- Lockfile={ {LOCKFILE-/var/lock/subsys/httpd}
- RETVAL=0
- Start (){
- 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 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 "$1" 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 $ @
- RETVAL= $?
- ;;
- *)
- Echo $ "Usage: $ prog {start | stop | restart | condrestart | reload | status | fullstatus | graceful | help | configtest }"
- Exit 1
- Esac
- Exit $ RETVAL
- # Chmod + x/etc/rc. d/init. d/httpd grant the execution right to this script
- # Chkconfig -- add httpd to the service list:
1.5 install the apache fastcgi module:
- # Tar-zxvf mod_fastcgi-current.tar.gz
- # Cd mod_fastcgi
- # Cp Makefile. AP2 Makefile
- # Vim Makefile ModificationTop_dir=/Usr/local/apache # Your apache installation path
- # Make
- # Make install
1.6 modify the configuration file so that apache supports php-fpm
- Added: LoadModule fastcgi_module modules/mod_fastcgi.so
- If yes, you do not need to add it.
- ScriptAlias/cgi-bin/"/usr/local/php/bin /"
- FastCgiExternalServer/usr/local/php/bin/php-fpm-Host 172.16.2.3: 9000
- AddType application/x-httpd-php. php
- AddHandler php-fastcgi. php
- Action php-fastcgi/cgi-bin/php-fpm
- <Directory"/Usr/local/php/bin /">
- Options-Indexes FollowSymLinks + ExecCGI
- Order allow, deny
- Allow from all
- Directory>