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



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

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

#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:
curl -fsSL https://packages.redis.io/gpg | sudo gpg –dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg
echo “deb [signed-by=/usr/share/keyrings/redis-archive-keyring.gpg] https://packages.redis.io/deb $(lsb_release -cs) main” | sudo tee /etc/apt/sources.list.d/redis.list
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 passwordrn
tcp-check expect string +OK
tcp-check send PINGrn
tcp-check expect string +PONG
tcp-check send info replicationrn
tcp-check expect string role:master
tcp-check send QUITrn
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

Comments are closed.