redis主从+高可用切换+负载均衡

1. redis主从配置

bash 复制代码
# 在master中
cp sentinel.conf /etc/redis/
vim /etc/redis/sentinel.conf
scp /etc/redis/sentinel.conf server2:/etc/redis/
scp /etc/redis/sentinel.conf server3:/etc/redis/
redis-sentinel /etc/redis/sentinel.conf # 启动监控
bash 复制代码
# 在slave中
redis-sentinel /etc/redis/sentinel.conf # 启动监控,在这之前一定要同步好sentinel.conf文件

2. 高可用自动切换

2.1 原master down

2.2 原master恢复为slave


2.3 问题

当客户机和master直接网络畅通,而master和slave直接网络故障,在切换主从过程中,客户向原来的master中写数据,会造成丢失。需要限制在切换主从时候添加数据。

bash 复制代码
min-slaves-to-write=2

3. 负载均衡(redis集群)

无中心化,所有节点均可读写

3.1 配置

bash 复制代码
# 停用之前的环境,防止影响实验
/etc/init.d/redis_6379 stop
bash 复制代码
cd utils/create-cluster/
./create-cluster start # 开启集群,该文件是配置文件,可以在里面加入集群的IP

3.2 拉起

bash 复制代码
# 快速拉起集群
./create-cluster create
bash 复制代码
redis-cli --cluster check 127.0.0.1:30001 # 查看集群

3.3 调用

bash 复制代码
redis-cli -c -p 30004 # 进入某个节点

在任意一节点上写入数据,会被重定向到对应的master。

3.4 故障切换

bash 复制代码
redis-cli -c -p 30002 shutdown # 原先的master故障

3.5 集群不可用

当hash表不完整时候,集群不可用

3.6 在线增加节点

bash 复制代码
vim create-cluster
bash 复制代码
./create-cluster start # 在线开启
 redis-cli --cluster help
 redis-cli --cluster add-node 127.0.0.1:30007 127.0.0.1:30001 # 添加节点
bash 复制代码
redis-cli --cluster add-node 127.0.0.1:30008 127.0.0.1:30001 --cluster-slave --cluster-master-id 6857101497d39b5d9ab59fbbd3b533c96baa1b4e # 添加节点同时,将其作为30007的slave
bash 复制代码
# 交互式手动分配hash
redis-cli --cluster reshard 127.0.0.1:30001 # 后面的节点任意
相关推荐
YL200404261 天前
MySQL-基础篇-事务
数据库·mysql
whn19771 天前
达梦dbms_sql对字段类型的展示
数据库
ITMr.罗1 天前
【无标题】
数据库
KaMeidebaby1 天前
卡梅德生物技术快报|细菌 FISH 实验 + 流式细胞术:尿路感染活菌快速定量系统实现与数据验证
前端·数据库·其他·百度·新浪微博
昆曲之源_娄江河畔1 天前
DBGridEh Footer的使用
前端·数据库·delphi·dbgrideh
邮专薛之谦1 天前
MySQL 完整SQL指令大全(含详细解释+实战示例)
数据库·sql·mysql
YL200404261 天前
MySQL-进阶篇-SQL优化
数据库·sql·mysql
Irissgwe1 天前
redis之典型应用-缓存cache
数据库·redis·缓存·缓存击穿·缓存雪崩·redis淘汰策略
Shely20171 天前
数据库索引
数据库·mysql
我也不曾来过11 天前
Mysql
数据库·mysql