haproxy笔记

文章目录

    • 场景
    • haproxy配置
    • 文档地址

场景

还得先从场景说起。
生产环境redis检查,发现配置的redis地址不对。 redis有3个节点。
192.168.0.1
192.168.0.2
192.168.0.3
但是配置的是 192.168.0.9 端口是16379。
好奇怪有没有,是不是配错了?

问了下部署大神,才确认部署的没问题。 说是走的haproxy。
那么问题来了,haproxy是什么?
还是那句话,做程序员即使不会用,也必须听说过。

google了下,才发现haproxy是redis负载均衡。 那么走起,一探究竟吧。

haproxy配置

如果只是使用的话,不需要深入了解(学习成本太高)。
好在主配置就是最后几行,大概明白什么意思就行。
当然,haproxy实际是很复杂的,我们只简单使用。

global
    log 127.0.0.1 local0 notice
    maxconn     10240
    daemon

defaults
    mode http
    log global
    option tcplog
    option dontlognull
    option http-server-close
    option  redispatch
    retries 3
    maxconn 10240
    timeout http-request 10s  
    timeout queue 1m  
    timeout connect 10s  
    timeout client 1m  
    timeout server 1m  
    timeout http-keep-alive 10s  
    timeout check 10s  

listen stats
    bind 0.0.0.0:1082           #监听端口  
    stats refresh 30s           #统计页面自动刷新时间  
    stats uri /                 #统计页面url
    stats realm Haproxy Manager #统计页面密码框上提示文本  
    stats auth admin:PfTFu@zcd6R3U4T      #统计页面用户名和密码设置  
    #stats hide-version         #隐藏统计页面上HAProxy的版本信息

########tcp配置#################  
listen redis
    bind 0.0.0.0:16379
    mode tcp
    maxconn 10240
    balance roundrobin

    option tcp-check
#   tcp-check connect
    tcp-check send AUTH\ Bw-redis@2023\r\n
    tcp-check expect string +OK
    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 10.168.0.1:6379 check inter 2000 rise 3 fall 3 weight 30

server redis2 10.168.0.2:6379 check inter 2000 rise 3 fall 3 weight 30

server redis3 10.168.0.3:6379 check inter 2000 rise 3 fall 3 weight 30

文档地址

http://haproxy.1wt.eu/
非官网,但是感觉这个网站也很不错,从版本到文档都比较全。

你可能感兴趣的:(笔记)