-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhaproxy.cfg
More file actions
97 lines (96 loc) · 4.7 KB
/
haproxy.cfg
File metadata and controls
97 lines (96 loc) · 4.7 KB
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
global
maxconn 10000 #默认最大连接数
log 127.0.0.1 local0 #[err warning info debug]
chroot /usr/local/sbin #chroot运行的路径
daemon #以后台形式运行haproxy
pidfile /var/run/haproxy.pid #haproxy的pid存放路径,启动进程的用户必须有权限访问此文件
defaults
log 127.0.0.1 local3
mode http #所处理的类别 (#7层 http;4层tcp )
maxconn 10000 #最大连接数
option dontlognull #不记录健康检查的日志信息
option redispatch #serverId对应的服务器挂掉后,强制定向到其他健康的服务器
#stats refresh 30 #统计页面刷新间隔
retries 3 #3次连接失败就认为服务不可用,也可以通过后面设置
balance roundrobin #默认的负载均衡的方式,轮询方式
#balance source #默认的负载均衡的方式,类似nginx的ip_hash
#balance leastconn #默认的负载均衡的方式,最小连接
timeout connect 5000 #连接超时
timeout client 50000 #客户端超时
timeout server 50000 #服务器超时
timeout check 2000 #心跳检测超时
####################################################################
listen http_front
bind 0.0.0.0:5669 #监听端口
stats refresh 30s #统计页面自动刷新时间
stats uri /haproxy?stats #统计页面url
stats realm Haproxy Manager #统计页面密码框上提示文本
stats auth admin:admin #统计页面用户名和密码设置
#stats hide-version #隐藏统计页面上HAProxy的版本信息
#####################我把RabbitMQ的管理界面也放在HAProxy后面了###############################
listen rabbitmq_admin
bind 0.0.0.0:5671
server rabbitmq3 rabbit1:15672
server rabbitmq2 rabbit2:15672
server rabbitmq1 rabbit3:15672
####################################################################
listen rabbitmq_cluster
bind 0.0.0.0:5670
option tcplog
mode tcp
timeout client 3h
timeout server 3h
option clitcpka
balance roundrobin #负载均衡算法(#banlance roundrobin 轮询,balance source 保存session值,支持static-rr,leastconn,first,uri等参数)
#balance url_param userid
#balance url_param session_id check_post 64
#balance hdr(User-Agent)
#balance hdr(host)
#balance hdr(Host) use_domain_only
#balance rdp-cookie
#balance leastconn
#balance source //ip
server rabbitmq3 rabbit1:5672 check inter 5s rise 2 fall 3 #check inter 2000 是检测心跳频率,rise 2是2次正确认为服务器可用,fall 3是3次失败认为服务器不可用
server rabbitmq2 rabbit1:5672 check inter 5s rise 2 fall 3
server rabbitmq1 rabbit1:5672 check inter 5s rise 2 fall 3
listen redis
bind 0.0.0.0:6379
mode tcp
balance roundrobin
timeout client 3h
timeout server 3h
option tcp-check
tcp-check connect
tcp-check send PING\r\n
tcp-check expect string +PONG
tcp-check send info\ replication\r\n
tcp-check expect string role:master
tcp-check send QUIT\r\n
tcp-check expect string +OK
server redis1 redis-master:6379 check inter 5s rise 2 fall 3
server redis2 redis-slave1:6379 check inter 5s rise 2 fall 3
listen mongodb_cluster
bind 0.0.0.0:27017
mode tcp #所处理的类别 (#7层 http;4层tcp )
option tcpka
option tcplog
option tcp-check
# MongoDB Wire Protocol
tcp-check send-binary 3a000000 # Message Length (58)
tcp-check send-binary EEEEEEEE # Request ID (random value)
tcp-check send-binary 00000000 # Response To (nothing)
tcp-check send-binary d4070000 # OpCode (Query)
tcp-check send-binary 00000000 # Query Flags
tcp-check send-binary 61646d696e2e # fullCollectionName (admin.$cmd)
tcp-check send-binary 24636d6400 # continued
tcp-check send-binary 00000000 # NumToSkip
tcp-check send-binary FFFFFFFF # NumToReturn
# Start of Document
tcp-check send-binary 13000000 # Document Length (19)
tcp-check send-binary 10 # Type (Int32)
tcp-check send-binary 69736d617374657200 # ismaster:
tcp-check send-binary 01000000 # Value : 1
tcp-check send-binary 00 # Term
tcp-check expect binary 69736d61737465720001 #ismaster True
server monogo1 mongo-1-1:27017 check inter 2000 rise 2 fall 3
server monogo2 mongo-1-2:27017 check inter 2000 rise 2 fall 3