HAProxy+Keepalived高可用负载均衡配置
前言* 随着负载均衡器的成熟,人们熟知的软件负载均衡如LVS、HAProxy,各方面性能不亚于硬件负载均衡,HAProxy提供高可用性、负载均衡以及基于TCP和HTTP应用的代理,支持虚拟主机,它是免费、快速并且可靠的一种解决方案。
HAProxy特别适用于那些负载特大的web站点,这些站点通常又需要会话保持或七层处理。
我们平时用的负载均衡LVS是基于四层,新型的大型互联网公司也在采用HAProxy,了解了haproxy大并发、七层应用等特点,那今天我们来研究一下HAProxy+Keepalived基于七层负载高可用负载均衡的配置。
一、系统环境:
- 系统版本:CentOS6.0 x86_64
- HAProxy版本:1.4.21
- Keepalived版本:1.2.1
- Nginx版本:1.2.2
- MASTER_IP:192.168.0.130
- BACKUP_IP:192.168.0.131
- VIP:192.168.0.133
- WEB_1:192.168.0.134
- WEB_2:192.168.0.135
二、HAProxy安装:
1)首先安装192.168.0.130上安装:
下载最新稳定版本:1.4.21
- cd /usr/src ;wget http://haproxy.1wt.eu/download/1.4/src/haproxy-1.4.21.tar.gz
- tar xzf haproxy-1.4.21.tar.gz &&cd haproxy-1.4.21 &&make TARGET=linux26PREFIX=/usr/local/haproxy &&make install PREFIX=/usr/local/haproxy
- 安装完毕,在/usr/local/haproxy/目录下会看到三个目录:doc、sbin、share
2) 接下来配置HAProxy。
cd /usr/local/haproxy ;mkdir -p etc/
然后在/usr/local/haproxy/etc/下新建haproxy.cfg文件,这里拷贝haproxy配置文件:
- global
- log 127.0.0.1 local0
- maxconn 65535
- chroot /usr/local/haproxy
- uid 99
- gid 99
- daemon
- nbproc 8
- pidfile /usr/local/haproxy/haproxy.pid
- defaults
- log 127.0.0.1 local3
- mode http
- option httplog
- option httpclose
- option dontlognull
- option forwardfor
- option redispatch
- retries 2
- maxconn 65535
- balance source
- stats uri /web-status
- contimeout 5000
- clitimeout 50000
- srvtimeout 50000
- listen chinaapp.sinaapp.com
- bind *:80
- mode http
- option httplog
- log global
- option httpchk HEAD /index.html HTTP/1.0
- server web1 192.168.0.134:80 weight 5 check inter 2000 rise 2 fall 3
- server web2 192.168.0.135:80 weight 5 check inter 2000 rise 2 fall 3
然后启动haproxy,如下执行启动命令:
- /usr/local/haproxy/sbin/haproxy -f /usr/local/haproxy/etc/haproxy.cfg
- [WARNING] 217/202150 (2857) : Proxy 'chinaapp.sinaapp.com': in multi-process mode, stats will be limited to process assigned to the current request.
- 会提示如上信息,nbproc进程如果设置为1则不会提示,如果想去掉这个提示可以修改编译文件即可。 在源码配置src/cfgparse.c找到如下行
- if (nbproc > 1) { if (curproxy->uri_auth) { - Warning("Proxy '%s': in multi-process mode, stats will be limited to process assigned to the current request.\n",
+ Warning("Proxy '%s': in multi-process mode, stats will be limited to the process assigned to the current request.\n",
调整nbproc > 1数值即可。
相关推荐
swtIrene 2020-08-14
slovyz 2020-08-14
tinydu 2020-08-03
yungame 2020-07-04
廖先贵 2020-06-23
畅聊架构 2020-06-10
魏莉的微 2020-06-07
后厂村老司机 2020-06-01
后厂村老司机 2020-05-08
azhuye 2020-11-12
liupengqwert 2020-10-28
YzhilongY 2020-08-31
crazyjingling 2020-08-16
tinydu 2020-08-09
Studynutlee 2020-08-03
快乐de馒头 2020-07-29
yungame 2020-07-27
buaichidoufu 2020-07-28