php是最好的语言

lnmp负载均衡搭建和检测节点模块安装

        nginx负载均衡就是利用nginx将请求分配到不同的服务器进行处理。

        一台负载均衡器,两台web服务器。

        直接上配置,省略了一些配置,主要配置如下(一些常见的参数也在下面):

        .........

http {

    include       mime.types;

    default_type  application/octet-stream;


    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '

    #                  '$status $body_bytes_sent "$http_referer" '

    #                  '"$http_user_agent" "$http_x_forwarded_for"';


    #access_log  logs/access.log  main;


    sendfile        on;

    #tcp_nopush     on;


    #keepalive_timeout  0;

   # keepalive_timeout  65;


    #gzip  on;

    upstream backend {//负载均衡所涉及的服务器

        server 49.4.142.151 weight=1 max_fails=1 fail_timeout=10s ;//down  backup

        server 49.4.143.217;

        check interval=3000 rise=2 fall=5 timeout=1000 type=http;//检测节点模块

         }

    server {

        listen      80;

        server_name www.xtwanwan.info;


        #charset koi8-r;


        #access_log  logs/host.access.log  main;

        location / {

#               root html/www;

#               index index.php index.html index.htm;

             proxy_set_header Host $host;

             proxy_set_header X-Real-IP $remote_addr;

             proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

             proxy_buffering off;

             proxy_pass http://backend;//反向代理

        }

.........

web1配置(web2配置一样):

................

server {

        listen       80;

        server_name  www.xtwanwan.info;


        #charset koi8-r;


        #access_log  logs/host.access.log  main;


        location / {

            root   html/www;

            index  index.php index.html index.htm;

        }


        #error_page  404              /404.html;


        # redirect server error pages to the static page /50x.html

        #

        error_page   500 502 503 504  /50x.html;

        location = /50x.html {

            root   html;

        }


        # proxy the PHP scripts to Apache listening on 127.0.0.1:80

        #

        #location ~ \.php$ {

        #    proxy_pass   http://127.0.0.1;

        #}


        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

        #

        location ~ \.php$ {

            root           html/www;

           fastcgi_pass   127.0.0.1:9000;

            fastcgi_index  index.php;

            fastcgi_param  SCRIPT_FILENAME  /application/nginx/html/www$fastcgi_script_name;

            include        fastcgi_params;

        }

....................


    上面已经可以实现负载均衡了,具体看自己怎么弄。下面搭建节点检测模块。


     cd /home/xutao/tools/,wget https://codeload.github.com/yaoweibin/nginx_upstream_check_module/zip/master,unzip master(这里可能需要安装unzip命令),cd nginx-1.6.3, patch -p1 </home/xutao/tools/nginx_upstream_check_module-master/check_1.5.12+.patch,./configure --prefix=/application/nginx-1.6.3 --add-module=../nginx_upstream_check_module-master/(这里和之前安装nginx要一模一样),make,mv /application/nginx/sbin/nginx{,.ori} , cp ./objs/nginx /application/nginx/sbin/, /application/nginx/sbin/nginx -t ,然后就可以重启按照上面的配置配好,然后在浏览器输入,www.xtwanwan.info/status.就可以了

作者:xTao 分类:LNMP 浏览:2382 评论:0