單一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,這臺應用程序服務器,
3,那麼svr2這臺服務器根據用戶請求的內容的不同,而進行不同的處理機制,根據上圖的架構一般有兩種可能,
         當用戶請求的內容是一個靜態的html頁面的話,那麼svr2,就直接將請求的結果響應給前端nginx負載均衡器,
         當用戶請求的內容是一個動態的頁面內容(在上圖中也就是PHP頁面了)那麼svr2會去找svr4上面的FastCGI程序來幫忙解析動態php頁面,如果此次頁面請求中需要訪問數據庫的話,fastcgi會通過mysql的接口訪問數據庫的,然後將其請求的結果,返回給svr2,
               當svr2收到返回的請求結果後,svr2再將結果返回給前端的nginx負載均衡器,
4,當前端的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/mysqld 
  3. #chmod a+x /etc/init.d/mysqld 
  4. #useradd -s /sbin/nologin mysql 
  5. #chown -R mysql:mysql /usr/local/mysql 
  6. #mysql_install_db --user=mysql 
  7. #chkconfig --add mysqld 
  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,需要在每臺服務器上執行以下命令

  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整   完!

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章