软件介绍
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
[root@server01 ~]# cd /usr/local/src/;wget [root@server01 src]# tar zxvf keepalived-1.2.15.tar.gz [root@server01 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. !!! [root@server01 keepalived-1.2.15]# yum -y install openssl-devel [root@server01 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 [root@server01 keepalived-1.2.15]# make && make install [root@server01 ~]# cp /usr/local/keepalived-1.2.15/etc/rc.d/init.d/keepalived /etc/init.d/keepalived [root@server01 ~]# cp /usr/local/keepalived-1.2.15/sbin/keepalived /usr/sbin/ [root@server01 ~]# cp /usr/local/keepalived-1.2.15/etc/sysconfig/keepalived /etc/sysconfig/ [root@server01 ~]# mkdir -v /etc/keepalived mkdir: created directory `/etc/keepalived‘ [root@server01 ~]# cp /usr/local/keepalived-1.2.15/etc/keepalived/keepalived.conf /etc/keepalived/ [root@server01 ~]# chmod a+x /etc/init.d/keepalived [root@server01 ~]# chkconfig --add /etc/init.d/keepalived [root@server01 ~]# cat /etc/keepalived/keepalived.conf ! Configuration File for keepalived global_defs { notification_email { kaibintest@126.com } notification_email_from keepalived@test.com 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
[root@centos-node1 src]wget http://haproxy.1wt.eu/download/1.4/src/haproxy-1.4.24.tar.gz [root@server01 src]# tar zxvf haproxy-1.4.24.tar.gz [root@server01 haproxy-1.4.24]# make TARGET=linux26 ARCH=x84_64 PREFIX=/usr/local/haproxy-1.4.24 [root@server01 haproxy-1.4.24]# make install PREFIX=/usr/local/haproxy-1.4.24 [root@server01 haproxy-1.4.24]# mkdir /etc/haproxy [root@server01 haproxy-1.4.24]# cp examples/haproxy.cfg /etc/haproxy/ [root@server01 haproxy-1.4.24]# cp examples/haproxy.init /etc/init.d/haproxy [root@server01 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‘ [root@server01 haproxy-1.4.24]# chmod a+x /etc/init.d/haproxy [root@server01 haproxy-1.4.24]# chkconfig --add haproxy [root@server01 haproxy-1.4.24]# chkconfig haproxy on [root@server01 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
本文出自 “Linux革命” 博客,请务必保留此出处http://kaibinyuan.blog.51cto.com/7304008/1621488
原文地址:http://kaibinyuan.blog.51cto.com/7304008/1621488