部署HAproxy的TCP代理模式

場景:測試HAproxy服務的TCP代理服務,與nginx的TCP代理做性能對比
部署過程:
1、下載haproxy-1.8.0.zip,下載頁面https://github.com/haproxy/haproxy/tree/v1.8.0

2、安裝部署haproxy
unzip haproxy-1.8.0.zip
cd haproxy-1.8.0
make TARGET=linux26 ARCH=X86_64 PREFIX=/home/homework/haproxy
make install PREFIX=/home/homework/haproxy
cd /home/homework/haproxy
mkdir etc logs
cd etc
vim haproxy.cfg

----------配置文件---------------
global
log 127.0.0.1 local3
pidfile /home/homework/haproxy/haproxy.pid
maxconn 4000
user homework
daemon

defaults
mode tcp
log global
log 127.0.0.1 local3
option tcplog
option dontlognull
option redispatch
option abortonclose
retries 3
timeout http-request 300s
timeout queue 1m
timeout connect 300s
timeout client 1m
timeout server 1m
timeout http-keep-alive 300s
timeout check 300s
maxconn 4000

listen stats
bind *:8090
balance roundrobin
mode tcp
server s1 192.168.8.63:8887 weight 1

chown homework.homework -R /home/homework/haproxy/

3、開啓日誌接收
vim /etc/rsyslog.conf
下面兩行註釋去掉
$ModLoad imudp
$UDPServerRun 514

添加配置
local3.* /home/homework/haproxy/logs/access.log

vim /etc/sysconfig/rsyslog
SYSLOGD_OPTIONS="-c 5"修改爲下面配置
SYSLOGD_OPTIONS="-r -m 0 -c 2"

/etc/init.d/rsyslog restart

4、啓動haproxy
/home/homework/haproxy/sbin/haproxy -f /home/homework/haproxy/etc/haproxy.cfg

5、檢查haproxy日誌是否有輸出
tail /home/homework/haproxy/logs/access.log
Dec 4 10:38:50 localhost haproxy[96612]: Proxy stats started.
Dec 4 10:38:50 localhost haproxy[96612]: Proxy stats started.

至此服務部署完成、重啓服務的腳本自行創建,這裏就不貼出來了。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章