haproxy 安装与配置以及遇到的问题

1,安装配置过程:两台haproxy安装配置过程一样

1
2
3
4
5
6
7
#cd /usr/local/src
#wget http://haproxy.1wt.eu/download/1.4/src/haproxy-1.4.24.tar.gz
#tar xf haproxy-1.4.24.tar.gz
#cd haproxy-1.4.24
#make TARGET=linux26 ARCH=x86_64
#TARGET是指定内核版本,ARCH指定CPU架构,我使用的是64bit系统
#make install

2,安装完毕后,创建配置文件和启动文件

1
2
3
4
5
6
#mkdir /etc/haproxy
#cp examples/haproxy.cfg /etc/haproxy
#cp examples/haproxy.init /etc/init.d/haproxy
#chmod +x /etc/init.d/haproxy
#ln -s /usr/local/sbin/haproxy /usr/sbin/
#mkdir /usr/share/haproxy

3、编辑配置文件(两台Haproxy配置文件相同)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
global
     log 127.0.0.1   local0  #日志输出配置,所有日志都记录在本机,通过local0输出
     log 127.0.0.1   local1 notice
     maxconn 4096         #最大连接数
     chroot  /usr/share/haproxy    #改变当前工作目录。
     uid 99                   #所属用户的uid
     gid 99                   #所属运行的gid
     daemon                   #以后台形式运行haproxy
 
defaults
     log global
     mode    http #默认的模式mode { tcp|http|health },tcp是4层,http是7层,health只会返回OK
     option  httplog
     option  dontlognull
     option   redispatch #当serverId对应的服务器挂掉后,强制定向到其他健康的服务器
     option  abortonclose #当服务器负载很高的时候,自动结束掉当前队列处理比较久的链接
     retries 3 #两次连接失败就认为是服务器不可用
     maxconn 2000  #默认的最大连接数
     contimeout  5000 #连接超时
     clitimeout  50000 #客户端超时
     srvtimeout  50000 #服务器超时
     timeout check 5s #心跳检测超时
     stats refresh 30s #统计页面自动刷新时间
     stats uri   /stats  #统计页面url
     stats realm baison- test -Haproxy #统计页面密码框上提示文本
     stats auth admin:admin123 #统计页面用户名和密码设置
     stats hide-version #隐藏统计页面上HAProxy的版本信息
frontend www
     bind *:80 #这里建议使用bind *:80的方式,要不然做集群高可用的时候有问题,vip切换到其他机器就不能访问了。
     acl web hdr(host) -i www.william.com #acl后面是规则名称,-i是要访问的域名,如果访问www.william.com这个域名就分发到下面的webserver 的作用域。
     acl img hdr(host) -i img.william.com #如果访问img.william.com就分发到imgserver这个作用域。
     use_backend webserver  if  web
     use_backend imgserver  if  img
 
backend webserver  #webserver作用域
     #timeout server 50000ms 
     mode http
     balance roundrobin #banlance roundrobin 轮询,balance source 保存session值,支持static-rr,leastconn,first,uri等参数
     option httpchk HEAD  /index .html #检测文件,如果分发到后台index.html访问不到就不再分发给它  *** 这里要住下 HEAD  这个参数一定要加上,它是以HEAD请求的方式来检测后端的server,不然haproxy认为后端的realserver 是down的
     server web01 ip:80  check inter 2000 fall 3 weight 30
     server web02 ip:80  check inter 2000 fall 3 weight 40
 
backend imgserver
     mode http
     option httpchk HEAD  /index .html
     balance roundrobin
     server img01 ip:80  check inter 2000 fall 3
     server img02 ip:80  check inter 2000 fall 3

4、启动Haproxy服务,查看状态。

1
service haproxy start

wKiom1bZVh7zCh1BAAFA8B6Vyvs182.png













本文转自wks9751CTO博客,原文链接:http://blog.51cto.com/wks97/1747660 ,如需转载请自行联系原作者




  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值