您的位置:首页 > 运维架构 > 网站架构

[高可用]Ubuntu下Haproxy + Keepalived 实现SuperMap iServer高可用负载均衡实现(1)

2015-08-03 08:48 951 查看

题记

前面提到了使用LVS+ Keepalived实现SuperMap iServer高可用负载均衡,其实这个配置只能实现高可用,也就是Keepalived可以检测所管辖的对象哪个是健康的,哪个是由问题的,将有问题的剔除掉,但是并无法实现负载均衡,也就是将压力转到负载比较小的对象节点中,其实我们可以通过Haproxy来做负载均衡的时候,也就是说这两个组合可以实现真正的高可用的负载均衡。

环境

这次我们使用了两台负载均衡机器,两台iServer机器

负载均衡机器vip1:10.0.0.10

负载均衡机器vip2:10.0.0.9

iServer机器ubuntu:10.0.0.11

iServer集群ubuntu:10.0.0.12

虚拟IP:10.0.0.200

部署

1、两个负载均衡机器安装软件

root@vip1:~# apt-get install keepalived haproxy


2、修改/etc/sysctl.conf

为了让keepalived能够随便绑定虚拟IP,需要启用IP转发,添加nonlocal_bind配置,可以参考生效后的规则

root@vip1:~# sysctl -p
net.ipv4.ip_nonlocal_bind = 1
net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_syncookies = 1
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.all.rp_filter = 1
net.ipv4.ip_forward = 1


如果是在OpenStack环境下的虚拟机,基于KVM或者Xen,还需要修改宿主机的sysctl.conf的其他配置

net.ipv4.tcp_sysncookied=1
#根据你的网卡信息eth0、eth1...
net.ipv4.conf.eth0.proxy_arp=1
net.ipv4.conf.eth1.proxy_arp=1
net.bridge.bridge-nf-call-ip6tables=0
net.bridge.bridge-nf-call-iptables=0
net.bridge.bridge-nf-call-arptables=0


3、配置Keepalived.conf

首先看VIP1的配置(主服务器,priority=101)

global_defs {
    router_id LVS_DEVEL
}
vrrp_script chk_haproxy { 
    script "killall -0 haproxy" 
    interval 2 
    weight 2
}
vrrp_instance VI_1 {

    state MASTER
    interface eth0
    virtual_router_id 51
    priority 101

    authentication {
        auth_type PASS
        auth_pass 1111
    }

    virtual_ipaddress {
        10.0.0.200
    }

    track_script{
    chk_haproxy
    }
}


看VIP2的配置(备服务器,priority=100)

global_defs {
    router_id LVS_DEVEL
}
vrrp_script chk_haproxy { 
    script "killall -0 haproxy" 
    interval 2 
    weight 2
}
vrrp_instance VI_1 {

    state BACKUP
    interface eth0
    virtual_router_id 51
    priority 100

    authentication {
        auth_type PASS
        auth_pass 1111
    }

    virtual_ipaddress {
        10.0.0.200
    }

    track_script{
    chk_haproxy
    }
}


4、重启keepalived服务

5、查看负载均衡机器的网络信息

VIP1的网络信息

root@vip1:~# ip addr sh eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:d6:af:8c brd ff:ff:ff:ff:ff:ff
    inet 10.0.0.10/24 brd 10.0.0.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet 10.0.0.200/32 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fed6:af8c/64 scope link 
       valid_lft forever preferred_lft forever


VIP2的网络信息

root@vip2:~# ip addr sh eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:cc:37:03 brd ff:ff:ff:ff:ff:ff
    inet 10.0.0.9/24 brd 10.0.0.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fecc:3703/64 scope link 
       valid_lft forever preferred_lft forever


我们可以看到,由于VIP1为主节点,所以虚拟IP绑定在该机器上。

6、配置haproxy,在所有负载均衡节点编辑即可/etc/haproxy/haproxy.cfg

global
    log /dev/log    local0
    log /dev/log    local1 notice
    maxconn 4096
    chroot /var/lib/haproxy
    user haproxy
    group haproxy
    daemon

defaults
    log global
    retries 3
    maxconn 8000
    option  dontlognull
        contimeout 5000
        clitimeout 50000
        srvtimeout 50000
    errorfile 400 /etc/haproxy/errors/400.http
    errorfile 403 /etc/haproxy/errors/403.http
    errorfile 408 /etc/haproxy/errors/408.http
    errorfile 500 /etc/haproxy/errors/500.http
    errorfile 502 /etc/haproxy/errors/502.http
    errorfile 503 /etc/haproxy/errors/503.http
    errorfile 504 /etc/haproxy/errors/504.http
listen  iserver 10.0.0.200:8090
    mode http
    option httplog
    stats   enable
    stats   auth admin:admin
    balance roundrobin
    cookie  JSESSIONID  prefix
    option  httpclose
    option  forwardfor
    server ubuntu 10.0.0.11:8090 check inter 2000 rise 2 fall 5
    server ubuntu2 10.0.0.12:8090 check inter 2000 rise 2 fall 5


7、设置Haproxy的自启动

编辑/etc/default/haproxy,将Enabled设置为1即可

重启haproxy服务。

同样,配置完毕之后,我们可以打开http://10.0.0.200:8090/iserver/ 进行模拟,刷新几次,系统会来回切换不同的iserver节点。

那么这个配置与前面介绍的LVS+Keepalived的区别就是比前者多了一个负载均衡的功能。这也是比较主流的而且比较方面的配置方式。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: