1、前言
前一整子实现了一个基于 LVS (DR) + KeepAlived 群集的技术方案,但是在使用上和维护上却发现比HAProxy + KeepAlived 技术方案更难维护和实现,而对于WEB应用的群集 HAProxy + KeepAlived 已经搓搓有余了,所以今天向大家推荐HAProxy + KeepAlived 群集技术方案。
2、环境CentOS6 (Linux Kernel 2.6.32-71.el6.i686) haproxy 1.4.19 keepalived 1.1.17
3、需要的IP配置Master IP:10.0.0.8 Backup IP:10.0.0.6 RealServer IP:10.0.0.5、10.0.0.6(兼)
4、安装MASTER机器上的keepalived
[root@RServer2 /]#mkdir /soft [root@RServer2 /]#cd /soft [root@RServer2 soft]# wget [root@RServer2 soft]# tar -zxvf keepalived-1.1.17.tar.gz [root@RServer2 soft]# cd keepalived-1.1.17 [root@RServer2 soft]# ./configure [root@RServer2 keepalived-1.1.17]# make;make install 顺利的话就这些步骤了,如果出现错误提示,那么根据具体的错误具体处理,一般可能出现的错误: 1)、OpenSSL,提示可能如下 !!! OpenSSL is not properly installed on your system. !!! !!! Can not include OpenSSL headers files. 解决方案:运行yum -y installopenssl-devel 2)、提示没有gcc编译器 解决方案:运行yum installncurses-devel gcc gcc-c++ make rpm-build [root@RServer2 keepalived-1.1.17]# cp /usr/local/etc/rc.d/init.d/keepalived /etc/init.d/keepalived [root@RServer2 keepalived-1.1.17]# cp /usr/local/sbin/keepalived /usr/sbin/ [root@RServer2 keepalived-1.1.17]# cp /usr/local/etc/sysconfig/keepalived /etc/sysconfig/ [root@RServer2 keepalived-1.1.17]# mkdir -p /etc/keepalived/ [root@RServer2 keepalived-1.1.17]# cp /usr/local/etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf [root@RServer2 keepalived-1.1.17]# chmod +x /etc/init.d/keepalived
5、编辑Master机器上的/etc/keepalived/keepalived.conf:
打开编辑器,比如VI或是gedit /etc/keepalived/keepalived.conf的内容如下,自己修改程序要的内容。 #Master服务器上的配置 /etc/keepalived/keepalived.conf global_defs { notification_email { leekexi@gmail.com #可以多个地址 } notification_email_from leekexi@gmail.com smtp_server smtp.gmail.com smtp_connect_timeout 30 router_id LVS_DEVEL } vrrp_instance VI_1 { state MASTER #标示状态为MASTER 备份机为BACKUP interface eth0 virtual_router_id 51 priority 100 #MASTER权重要高于BACKUP 比如BACKUP为99 advert_int 1 authentication { auth_type PASS #主从服务器验证方式 auth_pass 1111 } virtual_ipaddress { 10.0.0.8 #可以多个虚拟IP,换行即可 } } #虚拟服务器 80端口的配置 virtual_server 10.0.0.8 80 { delay_loop 6 lb_algo rr protocol TCP real_server 10.0.0.5 80 { weight 5 TCP_CHECK { connect_timeout 10 nb_get_retry 3 delay_before_retry 3 connect_port 80 } } real_server 10.0.0.6 80 { weight 5 TCP_CHECK { connect_timeout 10 nb_get_retry 3 delay_before_retry 3 connect_port 80 } } }
6、编辑Master机器上安装HAProxy: