haproxy安装及配置端口转发


HAProxy下载链接:http://www.haproxy.org/

 

HAProxy1.6.7下载:http://www.haproxy.org/download/1.6/src/haproxy-1.6.7.tar.gz

 

一、安装

 

# tar zcvf haproxy-1.6.7.tar.gz

# cd haproxy-1.6.7

# make TARGET=linux26 PREFIX=/usr/local/haproxy                                #将haproxy安装到/usr/local/haproxy

# make install PREFIX=/usr/local/haproxy


二、配置

#cd /usr/local/haproxy/

#mkdir conf logs

#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

 

二、端口转发

配置文件中加入:

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)。


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM