Two Web servers implement Load Balancing + FastCGI module + MySQL implement distributed architecture

Source: Internet
Author: User
Tags php mysql
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.
 
 
  1. Development Tools 
  2. Development Libraries 
  3. #yum  -y groupinstall "Development Libraries"   
1.2 install httpd 2.4.2
 
 
  1. # Yum-y install pcre-devel resolve Dependencies
  2. # Tar xf httpd-2.4.2.tar.bz2
  3. # Cd httpd-2.4.2
  4. # Less INSTALL view installation instructions
  5. $./Configure-- Prefix=PREFIX 
  6. $ Make
  7. $ Make install
  8. $ PREFIX/bin/apachectl start
  9. #./Configure-- Prefix=/Usr/local/apache-- Sysconfdir=/Etc/httpd
  10. -- Enable-so -- enable-rewrite -- with-zlib -- with-pcre
  11. -- With-apr=/Usr/local/apr-- With-apr-util=/Usr/local/apr-util
  12.  -- Enable-modules=Most-- Enable-ssl-- Enable-modules-shared=Most
  13. # Make & make install
1.3 modify the main configuration file of httpd and set the path of its Pid File
 
 
  1. # Vim/etc/httpd. conf
  2. Add idFile "/var/run/httpd. pid"
1.4 provide the SysV service script. The content is as follows: 
 
 
  1. # Vim/Etc/rc. d/init. d/httpd

  2. #! /Bin/bash
  3. #
  4. # Httpd Startup script for the Apache HTTP Server
  5. #
  6. # Chkconfig:-85 15
  7. # Description: Apache is a World Wide Web server. It is used to serve \
  8. # HTML files and CGI.
  9. # Processname: httpd
  10. # Config:/etc/httpd/conf/httpd. conf
  11. # Config:/etc/sysconfig/httpd
  12. # Pidfile:/var/run/httpd. pid
  13. # Source function library.
  14. ./Etc/rc. d/init. d/functions
  15. If [-f/etc/sysconfig/httpd]; then
  16. ./Etc/sysconfig/httpd
  17. Fi
  18. # Start httpd in the C locale by default.
  19. HTTPD_LANG={ {HTTPD_LANG-"C "}
  20. # This will prevent initlog from swallowing up a pass-phrase prompt if
  21. # Mod_ssl needs a pass-phrase from the user.
  22. INITLOG_ARGS="" 
  23. # SetHTTPD=/Usr/sbin/httpd. worker in/etc/sysconfig/httpd to use a server
  24. # With the thread-based "worker" MPM; be warned that some modules may not
  25. # Work correctly with a thread-based MPM; notably PHP will refuse to start.
  26. # Path to the apachectl script, server binary, and short-form for messages.
  27. Apachectl=/Usr/local/apache/bin/apachectl
  28. Httpd=$ {HTTPD-/usr/local/apache/bin/httpd}
  29. Prog=Httpd 
  30. Pidfile=$ {PIDFILE-/var/run/httpd. pid}
  31. Lockfile={ {LOCKFILE-/var/lock/subsys/httpd}
  32. RETVAL=0 
  33. Start (){
  34. Echo-n $ "Starting $ prog :"
  35. LANG= $ HTTPD_LANG daemon-- Pidfile=$ {Pidfile} $ httpd $ OPTIONS
  36. RETVAL= $?
  37. Echo
  38. [$RETVAL=0] & Touch $ {lockfile}
  39. Return $ RETVAL
  40. }
  41. Stop (){
  42. Echo-n $ "Stopping $ prog :"
  43. Killproc-p $ {pidfile}-d 10 $ httpd
  44. RETVAL= $?
  45. Echo
  46. [$RETVAL=0] & Rm-f $ {lockfile }$ {pidfile}
  47. }
  48. Reload (){
  49. Echo-n $ "Reloading $ prog :"
  50. If!LANG= $ HTTPD_LANG $ httpd $ OPTIONS-t>&/Dev/null; then
  51. RETVAL= $?
  52. Echo $ "not reloading due to configuration syntax error"
  53. Failure $ "not reloading $ httpd due to configuration syntax error"
  54. Else
  55. Killproc-p $ {pidfile} $ httpd-HUP
  56. RETVAL= $?
  57. Fi
  58. Echo
  59. }
  60. # See how we were called.
  61. Case "$1" in
  62. Start)
  63. Start
  64. ;;
  65. Stop)
  66. Stop
  67. ;;
  68. Status)
  69. Status-p $ {pidfile} $ httpd
  70. RETVAL= $?
  71. ;;
  72. Restart)
  73. Stop
  74. Start
  75. ;;
  76. Condrestart)
  77. If [-f $ {pidfile}]; then
  78. Stop
  79. Start
  80. Fi
  81. ;;
  82. Reload)
  83. Reload
  84. ;;
  85. Graceful | help | configtest | fullstatus)
  86. $ Apachectl $ @
  87. RETVAL= $?
  88. ;;
  89. *)
  90. Echo $ "Usage: $ prog {start | stop | restart | condrestart | reload | status | fullstatus | graceful | help | configtest }"
  91. Exit 1
  92. Esac
  93. Exit $ RETVAL
  94. # Chmod + x/etc/rc. d/init. d/httpd grant the execution right to this script
  95. # Chkconfig -- add httpd to the service list:
1.5 install the apache fastcgi module:
 
 
  1. # Tar-zxvf mod_fastcgi-current.tar.gz
  2. # Cd mod_fastcgi
  3. # Cp Makefile. AP2 Makefile
  4. # Vim Makefile ModificationTop_dir=/Usr/local/apache # Your apache installation path
  5. # Make
  6. # Make install
1.6 modify the configuration file so that apache supports php-fpm 
 
 
  1. Added: LoadModule fastcgi_module modules/mod_fastcgi.so
  2. If yes, you do not need to add it.
  3. ScriptAlias/cgi-bin/"/usr/local/php/bin /"
  4. FastCgiExternalServer/usr/local/php/bin/php-fpm-Host 172.16.2.3: 9000
  5. AddType application/x-httpd-php. php
  6. AddHandler php-fastcgi. php
  7. Action php-fastcgi/cgi-bin/php-fpm
  8. <Directory"/Usr/local/php/bin /">
  9. Options-Indexes FollowSymLinks + ExecCGI
  10. Order allow, deny
  11. Allow from all
  12. Directory>
Related Article

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.