HAProxy下载连接:http://www.haproxy.org/linux
HAProxy1.6.7下载:http://www.haproxy.org/download/1.6/src/haproxy-1.6.7.tar.gz
web
1、安装redis
# tar zcvf haproxy-1.6.7.tar.gzvim
# cd haproxy-1.6.7bash
# make TARGET=linux26 PREFIX=/usr/local/haproxy #将haproxy安装到/usr/local/haproxyfrontend
# make install PREFIX=/usr/local/haproxytcp
2、配置ui
#cd /usr/local/haproxy/spa
#mkdir conf logsserver
#vim conf/haproxy.cfg
输入如下内容,创建一个能让haproxy跑起来的最基本的配置
global log 127.0.0.1 local3 maxconn 4096 chroot /usr/local/haproxy uid 1000 gid 1000 daemon nbproc 1 pidfile /usr/local/haproxy/logs/haproxy.pid defaults log 127.0.0.1 local3 mode http option httplog option httpclose option dontlognull option forwardfor option redispatch retries 2 maxconn 2000 balance roundrobin stats uri /haproxy-stats timeout connect 5000 timeout client 50000 timeout server 50000 frontend web_proxy mode http bind 0.0.0.0:8080
启动:/usr/local/haproxy/sbin/haproxy -f /usr/local/haproxy/conf/haproxy.cfg
访问本身的IP对应的路径:http://ip:8080/haproxy-stats
2、端口转发
配置文件中加入:
listen http bind :80 timeout client 1h tcp-request inspect-delay 2s acl is_http req_proto_http tcp-request content accept if is_http server server-http :8080
此处意思是:绑定80端口,若是收到tcp链接请求,则延时2秒用于判断,若是是http协议,则转发到8080端口(webserver)。