Nginx/HAProxy/keepalived 方案

来源:互联网 发布:js创建button不可点击 编辑:程序博客网 时间:2024/05/17 03:31


方案拓扑图

web-server.jpg

1。
mater 192.168.2.2
backup 192.168.2.3
virtual ip 10.0.0.10

HAProxy 在mater,backup上配置相同

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
#--------------------------------------------------------------------- # Global settings #--------------------------------------------------------------------- global     log         127.0.0.1 local2     chroot      /var/lib/haproxy     pidfile     /var/run/haproxy.pid     maxconn     4000     user        haproxy     group       haproxy     daemon #--------------------------------------------------------------------- # common defaults that all the 'listen' and 'backend' sections will # use if not designated in their block #--------------------------------------------------------------------- defaults     mode        http     log         global     option      dontlognull     option      httpclose     option      httplog     option      forwardfor     option      redispatch     timeout connect 10000 # default 10 second time out if a backend is not found     timeout client 300000     timeout server 300000     maxconn     60000     retries     3         stats enable         stats refresh 30s         stats realm www.iiwoo.com         stats uri /st   #haproxy 监控页面的访问地址         stats auth admin:admin      #查看监控页,输入的用户名和密码 ##开始 frontend web1         bind 0.0.0.0:80         default_backend app1 backend app1         balance roundrobin         option httpchk GET /robots.txt         option forwardfor         cookie app1 insert nocache         server w_1_4 192.168.2.21:80 weight 1 maxconn 5000 cookie w_1_4 check         server w_1_5 192.168.2.22:80 weight 1 maxconn 5000 cookie w_1_5 check ##结束

2。
keepalived 的配置
mater

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
global_defs {    notification_email {         xx@qq.com    }    notification_email_from root@abc.com    smtp_server ngts6009.krypt.com    smtp_connect_timeout 30    router_id LVS_DEVEL } vrrp_instance VI_1 {     state MASTER     interface eth1     virtual_router_id 77     priority 100     advert_int 1     authentication     {         auth_type PASS         auth_pass qiwenadmin     }     virtual_ipaddress {         192.168.1.9     } } virtual_server 192.168.1.9 80 {     delay_loop 6             # 每隔 6 秒查询 realserver 状态     lb_algo rr     lb_kind NAT     nat_mask 255.255.255.0     persistence_timeout 50   # 同一IP 的连接50秒内被分配到同一台realserver     protocol TCP             # 用TCP监测realserver的状态     real_server 192.168.1.3 80 {         weight 3                # 权重         TCP_CHECK {             connect_timeout 10  # 10秒无响应超时             nb_get_retry 3             delay_before_retry 3             connect_port 80         }     }     real_server 192.168.1.4 80 {         weight 3         TCP_CHECK {             connect_timeout 3             delay_before_retry 3             connect_port 80         }     } }

backup

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
global_defs {    notification_email {         34214399@qq.com    }    notification_email_from root@ngts6009.krypt.com    smtp_server ngts6009.krypt.com    smtp_connect_timeout 30    router_id LVS_DEVEL } vrrp_instance VI_1 {     state BACKUP     interface eth0     virtual_router_id 77     priority 99     advert_int 1         authentication {         auth_type PASS         auth_pass qiwenadmin     }     virtual_ipaddress {         192.168.1.9     } } virtual_server 192.168.1.9 80 {     delay_loop 6             # 每隔 6 秒查询 realserver 状态     lb_algo rr     lb_kind NAT     nat_mask 255.255.255.0     persistence_timeout 50   # 同一IP 的连接50秒内被分配到同一台realserver     protocol TCP             # 用TCP监测realserver的状态     real_server 192.168.1.3 80 {         weight 3                # 权重         TCP_CHECK {             connect_timeout 10  # 10秒无响应超时             nb_get_retry 3             delay_before_retry 3             connect_port 80         }     }     real_server 192.168.1.4 80 {         weight 3         TCP_CHECK {             connect_timeout 3             delay_before_retry 3             connect_port 80         }     } }
原创粉丝点击