在实际项目中需要用到haproxy做TCP转发,下面主要针对haproxy的安装及TCP数据转发配置进行说明
一、安装Haproxy
(1)编译安装Haproxy
mkdir -p /data01/haproxy tar -zxvf haproxy-1.7.1.tar.gz cd haproxy-1.7.1 make TARGET=linux26 ARCH=x86_64 PREFIX=/data01/haproxy make install PREFIX=/data01/haproxy mkdir /data01/haproxy/conf mkdir /data01/haproxy/lib mkdir /data01/haproxy/run mkdir /data01/haproxy/logs cp haproxy.cfg /data01/haproxy/conf/
(2)修改Haproxy配置
vi /etc/syslog.conf local1.* /data01/haproxy/logs/haproxy.log local0.* /data01/haproxy/logs/haproxy.log vi /etc/rsyslog.d/haproxy.conf local1.* /data01/haproxy/logs/haproxy.log local0.* /data01/haproxy/logs/haproxy.log vi /etc/sysconfig/syslog SYSLOGD_OPTIONS="-r -m 0" servie rsyslog restart
(3)启动haproxy
sbin/haproxy -f conf/haproxy.cfgsbin/haproxy -f -d conf/haproxy.cfg #检查哪些服务启动OK
二、Haproxy TCP数据转发
global log 127.0.0.1 local0 log 127.0.0.1 local1 notice ulimit-n 40960 maxconn 4000 pidfile /data01/haproxy/run/haproxy.pid user XXX nbproc 2 daemon defaults mode tcp 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 4096 listen stats bind *:9093 balance roundrobin mode tcp server s1 XXX:5000 weight 1
参考:http://www.echojb.com/hp-web-develop/2016/11/03/251213.html
http://www.cnblogs.com/yjmyzz/p/haproxy.html
http://blog.amutu.com/%E6%9C%AA%E5%88%86%E7%B1%BB/2012/09/21/haproxy_for_portforward/
时间: 2024-10-14 10:49:52