微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

单一nginx负载均衡+LNMP分布式架构

   随着互联网的快速发展,我们的web站点访问量和数据流量的快速增长,对于我们服务器的处理能里的要求也越来越高,这样的情况下,单一的服务器根本无法承受, 这样的话我们丢弃掉原有的设备,做硬件升级,会造成成本的浪费,如果再过一段时间,升级过后的硬件有负载不起了,怎么办呢?没关系,我们有负载均衡的技术,就不用担心了!
   负载均衡通俗点说,就是一堆的计算机,或设备,同时为用户提供一个相同的服务,下面就来说说怎么实现的!
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
首先在此感谢,"马哥"以及网友"IT你好" 的帮助,一路走来,问题不断,感谢朋友们的支持,再次表示谢谢,“刘庸有句话说的好,(人在黑暗既又邪恶的道路上成长,才能使自己变的更加强大)” 我想表达的意思就是,在学习的过程中遇到的问题越多,那么自己就积累的越多,当然对于那些勇于克服问题的童鞋而言,呵呵,闲话有点多了,下面来介绍下单一的Nginx负载均衡是怎么工作的,
单一Nginx负载均衡,见下图,

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1,首先用户发送请求访问bbs.andy.com,
2,当前端Nginx负载均衡服务器(上图中的SVR1)收到用户的请求之后,Nginx负载均衡器,会根据此前配置好的调度算法,代用户请求后端的应用程序服务器,
3,应用程序服务器(也就是上图中的SVR2,3,4) 收到前端Nginx负载均衡器的请求的时候,它并不知道是Nginx负载均衡器是代用户请求的,对于后端的应用程序服务器而言前端Nginx负载均衡器就是一个用户,那么它收到请求之后,将对应请求的处理结果,再返回给前端Nginx负载均衡器,
4,当前端的Nginx负载均衡器,收到后端应用程序服务器返回的响应内容之后再讲结果返回给用户,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
应该是这样工作的吧,个人的理解,说的不好,还望大家伙指点,下面来说说LNMP分布式架构是怎么工作的,也就是上图啦,待会的配置也是根据上图的架构来配置的,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
LNMP分布式架构的工作原理,根据上图来,
1,用户请求bbs.andy.com
2,前端Nginx负载均衡器收到用户请求,根据此前设定的调度算法,假如说此时前端Nginx负载均衡器,根据调度算法的结果,应该访问svr2,这台应用程序服务器,那么svr2这台服务器根据用户请求的内容的不同,而进行不同的处理机制,根据上图的架构一般有两种可能,
         当用户请求的内容一个静态的html页面的话,那么svr2,就直接将请求的结果响应给前端Nginx负载均衡器,
         当用户请求的内容一个动态的页面内容(在上图中也就是PHP页面了)那么svr2会去找svr4上面的FastCGI程序来帮忙解析动态PHP页面,如果此次页面请求中需要访问数据库的话,fastcgi会通过MysqL的接口访问数据库的,然后将其请求的结果,返回给svr2,
               当svr2收到返回的请求结果后,svr2再将结果返回给前端的Nginx负载均衡器,当前端的Nginx负载均衡器收到请求的结果后,再将其返回给用户,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
下面来配置下在Nginx负载均衡的情况下,后端的LNMP应用服务器分布式架构,下面再简单介绍下上图中每台服务器的角色,已经IP地址,等信息,

服务器             角色                                IP地址                       DNS能解析的域名
SVR1       Nginx负载均衡器     192.168.0.52/172.16.0.1     bbs.andy.com解析到192.168.0.52
SVR2               Nginx                            172.16.0.2
SVR3               Nginx/NFS                    172.16.0.3
SVR4           PHP(FastCGI)/MysqL     172.16.0.4
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
SVR1负责接受用户请求,根据调度算法,负载到SVR2 SVR3上面去,
SVR3上面有个NFS服务,是提供共享存储的,这里主要是共享网站的源码
SVR4 PHP(FastCGI)提供SVR2 SVR3的动态PHP页面的请求, 
SVR4 MysqL数据库提供SVR4上的PHP(FastCGI)的数据请求等,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

