介绍
运维
安装
CentOS7中在线安装HAProxy1.5
1 | $ yum install haproxy -y |
CentOS7中在线安装HAProxy1.8
1 | $ yum install centos-release-scl -y |
CentOS7中编译安装HAProxy
1 | $ cd /usr/local/ |
Ubuntu中安装HAProxy
1 | $ sudo add-apt-repository ppa:vbernat/haproxy-1.8 |
Mac中安装HAProxy
1 | $ brew install haproxy |
内容如下: 1
2
3
4
5
6
7
8
9
10
11
12
13
14defaults
mode tcp
frontend shadowsocks-in
mode tcp
bind *:8388
default_backend shadowsocks-out
backend shadowsocks-out
mode tcp
balance roundrobin
server server1_name 123.123.123.101:8388
server server2_name 123.123.123.102:8388
server server3_name 123.123.123.103:8388
配置
配置文件位置
操作系统 | 位置 |
---|---|
Ubuntu | /etc/haproxy/haproxy.cfg |
MacOS | 默认不带配置文件需要自己创建。建议位置: /usr/local/etc/haproxy.cfg |
配置文件
1 | defaults |
重启Haproxy
1 | # 重启前验证配置 |
验证HaProxy配置
访问监听地址中绑定的ip:port。
常见问题
Mac安装注意事项
如果要用brew services后台运行haproxy,一定不要把haproxy自身配置成daemon运行。如果在配置文件中有这句配置: 1
2global
daemon
而你又用brew services后台自动运行,那么会发现隔几分钟haproxy就会生成一个新的进程,直到耗尽系统资源。