zl程序教程

您现在的位置是:首页 >  其他

当前栏目

Mycat HA(高可用) 与 LB(负载均衡)12

2023-03-31 10:29:26 时间

Haproxy的配置有三个来源:

  • 运行时通过命令行指定
  • 配置文件的 global 区域
  • 代理区域,包含 defaults、listen、frontend、backend

时间单位:

Units

Comment

us

microseconds 1/1000000 second

ms

milliseconds 1/1000 second ,这是默认配置,不指定单位时用这个单位

s

seconds. 1s = 1000ms

m

minutes. 1m = 60s = 60000ms

h

hours. 1h = 60m = 3600s = 3600000ms

d

days. 1d = 24h = 1440m = 86400s = 86400000ms

CONF

Comment

log 127.0.0.1 local0

记录到本机的 local0 类别中(之前rsyslog中自定义的类别),详细可参考 log

maxconn 512

限制 最大并行连接数 为512,详细可参考 maxconn

chroot /usr/local/haproxy

限定进程的 视域 ,详细可参考 chroot ,官方文档说 It is important to ensure that dir is both empty and unwritable to anyone ,然而实际并无此限制,强调这个只是为了安全考虑

user haproxy

以haproxy的身份运行 详细可参考 user

group haproxy

以haproxy的组运行 详细可参考 group

daemon

后台服务的方式运行, 详细可参考 daemon

log global

日志配置沿袭global的设定, 详细可参考 log global

option dontlognull

不记录无数据的操作,比如监控的侦测包 ,详细可参考 dontlognull

retries 3

失败后最多重试3次, 详细可参考 retries

option redispatch

跳转的设定,-1代表最后一次失败尝试就直接跳转,1代表每一次失败尝试都是跳转,0代表失败后不进行跳转, 详细可参考 redispatch

timeout connect 5000

一般性的超时时间为5s , 详细可参考 timeout connect

timeout client 50000

与客户端之间的超时时间为50s ,详细可参考 timeout client

timeout server 50000

与后端服务器之间的超时时间为50s ,详细可参考 timeout server

listen admin_status

定义一个包含前后端的完整监听

bind *:1234

监听1234端口, * 代表任意IP, 详细可参考 bind

stats uri /admin

定义/admin为统计uri, 详细可参考 stats uri

stats auth admin:admin

定义认证用户名和密码为 admin:admin , 详细可参考 stats auth

mode http

设定代理模式为http, 详细可参考 mode

option httplog

指定日志模式为http模式 , 详细可参考 option httplog

balance roundrobin

以轮询的方式进行负载均衡, 详细可参考 balance

server mycat_101 192.168.100.101:8066 check port 8066 inter 5s rise 2 fall 3

定义一个后端服务器为mycat_101,主机IP为192.168.100.101 , 端口为 8066,检查8066是否开放,检查周期为5s,连续两次检查成功算正常,连续三次检查失败算异常

Note: Mycat 官方文档中的配置是使用的 contimeout、clitimeout、srvtimeout ,这种写法已经不被支持,如果在配置中这样指定会有如下报错

[root@h101 haproxy]# /usr/local/haproxy/sbin/haproxy -f /usr/local/haproxy/haproxy.cfg
[WARNING] 063/215627 (16321) : parsing [/usr/local/haproxy/haproxy.cfg:16] : the 'contimeout' directive is now deprecated in favor of 'timeout connect', and will not be supported in future versions.
[WARNING] 063/215627 (16321) : parsing [/usr/local/haproxy/haproxy.cfg:18] : the 'clitimeout' directive is now deprecated in favor of 'timeout client', and will not be supported in future versions.
[WARNING] 063/215627 (16321) : parsing [/usr/local/haproxy/haproxy.cfg:20] : the 'srvtimeout' directive is now deprecated in favor of 'timeout server', and will not be supported in future versions.
[root@h101 haproxy]#