|
[教程]
CentOS6/Debian7下Haproxy实现负载均衡以及基于TCP和HTTP应用的代理
[复制链接]
本帖最后由 xiaoxiao 于 2016-2-9 13:23 编辑
一:安装Haproxy
For CentOS 6 Yum安装:
1:安装EPEL
标准的CentOS repository里面没有Haproxy,所以我们要先安装 Extra Packages for Enterprise Linux (EPEL) repository 到yum,EPEL包含有Haproxy。输入命令:
- rpm -ivh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
复制代码
或本站下载:
- rpm -ivh http://dl.aixiaoxiao.cn/vps/epel-release-6-8.noarch.rpm
复制代码
2:安装Haproxy
For Debian 7.0
1:添加源:
- vi /etc/apt/sources.list
- 添加一条源:
- deb http://ftp.us.debian.org/debian/ wheezy-backports main
复制代码
2:然后更新源:
3:安装:
二:配置Haproxy
先备份一份:
- cp /etc/haproxy/haproxy.cfg /etc/haproxy/haproxy.cfg.bak
复制代码
编辑:
- vi /etc/haproxy/haproxy.cfg
复制代码
以下配置可适用于https的代理
- global
- log 127.0.0.1 local2
- chroot /var/lib/haproxy
- pidfile /var/run/haproxy.pid
- maxconn 4000
- user haproxy
- group haproxy
- daemon
- defaults
- mode http
- log global
- option dontlognull
- option httpclose
- #option httplog
- option tcplog
- #option forwardfor
- option redispatch
- timeout connect 10000
- timeout client 300000
- timeout server 300000
- maxconn 60000
- retries 3
- frontend https_frontend
- bind *:443
- mode tcp
- default_backend web_server
- backend web_server
- mode tcp
- balance roundrobin
- server s1 192.168.1.100:443
- server s2 192.168.1.101:443
复制代码
以下配置可适用于中转SS流量,例如中转服务器的50000端口
- global
- ulimit-n 51200
- defaults
- log global
- mode tcp
- option dontlognull
- contimeout 1000
- clitimeout 150000
- srvtimeout 150000
- frontend ss-in
- bind *:50000(定义本地出口端口)
- default_backend ss-out
- backend ss-out
- server server1 目标服务器IP地址:50000 maxconn 20480
复制代码
设置开机自动启动
启动Haproxy服务
|
|