[高可用]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的区别就是比前者多了一个负载均衡的功能。这也是比较主流的而且比较方面的配置方式。
相关文章推荐
- 架构师速成6.12-开发框架-前端封装
- 用Mediawiki做百科网站资源大参考
- 用Mediawiki做百科网站资源大参考
- 网站流量统计系统 phpMyVisites
- 网站流量统计系统 phpMyVisites
- 建设自己拥有的B2C网站一般需要什么样的插件以及大体花费
- 当你访问网站时,Session会立刻建立吗?
- 一个没水平的钓鱼网站黑三个人:人们的安全意识和安全知识的缺失
- 基于规则引擎的电信CRM系统架构研究
- 在Github上搭建自己的博客网站
- 如何搭建轻量级架构-更新部署篇
- Android系统架构和内核及虚拟机
- mfs分布式存储+master端高可用
- 三层架构
- 技术学习网站收藏推荐(CodeProject , MSDN 等)
- 天亮舆情系统-架构设计-01
- 高清屏的背景图片适配
- 【Angular JS】网站使用社会化评论插件,以及过程中碰到的坑
- IIS-IIS服务器,发布网站:出错版本问…
- 高可用可伸缩架构实用经验谈