Centos7安装haproxy
安装Haproxy#yum -y install gcc
#tar zxf haproxy-1.4.21.tar.gz
#mv haproxt-1.4.21 haproxy
#make TARGET=linux31 PREFIX=/usr/local/haproxy 将haproxy安装到指定目录
#make install PREFIX=/usr/local/haproxy 配置
#安装完后会在安装目录下生成三个目录
doc sbinshare
#cd /usr/local/haproxy
#vi haproxy.cfg #默认没有这个文件,需要自己手动创建
global
maxconn 51200
uid 99
gid 99
daemon
pidfile /usr/local/haproxy/logs/haproxy.pid
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 #
balance roundrobin #负载均衡算法
# optionhttplog #日志类别,采用httplog
# optionhttpclose #每次请求完毕后主动关闭http通道,ha-proxy不支持keep-alive,只能模拟>这种模式的实现
# optiondontlognull
# optionforwardfor#如果后端服务器需要获得客户端真实ip需要配置的参数,可以从Http Header中获得客户端ip
listen admin_stats
bind 0.0.0.0:1080 #监听端口
option httplog #采用http日志格式
stats refresh 30s #统计页面自动刷新时间
stats uri /stats #统计页面url
stats realm Haproxy Manager #统计页面密码框上提示文本
stats auth admin:admin #统计页面用户名和密码设置
#stats hide-version #隐藏统计页面上HAProxy的版本信息
listen test2 :80
option httpclose
option forwardfor
server s1 192.168.0.168:80 check weight 1 minconn 1 maxconn 3 check inter 40000
server s2 192.168.0.198:80 check weight 1 minconn 1 maxconn 3 check inter 40000
启动haproxy
/usr/local/haproxy/sbin/haproxy -f haproxy.cfg 访问http://ip:1080/stats,出现如下界面
http://s4.运维网.com/wyfs02/M02/79/35/wKioL1aLiX2jAkj3AADA5ya6XJQ514.png
访问http://ip:80,实现代理效果。
http://blog.运维网.com/e/u261/themes/default/images/spacer.gif
http://s1.运维网.com/wyfs02/M02/79/36/wKioL1aLjmeAUuweAAAYe-nAnuI576.png
http://s1.运维网.com/wyfs02/M00/79/37/wKiom1aLjkKgMp2pAAAXQe-ErAU276.png
页:
[1]