单一Nginx负载均衡+LNMP分布式架构  rhel5.8的系统上实现

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
目录
一,安装配置SVR4
二,安装配置SVR3
三,安装配置SVR2
四,安装配置SVR1
注:配置过程中需要用到的源码包,自己在官方下载,所有包下载至系统的/usr/src目录
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
一,安装配置SVR4
1.安装基本开发库,等依赖软件包

 
 
  1. #yum -y groupinstall "Development Libraries"  "Development Tools" "X Software Development" 

2.安装配置MysqL
2.1 编译安装MysqL

 
 
  1. #cd /usr/src 
  2. #tar xzvf MysqL-5.0.56.tar.gz  
  3. #cd MysqL-5.0.56 
  4. #./configure --prefix=/usr/local/MysqL --sysconfdir=/usr/local/MysqL/etc --with-ssl \ 
  5. --localstatedir=/usr/local/MysqL/database --enable-assembler --with-readline \ 
  6. --with-extra-charsets=complex --enable-thread-safe-client --with-big-tables \ 
  7. --with-embedded-server --enable-local-infile --with-plugins=innobase 
  8. #make && make install 

2.2 将MySQL命令加入到系统搜索路径

 
 
  1. #vim /etc/profile 
  2. PATH=/usr/local/MysqL/bin:$PATH   将次行添加文件中的44行 
  3. #export PATH=/usr/local/MysqL/bin:$PATH 

2.3 将头文件添加到系统搜索路径

 
 
  1. #ln -s /usr/local/MysqL/include/MysqL /usr/include/MysqL 

2.4 将库文件添加到系统搜索路径

 
 
  1. #echo “/usr/local/MysqL/lib/MysqL”   > /etc/ld.so.conf.d/MysqL.conf 
  2. #ldconfig 

2.5 为MysqL提供配置文件,服务启动脚本,用户,并初始化MysqL

 
 
  1. #cp support-files/my-huge.cnf /etc/my.cnf 
  2. #cp support-files/MysqL.server /etc/init.d/MysqL
  3. #chmod a+x /etc/init.d/MysqL
  4. #useradd -s /sbin/nologin MysqL 
  5. #chown -R MysqL:MysqL /usr/local/MysqL 
  6. #MysqL_install_db --user=MysqL 
  7. #chkconfig --add MysqL
  8. #chkconfig MysqLd on 
  9. #service MysqLd restart 

3,安装配置PHP(FastCGI)
3.1 编译安装libiconv 编码转换库

 
 
  1. #cd /usr/src 
  2. #tar xzvf libiconv-1.13.1.tar.gz 
  3. #cd libiconv-1.13.1 
  4. #./configure --prefix=/usr/local 
  5. #make && make install 

3.2 编译安装libmcryp加密算法扩展库

 
 
  1. #cd /usr/src 
  2. #tar xjvf libmcrypt-2.5.8.tar.bz2 
  3. #cd libmcrypt-2.5.8 
  4. #./configure 
  5. #make 
  6. #make install 
  7. #ldconfig 
  8. #cd libltdl/ 
  9. #./configure --enable-ltdl-install 
  10. #make && make install 

3.3 编译安装mhash加密算法扩展库

 
 
  1. #cd /usr/src 
  2. #tar xjvf mhash-0.9.9.9.tar.bz2 
  3. #cd mhash-0.9.9.9 
  4. #./configure 
  5. #make && make install 
  6. #ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la 
  7. #ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so 
  8. #ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4 
  9. #ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8 
  10. #ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.a 
  11. #ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la 
  12. #ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.so 
  13. #ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2 
  14. #ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1 

3.4 编译安装mcrypt 加密算法工具

 
 
  1. #cd /usr/src 
  2. #tar xzvf mcrypt-2.6.8.tar.gz 
  3. #cd mcrypt-2.6.8 
  4. #./configure 
  5. #make && make install 

3.5 编译安装PHP(FastCGI) 这里使用的是5.4的版本,5.4的版本不需要打fpm补丁就支持FastCGI
3.5.1 编译安装PHP

 
 
  1. #cd /usr/src 
  2. #tar xjvf PHP-5.4.4.tar.bz2 
  3. #cd PHP-5.4.4 
  4. #./configure --prefix=/usr/local/PHP --with-MysqL=/usr/local/MysqL/ --with-openssl \
  5. --enable-fpm --enable-sockets --enable-sysvshm --with-MysqLi=/usr/local/MysqL/bin/MysqL_config\
  6. --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib-dir \
  7. --with-libxml-dir=/usr/ --enable-xml --with-mhash --with-mcrypt --with-config-file-path=/etc \
  8. --with-config-file-scan-dir=/etc/PHP.d --with-bz2 --with-curl --with-ldap --with-iconv-dir  
  9. #make  ZEND_EXTRA_LIBS='-liconv' 
  10. #make install 

