首先安装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) #软重启