[#redis] Thiết lập HA, Auto-failover cho Redis với HAproxy và Sentinel | DevOps Mentor

preview_player
Показать описание
#redis #sentinel #haproxy #devopsmentor
Redis là một mã nguồn mở (BSD licensed) được sử dụng như một database, cache hoặc message broker.

Một số đặc điểm của Redis:

Là cơ sở dữ liệu NoSQL, lưu trữ dữ liệu dưới dạng KEY-VALUE
Lưu trữ dữ liệu trên RAM, giúp việc truy xuất dữ liệu cực kì nhanh chóng.
Hỗ trợ nhiều cấu trúc dữ liệu cơ bản như Hash, List, Set, Sorted Set, String,....
Hỗ trợ cơ chế Pub/Sub messaging.
Nhờ đặc điểm giúp giảm thời gian truy vấn, nên Redis có tác dụng rất mạnh mẽ trong việc sử dụng làm cache cho các ứng dụng web.
-----------------------------------------------------------------------------
Cài đặt Redis, sentinel:
sudo apt-get update
apt-get install redis-server=6:6.2.7-1rl1~focal1 redis-tools=6:6.2.7-1rl1~focal1 -y
apt install redis-sentinel=6:6.2.7-1rl1~focal1 -y
-----------------------------------------------------------------------------
Cấu hình redis-server:
bind 0.0.0.0
masterauth "password"
#replicaof 10.5.5.92 6379
requirepass "password"
-----------------------------------------------------------------------------
Cấu hình redis-sentinel:
bind 0.0.0.0
sentinel monitor mymaster 10.5.5.92 6379 2
sentinel auth-pass mymaster password
sentinel down-after-milliseconds mymaster 10000
requirepass "password"
sentinel sentinel-pass password
sentinel failover-timeout mymaster 60000
sentinel parallel-syncs mymaster 2
-----------------------------------------------------------------------------
Cấu hình haproxy:
defaults redis
mode tcp
timeout connect 0s
timeout server 0s
timeout client 0s
timeout check 3s
listen stats # Define a listen section called "stats"
bind *:8080
mode http
stats enable # Enable stats page
stats hide-version # Hide HAProxy version
stats realm HAProxy\ Statistics # Title text for popup window
stats uri /redis-status # Stats URI
frontend redis-in
bind *:6379
default_backend redis-backend
backend redis-backend
option tcp-check
tcp-check connect
tcp-check send AUTH\ password\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.5.5.92:6379 check inter 1s downinter 1s fastinter 1s fall 1 rise 1
server redis2 10.5.5.96:6379 check inter 1s downinter 1s fastinter 1s fall 1 rise 1
server redis3 10.5.5.20:6379 check inter 1s downinter 1s fastinter 1s fall 1 rise 1
-----------------------------------------------------------------------------
00:00 Giới thiệu
03:09 Demo
Рекомендации по теме
Комментарии
Автор

recap: 3 sentinal tương ứng 3 node redis (1 master, 2 slave)
khi master down, sentinal ở node master gửi noti và cả 3 sentinal check rồi vote cho note slave nào lên làm master thay thế cho note master vừa bị down.
Q: làm cách nào để biết node nào hiện đang là node master để mà kết nối vào => A: haproxy ở ngoài và gửi request đến từng node để check xem node nào đang là master, rồi kết nối đến node đó.

futhedude
Автор

Video hay quá, bạn làm thêm clip với mysql được ko

nkzone
Автор

Mình nghĩ nên thiết lập 2 cụm HA để chúng auto-failover cho nhau

xuandungho
Автор

cho mình hỏi tại sao lại cần tới 3 thằng sentinel cho 3 cái nodes master + 2 slave? nó chỉ có chứa năng kiểm tra health của 3 thằng kia thì mình dùng 1 thằng sentinel có được ko?

acbafide
Автор

mình cấu hình 1 cụm cluster master-slave với 3 sentinel trên docker và connect to sentinel và gặp lỗi "All sentinels are unreachable" thì fix sao ạ. Nodejs với package ioredis có hỗ trợ sentinel?

zuno
Автор

hello sir, please help
I have configured the redis and sentinel just like yours. replication is doing fine but when i stop the master, the replicas are not being promoted to master. i have check the log, it's not going further after +sdown master. please help me

kamaltamang