3.5.2 为PHP-fpm提供配置文件,服务启动脚本等,

 
 
  1. #cp PHP.ini-production /etc/PHP.ini 
  2. #cp sapi/fpm/init.d.PHP-fpm  /etc/rc.d/init.d/PHP-fpm 
  3. #chmod +x /etc/rc.d/init.d/PHP-fpm 
  4. #chkconfig --add PHP-fpm 
  5. #chkconfig PHP-fpm on 
  6. #cp /usr/local/PHP/etc/PHP-fpm.conf.default /usr/local/PHP/etc/PHP-fpm.conf  
  7. #vim /usr/local/PHP/etc/PHP-fpm.conf  修改内容如下 
  8. pid = /usr/local/PHP/var/run/PHP-fpm.pid 
  9. listen = 172.16.0.4:9000
  10. pm.max_children = 50 
  11. pm.start_servers = 5 
  12. pm.min_spare_servers = 2 
  13. pm.max_spare_servers = 8 
  14. #service PHP-fpm start 


二,安装配置SVR3
1.安装基本开发库,及依赖软件包

 
 
  1. #yum groupinstall "Development Libraries"  "Development Tools" 
  2. #yum -y install pcre-devel 

2.安装配置Nginx
2.1 编译安装Nginx

 
 
  1. #useradd -s /sbin/nologin Nginx 
  2. #cd /usr/src 
  3. #tar xzvf Nginx-1.2.2.tar.gz 
  4. #cd Nginx-1.2.2 
  5. #./configure --prefix=/usr/local/Nginx --pid-path=/var/run/Nginx/Nginx.pid \ 
  6. --lock-path=/var/lock/Nginx.lock --user=Nginx --group=Nginx --with-http_ssl_module \ 
  7. --with-http_flv_module --with-http_stub_status_module --with-http_gzip_static_module \ 
  8. --http-client-body-temp-path=/var/tmp/Nginx/client/ --http-proxy-temp-path=/var/tmp/Nginx/proxy \ 
  9. --http-fastcgi-temp-path=/var/tmp/Nginx/fcgi --http-uwsgi-temp-path=/var/tmp/Nginx/uwsgi \ 
  10. --http-scgi-temp-path=/var/tmp/Nginx/scgi --with-pcre 
  11. #make && make install 

