redis哨兵模式及集群模式

https://juejin.cn/post/7162197682600017933

 

一.主从模式

主从结构与单节点不同的redis.conf配置

主从结构需要:

replicaof master-redis-svc 6379

masterauth 123456

二.哨兵模式

1.哨兵模式还需要添加sentinel.conf文件

# 哨兵sentinel实例运行的端口 默认26379
port 26379
# 哨兵sentinel的工作目录
dir "/tmp"
sentinel deny-scripts-reconfig yes
sentinel monitor mymaster redis-0.redis 6379 2
sentinel auth-pass mymaster devops
sentinel down-after-milliseconds mymaster 5000
sentinel failover-timeout mymaster 15000
# 设定5秒内没有响应,说明服务器挂了,需要将配置放在sentinel monitor master 127.0.0.1 6379 下面
sentinel parallel-syncs mymaster 2
# 设定15秒内master没有活起来,就重新选举主
sentinel config-epoch mymaster 3
#.表示如果master重新选出来后,其它slave节点能同时并行从新master同步缓存的台数有多少个,显然该值越大,所有slave节点完成同步切换的整体速度越快,但如
果此时正好有人在访问这些slave,可能造#成读取失败,影响面会更广。最保定的设置为1,只同一时间,只能有一台干这件事,这样其它slave还能继续服务,但是所
有slave全部完成缓存更新同步的进程将变慢。
sentinel leader-epoch mymaster 3

 

2.使用helm进行部署哨兵模式(1主两从)

1)下载chart包

helm repo add bitnami https://charts.bitnami.com/bitnami

helm pull bitnami/redis --version 17.3.7

tar -xf redis-17.3.7.tgz

2)推送镜像到私有镜像库

复制代码
#redis镜像
docker pull docker.io/bitnami/redis:7.0.5-debian-11-r7
docker tag docker.io/bitnami/redis:7.0.5-debian-11-r7 myharbor.com/bigdata/redis:7.0.5-debian-11-r7
docker push myharbor.com/bigdata/redis:7.0.5-debian-11-r7

#sentinel镜像
docker pull docker.io/bitnami/redis-sentinel:7.0.5-debian-11-r6
docker tag docker.io/bitnami/redis-sentinel:7.0.5-debian-11-r6 myharbor.com/bigdata/redis-sentinel:7.0.5-debian-11-r6
docker push myharbor.com/bigdata/redis-sentinel:7.0.5-debian-11-r6
复制代码

3)修改values.yaml,使用名为managed-nfs-storage的sc做存储

复制代码
global:
  imageRegistry: ""
  storageClass: "managed-nfs-storage"
  redis:
    password: "123456"

image:
  registry: myharbor.com
  repository: bigdata/redis
  tag: 7.0.5-debian-11-r7

replica:
  # replica.replicaCount与sentinel.quorum值一样
  replicaCount: 3
sentinel:
  enabled: true
  image:
    registry: myharbor.com
    repository: bigdata/redis-sentinel
    tag: 7.0.5-debian-11-r6
  quorum: 3
复制代码

部署helm

#干跑测试

helm install ocs-redis-sentinel ./redis --dry-run  -n ocs-test

#实际部署

helm install ocs-redis-sentinel ./redis  -n ocs-test

4)故障模拟测试

查看redis信息
kubectl exec -it redis-sentinel-node-0 -n redis-sentinel -- redis-cli -h redis-sentinel -a $(kubectl get secret --namespace redis-sentinel redis-sentinel -o jsonpath="{.data.redis-password}" | base64 -d) info replication
delete掉master的pod之后,再次查看redis信息,此时应该看到master变成其他节点
kubectl exec -it redis-sentinel-node-0 -n redis-sentinel -- redis-cli -h redis-sentinel -a $(kubectl get secret --namespace redis-sentinel redis-sentinel -o jsonpath="{.data.redis-password}" | base64 -d) info replication

 

3.集群模式

1)下载chart包

helm repo add bitnami https://charts.bitnami.com/bitnami
helm pull bitnami/redis-cluster --version 8.2.7
tar -xf redis-cluster-8.2.7.tgz
2)将镜像推送到私有仓库
docker pull docker.io/bitnami/redis-cluster:7.0.5-debian-11-r9
docker tag docker.io/bitnami/redis-cluster:7.0.5-debian-11-r9 myharbor.com/bigdata/redis-cluster:7.0.5-debian-11-r9
docker push myharbor.com/bigdata/redis-cluster:7.0.5-debian-11-r9
3)修改values.yaml,nodes为总个数总共为9个,replicas为master的副本数,也就是每个master的slave数,一主两从,replicas为从节点数为2
复制代码
global:
  imageRegistry: ""
  storageClass: "managed-nfs-storage"
  redis:
    password: "123456"

image:
  registry: myharbor.com
  repository: bigdata/redis-cluster
  tag: 7.0.5-debian-11-r9

cluster:
  init: true
  # 一主两从(三组)nodes为总个数,replicas为master的副本数,也就是每个master的slave数,一主两从,replicas为从节点数为2
  nodes: 9
  replicas: 2
复制代码

 

posted @   潇潇暮鱼鱼  阅读(155)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
点击右上角即可分享
微信分享提示