haproxy安裝及配置端口轉發

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

相關文章
相關標籤/搜索