Linux下使用haproxy配置tcp转发

本文基于阿里云CentOS 7.6测试成功

# cat /etc/redhat-release

CentOS Linux release 7.6.1810 (Core)

服务器信息:

192.168.109.101

TCP转发代理

192.168.200.10

目的服务器

需要转发的端口:

(1)8888

(2)1234

在“TCP转发代理”服务器上执行如下步骤:

1、安装haproxy

# yum install haproxy -y

2、查看haproxy版本信息

# rpm -qi haproxy

Name : haproxy

Version : 1.5.18

Release : 8.el7

Architecture: x86_64

Install Date: Tue 30 Apr 2019 11:32:40 AM CST

Group : System Environment/Daemons

Size : 2690238

License : GPLv2+

Signature : RSA/SHA256, Mon 12 Nov 2018 10:28:49 PM CST, Key ID 24c6a8a7f4a80eb5

Source RPM : haproxy-1.5.18-8.el7.src.rpm

Build Date : Wed 31 Oct 2018 05:39:00 AM CST

Build Host : x86-01.bsys.centos.org

Relocations : (not relocatable)

Packager : CentOS BuildSystem <http://bugs.centos.org>

Vendor : CentOS

URL : http://www.haproxy.org/

Summary : TCP/HTTP proxy and load balancer for high availability environments

Description :

HAProxy is a TCP/HTTP reverse proxy which is particularly suited for high

availability environments. Indeed, it can:

- route HTTP requests depending on statically assigned cookies

- spread load among several servers while assuring server persistence

through the use of HTTP cookies

- switch to backup servers in the event a main server fails

- accept connections to special ports dedicated to service monitoring

- stop accepting connections without breaking existing ones

- add, modify, and delete HTTP headers in both directions

- block requests matching particular patterns

- report detailed status to authenticated users from a URI

intercepted by the application

3、配置haproxy日志

# vim /etc/rsyslog.d/haproxy.conf

local2.* /var/log/haproxy.log

 

# systemctl restart rsyslog

4、配置haproxy转发

# vim /etc/haproxy/haproxy.cfg

# cat /etc/haproxy/haproxy.cfg

global

log 127.0.0.1 local2

ulimit-n 800000

chroot /var/lib/haproxy

pidfile /var/run/haproxy.pid

maxconn 4000

user haproxy

group haproxy

daemon

stats socket /var/lib/haproxy/stats

defaults

mode tcp

log global

option dontlognull

retries 3

maxconn 6000

timeout queue 1m

timeout connect 1000s

timeout client 150000m

timeout server 150000m

timeout check 10s

frontend forward11234

bind *:1234

default_backend server1234

frontend forward8888

bind *:8888

default_backend server8888

backend server1234

server server1 192.168.200.10:11234 maxconn 3000

backend server8888

server server1 192.168.200.10:8888 maxconn 3000

5、启动haproxy

# systemctl enable haproxy

# systemctl start haproxy

6、验证

访问相关端口的应用。

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值