使用HAProxy实现简单的1+2负载均衡

1,安装HAProxy

1
2
3
4
5
6
7
wget http: //haproxy .1wt.eu /download/1 .4 /src/haproxy-1 .4.21. tar .gz
tar zxf haproxy-1.4.21. tar .gz
cd haproxy-1.4.21 #发现里面没有.configure文件
uname -r #查看内核版本,下面的TARGET参数要用到
make TARGET=linux26 PREFIX= /usr/local/haproxy
make install PREFIX= /usr/local/haproxy
useradd -r haproxy #增加执行用户

2,配置与测试haproxy
在编辑配置文件之前当然要了解清楚主要的配置项啦,可以参考这里:http://cbonte.github.com/haproxy-dconv/configuration-1.4.html。

下面来实现一个简单的1+2负载均衡
如图:

参考最简单的一个配置来新建配置文件 vim /etc/haproxy.conf ,然后加入下面的内容:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# Simple configuration for an HTTP proxy listening on port 80 on all
# interfaces and forwarding requests to a single backend "servers" with
# two servers listening on 127.0.0.1:8000 and 127.0.0.1:8081
global
     daemon
     group haproxy
     user haproxy
     maxconn 256
defaults
     mode http
     timeout connect 1000ms
     timeout client 10000ms
     timeout server 10000ms
frontend http-in
     bind *:80
     default_backend servers
backend servers
     server server1 127.0.0.1:8080 maxconn 32
     server server2 127.0.0.1:8081 maxconn 32

其中127.0.0.1:8080和127.0.0.1:8081可以简单配置nginx或者httpd,这里不展开说明。

1
2
3
4
#启动haproxy
/usr/local/haproxy/sbin/haproxy -f /etc/haproxy .conf
#停止haproxy
kill [haproxy的pid]

最后通过浏览器访问 http://192.168.1.27 查看效果。

转载于:https://my.oschina.net/alexwu/blog/71173

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值