本节翻译第2章。
--------------------------------
HAProxy的配置文件包含3个主要的参数:
- 命令行里的参数,优先级最高
- "global" 部分, 设置进程级的参数
- proxies部分,包含"defaults", "listen", "frontend" and "backend".
配置文件以行组成,开头是一个关键字,可选的,后面跟随一个或者多个参数(空格隔开)。
如果空格在字符串中出现了,必须以\space的形式出现。
‘\’字符可以用\\。
一些参数表示时间,比如超时时间timeouts.这些值总的以毫秒为单位,除非另外特别指出。
但是可以以任何其它单位表示,这通过添加后缀。
必须注意到这个,因为不会再赘述。支持的单位如下:
- us : 微秒, 1 microsecond = 1/1000000 second
- ms : 毫秒. 1 millisecond = 1/1000 second. 默认值
- s : 秒. 1s = 1000ms
- m : 分钟. 1m = 60s = 60000ms
- h : 小时. 1h = 60m = 3600s = 3600000ms
- d : 天. 1d = 24h = 1440m = 86400s = 86400000ms
# Simple configuration for an HTTP proxy listening on port 80 on all
# interfaces and forwarding requests to a single backend "servers" with a
# single server "server1" listening on 127.0.0.1:8000
global
daemon
maxconn 256
defaults
mode http
timeout connect 5000ms
timeout client 50000ms
timeout server 50000ms
frontend http-in
bind *:80
default_backend servers
backend servers
server server1 127.0.0.1:8000 maxconn 32
# The same configuration defined with a single listen block. Shorter but
# less expressive, especially in HTTP mode.
global
daemon
maxconn 256
defaults
mode http
timeout connect 5000ms
timeout client 50000ms
timeout server 50000ms
listen http-in
bind *:80
server server1 127.0.0.1:8000 maxconn 32
假设HAProxy在当前路径,测试如下:
$ sudo haproxy -f configuration.conf -c
|
翻译 |
理解 |
1 |
ok |
ok |
2 |
ok |
ok |