haproxy是一个简单易用的转发工具,通过它可以借助中间速度快的vps用作跳板来加速其它访问比较慢的VPS,例如国内的微林中转就是用到的数据转发模式来大幅度提升访问速度;
国内数据流量太贵,微林也不便宜,如果我们有自己的日本vps或者基于cn2线路的高质量vps用作转发的话,对其它国内访问很慢的vps服务器是个很好的解决方案;
yum安装命令
1
|
yum install haproxy
|
find命令查找haproxy目录
1
2
3
|
find / –name haproxy
#/usr/local/sbin/haproxy ###显示结果
#/usr/local/doc/haproxy ###显示结果
|
编辑haproxy.cfg配置文件
1
|
vi /etc/haproxy/haproxy.cfg
|
ss中转配置实例:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
global
ulimit–n 51200
defaults
log global
mode tcp
option dontlognull
timeout connect 1000ms
timeout client 150000ms
timeout server 150000ms
#中转Shadowsocks
frontend ss–in
bind *:8686
default_backend ss–out
backend ss–out
server server1 IP:8686 maxconn 20480
#中转VPS 22端口
frontend vps–in
bind *:2222
default_backend vps–out
backend vps–out
server server1 IP:22 maxconn 20480
|
haproxy操作命令
1
2
3
4
5
6
7
|
service haproxy status #查看运行状态
service haproxy start #启动
service haproxy stop #停止
service haproxy restart #重启
chkconfig haproxy on #开机启动
chkconfig —list #查看启动状态
|
centos 7
#———————————————————————
# Example configuration for a possible web application. See the
# full configuration options online.
#
# http://haproxy.1wt.eu/download/1.4/doc/configuration.txt
#
#———————————————————————
#———————————————————————
# Global settings
#———————————————————————
global
# to have these messages end up in /var/log/haproxy.log you will
# need to:
#
# 1) configure syslog to accept network log events. This is done
# by adding the ‘-r’ option to the SYSLOGD_OPTIONS in
# /etc/sysconfig/syslog
#
# 2) configure local2 events to go to the /var/log/haproxy.log
# file. A line like the following can be added to
# /etc/sysconfig/syslog
#
# local2.* /var/log/haproxy.log
#
log 127.0.0.1 local2
chroot /var/lib/haproxy
pidfile /var/run/haproxy.pid
maxconn 4000
user haproxy
group haproxy
daemon
# turn on stats unix socket
stats socket /var/lib/haproxy/stats
#———————————————————————
# common defaults that all the ‘listen’ and ‘backend’ sections will
# use if not designated in their block
#———————————————————————
defaults
mode tcp
log global
option httplog
option dontlognull
option http-server-close
option forwardfor except 127.0.0.0/8
option redispatch
retries 3
timeout http-request 10s
timeout queue 1m
timeout connect 10s
timeout client 1m
timeout server 1m
timeout http-keep-alive 10s
timeout check 10s
maxconn 3000
#———————————————————————
# main frontend which proxys to the backends
#———————————————————————
frontend bind *:6688
default_backend ss
#———————————————————————
# static backend for serving up images, stylesheets and such
#———————————————————————
backend static
balance roundrobin
server static 127.0.0.1:4331 check
#———————————————————————
# round robin balancing between the various backends
#———————————————————————
backend ss
balance roundrobin
server ss VPS-IP:6688 maxconn 20480
server app1 127.0.0.1:5001 check
server app2 127.0.0.1:5002 check
server app3 127.0.0.1:5003 check
server app4 127.0.0.1:5004 check