首页 > 代码库 > Haproxy TCP数据转发

Haproxy TCP数据转发

   在实际项目中需要用到haproxy做TCP转发,下面主要针对haproxy的安装及TCP数据转发配置进行说明

一、安装Haproxy

  (1)编译安装Haproxy

mkdir -p /data01/haproxytar -zxvf haproxy-1.7.1.tar.gzcd haproxy-1.7.1make TARGET=linux26 ARCH=x86_64 PREFIX=/data01/haproxymake install PREFIX=/data01/haproxymkdir /data01/haproxy/confmkdir /data01/haproxy/libmkdir /data01/haproxy/runmkdir /data01/haproxy/logscp haproxy.cfg /data01/haproxy/conf/

  (2)修改Haproxy配置

vi /etc/syslog.conflocal1.*  /data01/haproxy/logs/haproxy.loglocal0.*  /data01/haproxy/logs/haproxy.logvi /etc/rsyslog.d/haproxy.conflocal1.*  /data01/haproxy/logs/haproxy.loglocal0.*  /data01/haproxy/logs/haproxy.logvi /etc/sysconfig/syslogSYSLOGD_OPTIONS="-r -m 0"servie rsyslog restart

(3)启动haproxy

sbin/haproxy -f conf/haproxy.cfg
sbin/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   daemondefaults    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                     4096listen 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/

Haproxy TCP数据转发