OpenFire源码学习之三十:haproxy负载均衡

来源:互联网 发布:windows补丁清理工具 编辑:程序博客网 时间:2024/06/06 10:03

安装

使用Haproxy做负载均衡。

下载地址:http://www.haproxy.com/downloads/trial-versions/

下载后解压:

tar zcvf haproxy-1.3.20.tar.gz

cd haproxy-1.3.20

make TARGET=linux26 PREFIX=/usr/local/haprpxy

make install PREFIX=/usr/local/haproxy

本人安装在/usr/local/haproxy

解下来编辑haproxy.cfg

vi haproxy.cfg

global      maxconn 51200      chroot /usr/local/haproxy      uid 99      gid 99      daemon      #quiet      nbproc 2 #进程数      pidfile /usr/local/haproxy/haproxy.pid    defaults          mode http #默认的模式mode { tcp|http|health },tcp是4层,http是7层,health只会返回OK          #retries 2 #两次连接失败就认为是服务器不可用,也可以通过后面设置          option redispatch #当serverId对应的服务器挂掉后,强制定向到其他健康的服务器          option abortonclose #当服务器负载很高的时候,自动结束掉当前队列处理比较久的链接          timeout connect 5000ms #连接超时          timeout client 30000ms #客户端超时          timeout server 30000ms #服务器超时          #timeout check 2000 #=心跳检测超时          log 127.0.0.1 local0 err #[err warning info debug]          balance roundrobin #负载均衡算法  #option  httplog #日志类别,采用httplog  #option  httpclose   #每次请求完毕后主动关闭http通道,ha-proxy不支持keep-alive,只能模拟这种模式的实现  #option  dontlognull  #option  forwardfor  #如果后端服务器需要获得客户端真实ip需要配置的参数,可以从Http Header中获得客户端ip    listen admin_stats          bind 0.0.0.0:8888 #监听端口          option httplog #采用http日志格式          stats refresh 30s #统计页面自动刷新时间          stats uri /haproxy-stats #统计页面url          stats realm Haproxy Manager #统计页面密码框上提示文本          stats auth admin:admin #统计页面用户名和密码设置          #stats hide-version #隐藏统计页面上HAProxy的版本信息    listen test1          bind :5222          mode tcp          server t1 192.169.1.120:5222          server t2 192.169.1.240:5222  server t3 192.169.1.250:5222    listen test2 192.169.1.245:80         option httpclose         option forwardfor          server s1 192.169.1.120:9090 check weight 1 minconn 1 maxconn 3 check inter 40000                server s2 192.169.1.240:9090 check weight 1 minconn 1 maxconn 3 check inter 40000 server s3 192.169.1.250:9090 check weight 1 minconn 1 maxconn 3 check inter 40000 

启动

开启:/usr/local/haproxy/sbin/haproxy -f /usr/local/haproxy/haproxy.cfg 

查看进程:ps -e|grep haproxy

杀死进程:kill -s 9 9883

另外还需要设置下linux环境下的打开连接数

修改linux tcp参数

ulimit -n 102400


1 1
原创粉丝点击