zoukankan      html  css  js  c++  java
  • 使用Haproxy实现端口转发

    首先安装Haproxy

    CentOS使用

    yum install haproxy -y

    debian使用

    vi /etc/apt/sources.list

    添加如下内容

    deb http://ftp.us.debian.org/debian/ wheezy-backports main

    然后

    apt-get update apt-get install haproxy

    接下来设置配置文件

    vim /etc/haproxy/haproxy.cfg

    清空配置文件后,输入如下内容

    global
        daemon
        log 127.0.0.1 local3 info
        maxconn 1000
        ulimit-n 4000
        uid 1001 #普通用户的uid和gid
        gid 1001
        quiet
        nbproc 1
        pidfile /etc/haproxy/haproxy.pid #普通用户路径权限
    defaults
        mode tcp #协议
        timeout connect 5000ms
        timeout client 50000ms
        timeout server 50000ms

    frontend tcp
    -in-unstable #名字 bind *:33891 #本地端口 ,注本地端口防火墙也要放开 default_backend tcpunstable backend tcpunstable server proxy00 192.168.122.27:3389 maxconn 1000 #外部端口(虚拟机)端口

    frontend tcp
    -in-unstable_33892 bind *:33892 default_backend tcpunstable_33892 backend tcpunstable_33892 server proxy00 192.168.122.81:3389 maxconn 1000

    运行Haproxy

    haproxy -f /etc/haproxy/haproxy.cfg    #启动
    
    haproxy -f /etc/haproxy/haproxy.cfg   -sf $(cat haproxy.pid)  #软重启


  • 相关阅读:
    java volatile关键字解惑
    Java 反射
    拷贝源实体类到目标实体类中
    Bean和Map之间的转换
    DateUtils时间的封装
    HttpClient的代码封装,便于直接调用
    HttpClient语法
    LinkedHashMap+ConcurrentHashMap+hashMap的区别
    1006 Tick and Tick
    Event Flow
  • 原文地址:https://www.cnblogs.com/ellisonzhang/p/14085241.html
Copyright © 2011-2022 走看看