当前位置:网站首页>Implementation of deploying redis sentry in k8s
Implementation of deploying redis sentry in k8s
2022-07-01 15:05:00 【1024 questions】
One 、 Get ready redis Mirror image
Two 、 Get ready k8s yml—redis-sentinel.yml
3、 ... and 、 see redis Sentinel information
Four 、 Connect redis sentry
One 、 Get ready redis Mirror imageDockerfile
FROM redis:6.0MAINTAINER Operation and maintenance @ Soldier 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.sh
redis The configuration file redis.conf
# To which machine ,0.0.0.0 Indicates that all hosts are allowed to access bind 0.0.0.0#redis3.2 Features added after version ,yes After opening , If not configured bind Only... Is allowed by default 127.0.0.1 visit protected-mode yes# Exposed access port port 6379# The login password requirepass devops# Master slave synchronous authentication password masterauth devops# Three handshakes server The end receives the client ack The queue value after the confirmation number tcp-backlog 511# Timeout of connection between server and client ,0 Means never time out timeout 0# Connect redis The password at the time of hello#requirepass hello#tcp Keep the conversation for 300stcp-keepalive 300#redis Whether to run as a daemons , If it is , Will generate piddaemonize yessupervised no#pid File path pidfile /var/run/redis_6379.pid# The level of logging loglevel noticelogfile /var/log/redis.log# Default redis There are several db library databases 32# Every interval 900 second , If a key value changes, the snapshot mechanism is triggered save 900 1save 300 10save 60 10000# Error in snapshot , Whether to ban redis write in stop-writes-on-bgsave-error no# Persist to rdb When you file , Whether to compress the file rdbcompression no# Persist to rdb File is , whether RC64 Turn on Validation rdbchecksum no# When persisting output ,rdb File naming dbfilename dump.rdb# Persistent file path slave-serve-stale-data yesslave-read-only yesrepl-diskless-sync norepl-diskless-sync-delay 5repl-disable-tcp-nodelay noslave-priority 100# Open or not aof Backup appendonly yes#aof Backup file name 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# Maximum number of client connections maxclients 20000lazyfree-lazy-eviction yeslazyfree-lazy-expire yeslazyfree-lazy-server-del yesslave-lazy-flush yes
redis Sentry profile sentinel.conf
# sentry sentinel The port on which the instance runs Default 26379port 26379# sentry sentinel Working directory of 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# Set up 5 No response in seconds , The server is down , You need to put the configuration in sentinel monitor master 127.0.0.1 6379 below sentinel parallel-syncs mymaster 2# Set up 15 Seconds master Not alive , Re elect the Lord sentinel config-epoch mymaster 3#. Said if master After re selecting , Other slave Nodes can run in parallel at the same time master How many synchronous caches are there , Obviously the greater the value , all slave The faster the node can complete the synchronous handover , But if someone happens to be visiting these slave, It's possible to make # Failed to read , It will have a wider impact . The most stable setting is 1, Only at the same time , Only one can do it , So other slave And continue to serve , But all slave The process of complete cache update synchronization will be slow .sentinel leader-epoch mymaster 3
The startup script run.sh
#!/bin/bashpod_seq=$(echo $POD_NAME | awk -F"-" '{print $2}')if [[ ${pod_seq} -ne 0 ]];then # For slave sed -i '/^slaveof /d' /opt/conf/redis.conf echo "slaveof redis-0.redis 6379" >> /opt/conf/redis.conf#redis-0.redis On behalf of the first redis Access address of fi/usr/local/bin/redis-server /opt/conf/redis.confsleep 15 # If redis-0 Didn't get up , The sentry in it can't get up , Wait a while before starting the sentry /usr/local/bin/redis-sentinel /opt/conf/sentinel.conf &tail -f /var/log/redis.log
Build a mirror image
docker build --pull -t 192.168.1.2/common/redis_sentinel:6.0 .docker push 192.168.1.2/common/redis_sentinel:6.0
Two 、 Get ready k8s yml—redis-sentinel.ymlStatefulSet Please refer to :K8S And StatefulSet Stateful service
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: redis
kubectl apply -f redis-sentinel.yml
Will create three 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# View master-slave information
127.0.0.1:6379> [email protected]:/data# redis-cli -p 26379127.0.0.1:26379> info sentinel# Check the sentry information
k8s Other command space java Process connection redis sentry
127.0.0.1:6379> [email protected]:/data# redis-cli -p 26379127.0.0.1:26379> info sentinel# Check the sentry information
Client connection redis
node node IP:26380 password :devops
This is about k8s Deploy redis This is the end of the article on the implementation of sentinel , More about k8s Deploy redis sentry Please search the previous articles of software development network or continue to browse the relevant articles below. I hope you will support software development network more in the future !
边栏推荐
- JVM第一话 -- JVM入门详解以及运行时数据区分析
- What is the relationship between network speed, broadband, bandwidth and traffic?
- 适合没口才的人做,加入中视频伙伴计划收益是真香,一个视频拿3份收益
- SQL常用的四个排序函数梳理
- NPDP能给产品经理带来什么价值?你都知道了吗?
- 竣达技术丨室内空气环境监测终端 pm2.5、温湿度TVOC等多参数监测
- 基于价值量化的需求优先级排序方法
- Internet hospital system source code hospital applet source code smart hospital source code online consultation system source code
- 炎炎夏日,这份安全用气指南请街坊们收好!
- Tableapi & SQL and Kafka message insertion in Flink
猜你喜欢
Task. Run(), Task. Factory. Analysis of behavior inconsistency between startnew() and new task()
C learning notes (5) class and inheritance
[零基础学IoT Pwn] 复现Netgear WNAP320 RCE
官宣:Apache Doris 顺利毕业,成为 ASF 顶级项目!
leetcode:329. 矩阵中的最长递增路径
Filter &(登录拦截)
厦门灌口镇田头村特色农产品 甜头村特色农产品蚂蚁新村7.1答案
关于重载运算符的再整理
Filter & (login interception)
Word2vec yyds dry goods inventory
随机推荐
Chapter 4 of getting started with MySQL: creation, modification and deletion of data tables
对于编程思想和能力有重大提升的书有哪些?
go-zero实战demo(一)
Summary of empty string judgment in the project
[leetcode 324] swing sorting II thinking + sorting
一波三折,终于找到src漏洞挖掘的方法了【建议收藏】
Implementation of wechat web page subscription message
What are the requirements for NPDP product manager international certification registration?
[zero basic IOT pwn] reproduce Netgear wnap320 rce
Tableapi & SQL and MySQL data query of Flink
In hot summer, please put away this safe gas use guide!
音乐播放器开发实例(可毕设)
Mongodb second talk - - mongodb High available Cluster Implementation
这3款在线PS工具,得试试
Internet hospital system source code hospital applet source code smart hospital source code online consultation system source code
NPDP产品经理国际认证报名有什么要求?
[lock] redis lock handles concurrency atomicity
The markdown editor uses basic syntax
JVM second conversation -- JVM memory model and garbage collection
基于价值量化的需求优先级排序方法