当前位置:网站首页> k8s部署redis哨兵的实现
k8s部署redis哨兵的实现
2022-07-01 15:00:00 【1024问】
一、准备redis镜像
二、准备k8s yml—redis-sentinel.yml
三、查看redis哨兵信息
四、连接redis哨兵
一、准备redis镜像Dockerfile
FROM redis:6.0MAINTAINER 运维@小兵COPY *.conf /opt/conf/COPY run.sh /opt/run.shRUN apt update -y;apt-get install vim net-tools -y;apt-get clean && \ chmod +x /opt/run.shCMD /opt/run.shredis配置文件redis.conf
#绑定到哪台机器,0.0.0.0表示允许所有主机访问bind 0.0.0.0#redis3.2版本之后加入的特性,yes开启后,如果没有配置bind则默认只允许127.0.0.1访问protected-mode yes#对外暴露的访问端口port 6379#登录密码requirepass devops#主从同步认证密码masterauth devops#三次握手的时候server端接收到客户端 ack确认号之后的队列值tcp-backlog 511#服务端与客户端连接超时时间,0表示永不超时timeout 0#连接redis的时候的密码 hello#requirepass hello#tcp 保持会话时间是300stcp-keepalive 300#redis是否以守护进程运行,如果是,会生成piddaemonize yessupervised no#pid文件路径pidfile /var/run/redis_6379.pid#日志级别loglevel noticelogfile /var/log/redis.log#默认redis有几个db库databases 32#每间隔900秒,如果一个键值发生变化就触发快照机制save 900 1save 300 10save 60 10000#快照出错时,是否禁止redis写入stop-writes-on-bgsave-error no#持久化到rdb文件时,是否压缩文件rdbcompression no#持久化到rdb文件是,是否RC64开启验证rdbchecksum no#持久化输出的时候,rdb文件命名dbfilename dump.rdb#持久化文件路径slave-serve-stale-data yesslave-read-only yesrepl-diskless-sync norepl-diskless-sync-delay 5repl-disable-tcp-nodelay noslave-priority 100#是否开启aof备份appendonly yes#aof备份文件名称appendfilename "appendonly.aof"appendfsync everysecno-appendfsync-on-rewrite noauto-aof-rewrite-percentage 100auto-aof-rewrite-min-size 64mbaof-load-truncated yeslua-time-limit 5000slowlog-log-slower-than 10000slowlog-max-len 128latency-monitor-threshold 0notify-keyspace-events ""hash-max-ziplist-entries 512hash-max-ziplist-value 64list-max-ziplist-size -2list-compress-depth 0set-max-intset-entries 512zset-max-ziplist-entries 128zset-max-ziplist-value 64hll-sparse-max-bytes 3000activerehashing yesclient-output-buffer-limit normal 0 0 0client-output-buffer-limit slave 256mb 64mb 60client-output-buffer-limit pubsub 32mb 8mb 60hz 10aof-rewrite-incremental-fsync yes#客户端最大连接数maxclients 20000lazyfree-lazy-eviction yeslazyfree-lazy-expire yeslazyfree-lazy-server-del yesslave-lazy-flush yesredis哨兵配置文件sentinel.conf
# 哨兵sentinel实例运行的端口 默认26379port 26379# 哨兵sentinel的工作目录dir "/tmp"sentinel deny-scripts-reconfig yessentinel monitor mymaster redis-0.redis 6379 2sentinel auth-pass mymaster devopssentinel down-after-milliseconds mymaster 5000sentinel 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启动脚本run.sh
#!/bin/bashpod_seq=$(echo $POD_NAME | awk -F"-" '{print $2}')if [[ ${pod_seq} -ne 0 ]];then #为从机 sed -i '/^slaveof /d' /opt/conf/redis.conf echo "slaveof redis-0.redis 6379" >> /opt/conf/redis.conf#redis-0.redis代表第一个redis的访问地址fi/usr/local/bin/redis-server /opt/conf/redis.confsleep 15 #如果redis-0没起来,它里面的哨兵也起不来,等待一段时间再启动哨兵/usr/local/bin/redis-sentinel /opt/conf/sentinel.conf &tail -f /var/log/redis.log构建镜像
docker build --pull -t 192.168.1.2/common/redis_sentinel:6.0 .docker push 192.168.1.2/common/redis_sentinel:6.0二、准备k8s yml—redis-sentinel.ymlStatefulSet相关信息可以参考:K8S之StatefulSet有状态服务
apiVersion: apps/v1kind: StatefulSetmetadata: name: redis namespace: redis-nsspec: serviceName: redis selector: matchLabels: app: redis replicas: 3 template: metadata: labels: app: redis spec: nodeSelector: productLine: redis-ns area: wuhan restartPolicy: Always containers: - name: redis image: 192.168.1.2/common/redis_sentinel:6.0 imagePullPolicy: Always env: - name: POD_NAME valueFrom: fieldRef: fieldPath: metadata.name livenessProbe: tcpSocket: port: 6379 initialDelaySeconds: 3 periodSeconds: 5 readinessProbe: tcpSocket: port: 6379 initialDelaySeconds: 3 periodSeconds: 5 ports: - containerPort: 6379 resources: requests: memory: 256Mi cpu: 50m limits: memory: 256Mi cpu: 200m---apiVersion: v1kind: Servicemetadata: name: redis namespace: redis-nsspec: type: NodePort ports: - name: redis port: 6379 targetPort: 6379 nodePort: 26380 selector: app: rediskubectl apply -f redis-sentinel.yml
会创建三个redis pod
kubectl get pod -n redis-ns
kubectl exec -it redis-0 -n redis-ns -- [email protected]:/data# redis-cli127.0.0.1:6379> AUTH devops127.0.0.1:6379> info Replication#查看主从信息
127.0.0.1:6379> [email protected]:/data# redis-cli -p 26379127.0.0.1:26379> info sentinel#查看哨兵信息
k8s其它命令空间的java进程连接redis哨兵
127.0.0.1:6379> [email protected]:/data# redis-cli -p 26379127.0.0.1:26379> info sentinel#查看哨兵信息客户端连接redis
node节点IP:26380 密码:devops
到此这篇关于k8s部署redis哨兵的实现的文章就介绍到这了,更多相关k8s部署redis哨兵 内容请搜索软件开发网以前的文章或继续浏览下面的相关文章希望大家以后多多支持软件开发网!
边栏推荐
- Blog recommendation | in depth study of message segmentation in pulsar
- NPDP能给产品经理带来什么价值?你都知道了吗?
- Filter &(登录拦截)
- Solidty智能合约开发-简易入门
- C learning notes (5) class and inheritance
- One of the first steps to redis
- Solid basic basic grammar and definition function
- What are the requirements for NPDP product manager international certification registration?
- MIT团队使用图神经网络,加速无定形聚合物电解质筛选,促进下一代锂电池技术开发
- Error-tf. function-decorated function tried to create variables on non-first call
猜你喜欢

