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 # 后面的节点任意
相关推荐
IndulgeCui3 分钟前
KES集群部署安装问题记录
数据库
Yilena8 分钟前
通过mysqldump进行数据迁移时权限不足的解决方案
数据库·学习
韩立学长15 分钟前
基于Springboot酒店管理系统的设计与实现c12044zy(程序、源码、数据库、调试部署方案及开发环境)系统界面展示及获取方式置于文档末尾,可供参考。
数据库·spring boot·后端
han_hanker16 分钟前
统一拦截异常 @RestControllerAdvice
java·开发语言·数据库
herinspace38 分钟前
管家婆软件年结存后快马商城操作注意事项
服务器·数据库·windows
qq_348231851 小时前
MySQL 与 PostgreSQL PL/pgSQL 的对比详解
数据库·mysql·postgresql
玩转数据库管理工具FOR DBLENS1 小时前
DBLens:开启数据库管理新纪元——永久免费,智能高效的国产化开发利器
数据结构·数据库·测试工具·数据库开发
芝麻馅汤圆儿1 小时前
sockperf 工具
linux·服务器·数据库
IndulgeCui1 小时前
金仓数据库征文_使用KDTS迁移mysql至金仓数据库问题处理记录分享
数据库
wsx_iot2 小时前
mysql的快照读和当前读
数据库·mysql