2.2 为Nginx提供服务启动脚本

 
 
  1. #vim /etc/rc.d/init.d/Nginx  内容如下 
  2. #!/bin/sh 
  3. Nginx - this script starts and stops the Nginx daemon 
  4. # chkconfig:   - 85 15  
  5. # description:  Nginx is an HTTP(S) server, HTTP(S) reverse \ 
  6. #               proxy and IMAP/POP3 proxy server 
  7. # processname: Nginx 
  8. # config:      /etc/Nginx/Nginx.conf 
  9. # config:      /etc/sysconfig/Nginx 
  10. # pidfile:     /var/run/Nginx.pid 
  11.   
  12. # Source function library. 
  13. . /etc/rc.d/init.d/functions 
  14.   
  15. # Source networking configuration. 
  16. . /etc/sysconfig/network 
  17.   
  18. # Check that networking is up. 
  19. [ "$NETWORKING" = "no" ] && exit 0 
  20.   
  21. Nginx="/usr/local/Nginx/sbin/Nginx" 
  22. prog=$(basename $Nginx
  23.   
  24. Nginx_CONF_FILE="/usr/local/Nginx/conf/Nginx.conf" 
  25.   
  26. [ -f /etc/sysconfig/Nginx ] && . /etc/sysconfig/Nginx 
  27.   
  28. lockfile=/var/lock/subsys/Nginx 
  29.   
  30. make_dirs() { 
  31.    # make required directories 
  32.    user=`Nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -` 
  33.    options=`$Nginx -V 2>&1 | grep 'configure arguments:'` 
  34.    for opt in $options; do 
  35.        if [ `echo $opt | grep '.*-temp-path'` ]; then 
  36.            value=`echo $opt | cut -d "=" -f 2` 
  37.            if [ ! -d "$value" ]; then 
  38.                # echo "creating" $value 
  39.                mkdir -p $value && chown -R $user $value 
  40.            fi 
  41.        fi 
  42.    done 
  43.   
  44. start() { 
  45.     [ -x $Nginx ] || exit 5 
  46.     [ -f $Nginx_CONF_FILE ] || exit 6 
  47.     make_dirs 
  48.     echo -n $"Starting $prog: " 
  49.     daemon $Nginx -c $Nginx_CONF_FILE 
  50.     retval=$? 
  51.     echo 
  52.     [ $retval -eq 0 ] && touch $lockfile 
  53.     return $retval 
  54.   
  55. stop() { 
  56.     echo -n $"Stopping $prog: " 
  57.     killproc $prog -QUIT 
  58.     retval=$? 
  59.     echo 
  60.     [ $retval -eq 0 ] && rm -f $lockfile 
  61.     return $retval 
  62.   
  63. restart() { 
  64.     configtest || return $? 
  65.     stop 
  66.     sleep 1 
  67.     start 
  68.   
  69. reload() { 
  70.     configtest || return $? 
  71.     echo -n $"Reloading $prog: " 
  72.     killproc $Nginx -HUP 
  73.     RETVAL=$? 
  74.     echo 
  75.   
  76. force_reload() { 
  77.     restart 
  78.   
  79. configtest() { 
  80.   $Nginx -t -c $Nginx_CONF_FILE 
  81.   
  82. rh_status() { 
  83.     status $prog 
  84.   
  85. rh_status_q() { 
  86.     rh_status >/dev/null 2>&1 
  87.   
  88. case "$1" in 
  89.     start) 
  90.         rh_status_q && exit 0 
  91.         $1 
  92.         ;; 
  93.     stop) 
  94.         rh_status_q || exit 0 
  95.         $1 
  96.         ;; 
  97.     restart|configtest) 
  98.         $1 
  99.         ;; 
  100.     reload) 
  101.         rh_status_q || exit 7 
  102.         $1 
  103.         ;; 
  104.     force-reload) 
  105.         force_reload 
  106.         ;; 
  107.     status) 
  108.         rh_status 
  109.         ;; 
  110.     condrestart|try-restart) 
  111.         rh_status_q || exit 0 
  112.             ;; 
  113.     *) 
  114.         echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}" 
  115.         exit 2 
  116. esac 
  117.  
  118.  
  119. #chmod a+x /etc/init.d/Nginx 
  120. #chkconfig --add Nginx 
  121. #chkconfig Nginx on 

2.3 编辑Nginx的主配置文件

 
 
  1. #vim /usr/local/Nginx/conf/Nginx.conf  内容如下 
  2. user  Nginx
  3. worker_processes  10; 
  4. error_log  logs/error.log crit; 
  5. pid        logs/Nginx.pid; 
  6. events 
  7.   use epoll; 
  8.   worker_connections 51000; 
  9. http { 
  10.     include       mime.types; 
  11.     default_type  application/octet-stream; 
  12.         client_header_buffer_size 32k; 
  13.         large_client_header_buffers 4 32k; 
  14.         client_max_body_size 10m; 
  15.     sendfile        on; 
  16.     tcp_nopush     on; 
  17.     keepalive_timeout  60; 
  18.     tcp_nodelay on; 
  19.         fastcgi_connect_timeout 300; 
  20.         fastcgi_send_timeout 300; 
  21.         fastcgi_read_timeout 300; 
  22.         fastcgi_buffer_size 64k; 
  23.         fastcgi_buffers 4 64k; 
  24.         fastcgi_busy_buffers_size 128k; 
  25.         fastcgi_temp_file_write_size 128k; 
  26.         gzip on; 
  27.         gzip_min_length 1k; 
  28.         gzip_buffers    4 16k; 
  29.         gzip_http_version 1.0; 
  30.         gzip_comp_level 2; 
  31.         gzip_types      text/plain application/x-javascript text/ccs application/xml; 
  32.         gzip_vary on; 
  33.         server { 
  34.                 listen       80; 
  35.                 server_name  172.16.0.3; 
  36.                 index index.html index.htm index.PHP
  37.                 root /web/bbs; 
  38.                 location ~ .*\.(PHP|PHP5)?$ 
  39.                 { 
  40.                 fastcgi_pass    172.16.0.4:9000; 
  41.                 fastcgi_index index.PHP
  42.                 fastcgi_param SCRIPT_FILENAME /web/bbs$fastcgi_script_name; 
  43.                 include fastcgi.conf; 
  44.                 } 
  45.                 access_log      logs/bbs.log; 
  46.  
  47.         } 

2.4 创建网站根目录以及测试文件

 
 
  1. #mkdir -pv /web/bbs 
  2. #vim /web/bbs/index.PHP 
  3. <h1>test</h1> 
  4. <?PHP 
  5. PHPinfo(); 
  6. ?> 

2.5 启动Nginx服务

 
 
  1. #service Nginx restart 


3,配置NFS

 
 
  1. #vim /etc/exports  
  2. /web 172.16.0.*(rw,no_root_squash,sync) 
  3.  
  4. #chkconfig portmap on 
  5. #chkconfig nfs on 
  6. #service portmap restart 
  7. #service nfs restart 


三,安装配置SVR2

1.安装基本开发库,及依赖软件包

 
 
  1. #yum groupinstall "Development Libraries"  "Development Tools" 
  2. #yum -y install pcre-devel 

2.安装配置Nginx
2.1 编译安装Nginx

 
 
  1. #useradd -s /sbin/nologin Nginx 
  2. #cd /usr/src 
  3. #tar xzvf Nginx-1.2.2.tar.gz 
  4. #cd Nginx-1.2.2 
  5. #./configure --prefix=/usr/local/Nginx --pid-path=/var/run/Nginx/Nginx.pid \ 
  6. --lock-path=/var/lock/Nginx.lock --user=Nginx --group=Nginx --with-http_ssl_module \ 
  7. --with-http_flv_module --with-http_stub_status_module --with-http_gzip_static_module \ 
  8. --http-client-body-temp-path=/var/tmp/Nginx/client/ --http-proxy-temp-path=/var/tmp/Nginx/proxy \ 
  9. --http-fastcgi-temp-path=/var/tmp/Nginx/fcgi --http-uwsgi-temp-path=/var/tmp/Nginx/uwsgi \ 
  10. --http-scgi-temp-path=/var/tmp/Nginx/scgi --with-pcre 
  11. #make && make install 

2.2 为Nginx提供服务启动脚本

 
 
  1. 见 二.2.2 的配置内容

2.3 编辑Nginx的主配置文件

 
 
  1. #vim /usr/local/Nginx/conf/Nginx.conf  内容如下 
  2. user  Nginx
  3. worker_processes  10; 
  4. error_log  logs/error.log crit; 
  5. pid        logs/Nginx.pid; 
  6. events 
  7.   use epoll; 
  8.   worker_connections 51000; 
  9. http { 
  10.     include       mime.types; 
  11.     default_type  application/octet-stream; 
  12.         client_header_buffer_size 32k; 
  13.         large_client_header_buffers 4 32k; 
  14.         client_max_body_size 10m; 
  15.     sendfile        on; 
  16.     tcp_nopush     on; 
  17.     keepalive_timeout  60; 
  18.     tcp_nodelay on; 
  19.         fastcgi_connect_timeout 300; 
  20.         fastcgi_send_timeout 300; 
  21.         fastcgi_read_timeout 300; 
  22.         fastcgi_buffer_size 64k; 
  23.         fastcgi_buffers 4 64k; 
  24.         fastcgi_busy_buffers_size 128k; 
  25.         fastcgi_temp_file_write_size 128k; 
  26.         gzip on; 
  27.         gzip_min_length 1k; 
  28.         gzip_buffers    4 16k; 
  29.         gzip_http_version 1.0; 
  30.         gzip_comp_level 2; 
  31.         gzip_types      text/plain application/x-javascript text/ccs application/xml; 
  32.         gzip_vary on; 
  33.         server { 
  34.                 listen       80; 
  35.                 server_name  172.16.0.2; 
  36.                 index index.html index.htm index.PHP
  37.                 root /web/bbs; 
  38.                 location ~ .*\.(PHP|PHP5)?$ 
  39.                 { 
  40.                 fastcgi_pass    172.16.0.4:9000; 
  41.                 fastcgi_index index.PHP
  42.                 fastcgi_param SCRIPT_FILENAME /web/bbs$fastcgi_script_name; 
  43.                 include fastcgi.conf; 
  44.                 } 
  45.                 access_log      logs/bbs.log; 
  46.  
  47.         } 
  48.  

3.重启Nginx服务

 
 
  1. #service Nginx restart 


4.使用NFS 共享的网站目录,以达到共享存储的目的

 
 
  1. #mkdir /web
  2. #mount -t nfs 172.16.0.3:/web /web 
  3. #echo "mount -t nfs 172.16.0.3:/web /web " >> /etc/rc.local

 

四.安装配置SVR1
1. 安装基本开发库,以及依赖的软件包

 
 
  1. #yum groupinstall "Development Libraries"  "Development Tools" 
  2. #yum -y install pcre-devel 

2.安装配置Nginx

 
 
  1. useradd -s /sbin/nologin Nginx 
  2. #cd /usr/src 
  3. #tar xzvf Nginx-1.2.2.tar.gz 
  4. #cd Nginx-1.2.2 
  5. #./configure --prefix=/usr/local/Nginx --pid-path=/var/run/Nginx/Nginx.pid \ 
  6. --lock-path=/var/lock/Nginx.lock --user=Nginx --group=Nginx --with-http_ssl_module \ 
  7. --with-http_flv_module --with-http_stub_status_module --with-http_gzip_static_module \ 
  8. --http-client-body-temp-path=/var/tmp/Nginx/client/ --http-proxy-temp-path=/var/tmp/Nginx/proxy \ 
  9. --http-fastcgi-temp-path=/var/tmp/Nginx/fcgi --http-uwsgi-temp-path=/var/tmp/Nginx/uwsgi \ 
  10. --http-scgi-temp-path=/var/tmp/Nginx/scgi --with-pcre 
  11. #make && make install 

3.为Nginx提供服务启动脚本

 
 
  1. 见 二.2.2 的配置内容 

4.编辑Nginx配置文件,配置负载均衡

 
 
  1. #vim /usr/local/Nginx/conf/Nginx.conf 
  2. user  Nginx
  3. worker_processes  10; 
  4. error_log  logs/error.log crit; 
  5. pid        logs/Nginx.pid; 
  6. events 
  7.   use epoll; 
  8.   worker_connections 51000; 
  9. http { 
  10.     include       mime.types; 
  11.     default_type  application/octet-stream; 
  12.     keepalive_timeout  60; 
  13.     tcp_nodelay on; 
  14. #指定负载均衡的方式
  15.     upstream bbs.andy.com { 
  16.         server  172.16.0.2:80; 
  17.         server  172.16.0.3:80; 
  18.         ip_hash; 
  19.         } 
  20.     server { 
  21.         listen       80; 
  22.         server_name  bbs.andy.com; 
  23.         index index.html index.htm index.PHP
  24.         location / { 
  25.             proxy_pass      http://bbs.andy.com; 
  26.             proxy_next_upstream http_502 http_504 error timeout invalid_header; 
  27.             proxy_set_header    Host    $host; 
  28.             proxy_set_header    X-Real-IP   $remote_addr; 
  29.             proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for; 
  30.             proxy_connect_timeout   600; 
  31.             proxy_read_timeout  600; 
  32.             proxy_send_timeout  600; 
  33.             proxy_buffer_size   8k; 
  34.             proxy_temp_file_write_size  64k; 
  35.         }    
  36.  
  37.      
  38.         access_log      logs/bbs.log; 
  39.  
  40.         } 

 

3.重启Nginx服务

 
 
  1. #service Nginx restart 


五,收尾配置,需要在每台服务器上执行以下命令

 
 
  1. #chkconfig iptables off 
  2. #service iptables stop 
  3. #setenforce 0 
  4. #echo "setenforce 0" >> /etc/rc.local    

2.需要在SVR4上挂载nfs共享

 
 
  1. #mkdir /web 
  2. #mount -t nfs 172.16.0.3:/web /web 
  3. #echo "mount -t nfs 172.16.0.3:/web /web" >> /etc/rc.local 

OK.到这里配置就结束了,2012年7月16日凌晨3:00整   完!

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