LVS+Keepalived-DR+Nginx反向代理

LVS+Keepalived-DR+Nginx反向代理

作者:admin |  时间:2014-03-10 |  浏览:1165 |  0 条评论

Image

在这种模式下,Web服务器上获取REMOTE_ADDR是Nginx反向代理的ip地址,即192.168.48.153
ext.centos.jsp绑定192.168.48.200
skin.centos.jsp绑定192.168.48.200
通过http://ext.centos.jsp随机访问154和155
152 /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
   router_id LVS_CNC_1
}
vrrp_sync_group VGM {
   group {
     VI_CACHE
   }
}
vrrp_instance VI_CACHE {
    state MASTER
    interface eth0
    virtual_router_id 51
    lvs_sync_daemon_interface eth0
    priority 100
    advert_int 5
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.48.200
        192.168.48.201
    }
}
virtual_server_group www {
   192.168.48.200 80
   192.168.48.201 80
}
virtual_server group www {
    delay_loop 6
    lb_algo wlc
    lb_kind DR
    persistence_timeout 50
    protocol TCP
    real_server 192.168.48.153 80 {
        weight 3
        HTTP_GET {
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
            connect_port 80
            url {
              path /status.html
              status_code 200
            }
        }
    }
}
真实服务器192.168.48.153  lvs_real.sh
#!/bin/bash
#description:start realserver
VIP=192.168.48.200
VIP1=192.168.48.201
/bin/bash /etc/rc.d/init.d/functions
case "$1" in
start)
echo " start LVS of REAL Server"
/sbin/ifconfig lo:0 $VIP broadcast $VIP netmask 255.255.255.255 up
/sbin/ifconfig lo:1 $VIP1 broadcast $VIP1 netmask 255.255.255.255 up
echo "1">/proc/sys/net/ipv4/conf/lo/arp_ignore # 抑制ARP广播
echo "2">/proc/sys/net/ipv4/conf/lo/arp_announce
echo "1">/proc/sys/net/ipv4/conf/all/arp_ignore
echo "2">/proc/sys/net/ipv4/conf/all/arp_announce
;;
stop)
/sbin/ifconfig lo:0 down
/sbin/ifconfig lo:1 down
echo " close LVS Directorserver"
echo "0">/proc/sys/net/ipv4/conf/lo/arp_ignore
echo "0">/proc/sys/net/ipv4/conf/lo/arp_announce
echo "0">/proc/sys/net/ipv4/conf/all/arp_ignore
echo "0">/proc/sys/net/ipv4/conf/all/arp_announce
;;
*)
echo "Usage:$0 {start|stop}"
exit 1
esac

153  nginx配置 reverse.proxy.conf
  server
  {
    listen       80;
    server_name  192.168.48.153;
    index index.html index.htm index.php;
    location / {
       proxy_pass http://proxy1;
      
       proxy_redirect off;
       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_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
       proxy_max_temp_file_size 0;
       proxy_connect_timeout 90;
       proxy_send_timeout 90;
       proxy_read_timeout 90;
       proxy_buffer_size 4k;
       proxy_buffers 4 32k;
       proxy_busy_buffers_size 64k;
       proxy_temp_file_write_size 64k;
    }
  
    log_format  reverse_proxy_access  '$remote_addr - $remote_user [$time_local] "$request" '
              '$status $body_bytes_sent "$http_referer" '
              '"$http_user_agent" $http_x_forwarded_for $request_uri';
    access_log  /data/logs/reverse_proxy.log  reverse_proxy_access;
  }
  upstream proxy1 {
    server 192.168.48.155;
    server 192.168.48.154;
  }
154和155  nginx配置 ext.centos.jsp.conf和skin.centos.jsp.conf
  server
  {
    listen       80;
    server_name  ext.centos.jsp;
    index index.html index.htm index.php;
    root  /data/htdocs/ext.centos.jsp;
    #limit_conn   crawler  20;   
                            
    location ~ .*\.(php|php5)?$
    {     
      #fastcgi_pass  unix:/tmp/php-cgi.sock;
      fastcgi_pass  127.0.0.1:9000;
      fastcgi_index index.php;
      include fcgi.conf;
    }
   
    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
    {
      expires      30d;
    }
    location ~ .*\.(js|css)?$
    {
      expires      1h;
    }   
    log_format  ext_access  '$remote_addr - $remote_user [$time_local] "$request" '
              '$status $body_bytes_sent "$http_referer" '
              '"$http_user_agent" $http_x_forwarded_for';
    access_log  /data/logs/ext_access.log  ext_access;
  }
  server
  {
    listen       80;
    server_name  skin.centos.jsp;
    index index.html index.htm index.php;
    root  /data/htdocs/skin.centos.jsp;
    #limit_conn   crawler  20;   
                            
    location ~ .*\.(php|php5)?$
    {     
      #fastcgi_pass  unix:/tmp/php-cgi.sock;
      fastcgi_pass  127.0.0.1:9000;
      fastcgi_index index.php;
      include fcgi.conf;
    }
   
    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
    {
      expires      30d;
    }
    location ~ .*\.(js|css)?$
    {
      expires      1h;
    }   
    log_format  skin_access  '$remote_addr - $remote_user [$time_local] "$request" '
              '$status $body_bytes_sent "$http_referer" '
              '"$http_user_agent" $http_x_forwarded_for';
    access_log  /data/logs/skin_access.log  skin_access;
  }

本文标签:

相关推荐

发表评论

电子邮件地址不会被公开。

您可以使用这些HTML标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>