Opencv Learning Notes 6 -- image mosaic

一波三折,终于找到src漏洞挖掘的方法了【建议收藏】

微信网页订阅消息实现

Cannot link redis when redis is enabled

音乐播放器开发实例(可毕设)

Word2vec yyds dry goods inventory

关于重载运算符的再整理

What are the books that have greatly improved the thinking and ability of programming?

微信公众号订阅消息 wx-open-subscribe 的实现及闭坑指南

Blog recommendation | in depth study of message segmentation in pulsar
随机推荐
使用net core 6 c# 的 NPOI 包,讀取excel..xlsx單元格內的圖片,並存儲到指定服務器
Develop small programs and official account from zero [phase III]
241. Design priorities for operational expressions
Demand prioritization method based on value quantification
Markdown编辑器使用基本语法
[zero basic IOT pwn] reproduce Netgear wnap320 rce
Solidty智能合约开发-简易入门
Fix the failure of idea global search shortcut (ctrl+shift+f)
solidty-基础篇-基础语法和定义函数
Build MySQL master-slave server under Ubuntu 14.04
JVM第二话 -- JVM内存模型以及垃圾回收
Generate random numbers (4-bit, 6-bit)
Take you to API development by hand
Task.Run(), Task.Factory.StartNew() 和 New Task() 的行为不一致分析
solidty-基础篇-结构体和数组,私有 / 公共函数,函数的返回值和修饰符,事件
Error-tf. function-decorated function tried to create variables on non-first call
Flink 系例 之 TableAPI & SQL 与 MYSQL 插入数据
【LeetCode】16、最接近的三数之和
Pat 1065 a+b and C (64bit) (20 points) (16 points)
QT capture interface is displayed as picture or label