- 软件介绍
HAProxy提供高可用性、负载均衡以及基于TCP和HTTP应用的代理,支持虚拟主机,它是免费、快速并且可靠的一种解决方案,适用于那些负载特大的web站点,这些站点通常又需要会话保持或七层处理。HAProxy运行在当前的硬件上,完全可以支持数以万计的并发连接。并且它的运行模式使得它可以很简单安全的整合进您当前的架构中,同时可以保护你的web服务器不被暴露到网络上。
keepalived可提供vrrp以及health-check功能,可以只用它提供双机浮动的vip(vrrp虚拟路由功能),这样可以简单实现一个双机热备高可用功能,类似于layer3, 4 & 5交换机制的软件,也就是我们平时说的第3层、第4层和第5层交换,作
用是检测web服务器的状态,如果有一台web服务器死机,或工作出现故障,Keepalived将检测到,并将有故障的web服务器从系统中剔除,当
web服务器工作正常后Keepalived自动将web服务器加入到服务器群中,这些工作全部自动完成,不需要人工干涉,需要人工做的只是修复故障的
web服务器
- 实验环境
keepalived+Haproxy 192.168.40.144
keepalived+Haproxy 192.168.40.135
vip: 192.168.40.100
web01: 192.168.40.144:80
web02: 192.168.40.135:80
- 操作
1.安装Keepalived
[[email protected] ~]# cd /usr/local/src/;wget [[email protected] src]# tar zxvf keepalived-1.2.15.tar.gz [[email protected] keepalived-1.2.15]# ./configure --prefix=/usr/local/keepalived-1.2.15 ..... configure: error: !!! OpenSSL is not properly installed on your system. !!! !!! Can not include OpenSSL headers files. !!! [[email protected] keepalived-1.2.15]# yum -y install openssl-devel [[email protected] keepalived-1.2.15]# ./configure --prefix=/usr/local/keepalived-1.2.15 ....编译安装成功 Keepalived configuration ------------------------ Keepalived version : 1.2.15 Compiler : gcc Compiler flags : -g -O2 Extra Lib : -lssl -lcrypto -lcrypt Use IPVS Framework : Yes IPVS sync daemon support : Yes IPVS use libnl : No fwmark socket support : Yes Use VRRP Framework : Yes Use VRRP VMAC : Yes SNMP support : No SHA1 support : No Use Debug flags : No [[email protected] keepalived-1.2.15]# make && make install [[email protected] ~]# cp /usr/local/keepalived-1.2.15/etc/rc.d/init.d/keepalived /etc/init.d/keepalived [[email protected] ~]# cp /usr/local/keepalived-1.2.15/sbin/keepalived /usr/sbin/ [[email protected] ~]# cp /usr/local/keepalived-1.2.15/etc/sysconfig/keepalived /etc/sysconfig/ [[email protected] ~]# mkdir -v /etc/keepalived mkdir: created directory `/etc/keepalived‘ [[email protected] ~]# cp /usr/local/keepalived-1.2.15/etc/keepalived/keepalived.conf /etc/keepalived/ [[email protected] ~]# chmod a+x /etc/init.d/keepalived [[email protected] ~]# chkconfig --add /etc/init.d/keepalived [[email protected] ~]# cat /etc/keepalived/keepalived.conf ! Configuration File for keepalived global_defs { notification_email { [email protected] } notification_email_from [email protected] smtp_server 192.168.40.144 smtp_connect_timeout 30 router_id HAPROXY_MASTER } vrrp_script chk_haproxy { script "/usr/local/keepalived-1.2.15/check_haproxy.sh" interval 2 weight 2 } vrrp_instance VI_1 { state MASTER interface eth0 virtual_router_id 51 priority 101 advert_int 1 authentication { auth_type PASS auth_pass 1111 } track_script { chk_haproxy } virtual_ipaddress { 192.168.40.100 } }
2.安装Haproxy
[[email protected] src]wget http://haproxy.1wt.eu/download/1.4/src/haproxy-1.4.24.tar.gz [[email protected] src]# tar zxvf haproxy-1.4.24.tar.gz [[email protected] haproxy-1.4.24]# make TARGET=linux26 ARCH=x84_64 PREFIX=/usr/local/haproxy-1.4.24 [[email protected] haproxy-1.4.24]# make install PREFIX=/usr/local/haproxy-1.4.24 [[email protected] haproxy-1.4.24]# mkdir /etc/haproxy [[email protected] haproxy-1.4.24]# cp examples/haproxy.cfg /etc/haproxy/ [[email protected] haproxy-1.4.24]# cp examples/haproxy.init /etc/init.d/haproxy [[email protected] haproxy-1.4.24]# ln -svf /usr/local/haproxy-1.4.24/sbin/haproxy /usr/sbin/haproxy `/usr/sbin/haproxy‘ -> `/usr/local/haproxy-1.4.24/sbin/haproxy‘ [[email protected] haproxy-1.4.24]# chmod a+x /etc/init.d/haproxy [[email protected] haproxy-1.4.24]# chkconfig --add haproxy [[email protected] haproxy-1.4.24]# chkconfig haproxy on [[email protected] haproxy-1.4.24]# chkconfig --list haproxy haproxy 0:off 1:off 2:on 3:on 4:on 5:on 6:off
http://pynliu.blog.51cto.com/5027391/1619400
http://bbotte.blog.51cto.com/6205307/1606877
http://siriusz.blog.51cto.com/8150455/1368188