LVS+Keepalived-NAT模式

LVS+Keepalived-NAT模式

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

Image

网络拓扑结构图

192.168.48.152服务器部署两个vip:192.168.48.200和192.168.245.200,一个对内,一个对外。注意:因为使用NAT模式,所以必须使用两个不同网段虚拟ip。
修改152上/etc/sysctl.conf文件,将net.ipv4.ip_forward等于0修改为等于1,即允许ip包转发。然后执行sysctl -p
将web服务器192.168.48.154和192.168.48.155的网关要设置为对内虚拟ip192.168.48.200
将ext.centos.jsp绑定192.168.245.200:
从192.168.48.153访问http://ext.centos.jsp显示的客户端ip是192.168.245.1
从192.168.245.128访问http://ext.centos.jsp显示的客户端ip是192.168.245.128
从192.168.48.152访问http://ext.centos.jsp显示的客户端ip是192.168.245.200
192.168.48.152上/etc/keepalived/keepalived.conf配置
! Configuration File for keepalived
global_defs {
   router_id LVS_CNC_1
}
vrrp_instance VI_CACHE_1 {
    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.245.200  #必须是不同于48的网段
    }
}
vrrp_instance VI_CACHE {
    state MASTER
    interface eth0
    virtual_router_id 52
    lvs_sync_daemon_interface eth0
    priority 100
    advert_int 5
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.48.200
    }
}
virtual_server 192.168.245.200 80  { 
    delay_loop 6
    lb_algo rr
    lb_kind NAT
    #persistence_timeout 50
    protocol TCP
    real_server 192.168.48.154 80 {
        weight 3
        HTTP_GET {
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
            url {
              path /status.html
              status_code 200
            }
        }
    }
    real_server 192.168.48.155 80 {
        weight 3
        HTTP_GET {
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
            url {
              path /status.html
              status_code 200
            }
        }
    }
}
192.168.48.154和192.168.48.155上web服务器配置ext.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;
  }

本文标签:

发表评论

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

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