当前位置:网站首页>Deploy redis sentry in k8s
Deploy redis sentry in k8s
2022-06-29 14:38:00 【Operation and maintenance @ small soldier】
List of articles
One 、 Get ready redis Mirror image
Dockerfile
FROM redis:6.0
MAINTAINER Operation and maintenance @ Soldier
COPY *.conf /opt/conf/
COPY run.sh /opt/run.sh
RUN apt update -y;apt-get install vim net-tools -y;apt-get clean && \
chmod +x /opt/run.sh
CMD /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 300s
tcp-keepalive 300
#redis Whether to run as a daemons , If it is , Will generate pid
daemonize yes
supervised no
#pid File path
pidfile /var/run/redis_6379.pid
# The level of logging
loglevel notice
logfile /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 1
save 300 10
save 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 yes
slave-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
slave-priority 100
# Open or not aof Backup
appendonly yes
#aof Backup file name
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
aof-rewrite-incremental-fsync yes
# Maximum number of client connections
maxclients 20000
lazyfree-lazy-eviction yes
lazyfree-lazy-expire yes
lazyfree-lazy-server-del yes
slave-lazy-flush yes
redis Sentry profile sentinel.conf
# sentry sentinel The port on which the instance runs Default 26379
port 26379
# sentry sentinel Working directory of
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
# 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 , However, such as
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 the
Yes slave The process of complete cache update synchronization will be slow .
sentinel leader-epoch mymaster 3
The startup script run.sh
#!/bin/bash
pod_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.conf
sleep 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.yml
StatefulSet Please refer to :K8S And StatefulSet Stateful service
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: redis
namespace: redis-ns
spec:
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: v1
kind: Service
metadata:
name: redis
namespace: redis-ns
spec:
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

3、 ... and 、 see redis Sentinel information
kubectl exec -it redis-0 -n redis-ns -- bash
[email protected]:/data# redis-cli
127.0.0.1:6379> AUTH devops
127.0.0.1:6379> info Replication # View master-slave information

127.0.0.1:6379> exit
[email protected]:/data# redis-cli -p 26379
127.0.0.1:26379> info sentinel # Check the sentry information

Four 、 Connect redis sentry
k8s Other command space java Process connection redis sentry
spring:
redis:
database: 4
# redis The Sentinel's address
sentinel:
master: mymaster
nodes: redis-0.redis.redis-demo.svc.cluster.local:26379,redis-1.redis.redis-demo.svc.cluster.local:26379,redis-2.redis.redis-demo.svc.cluster.local:26379
# redis Access password ( The default is empty. )
password: devops
Client connection redis
node node IP:26380 password :devops
边栏推荐
- 一位博士在华为的22年
- Turbulent intermediary business, restless renters
- Wechat applet: install B artifact and P diagram, modify wechat traffic main applet source code, Download funny joke diagram, make server free domain name
- unity吃豆人小游戏,迷宫实现
- Source code of campus secondary market
- Introduction to bloom filter
- Transport layer user datagram protocol (UDP)
- Kubernetes Pod 排错指南
- Persistence mechanism of redis
- [use of veux developer tools - use of getters]
猜你喜欢

Are you still reading the log by command? Use kibana, one picture is better than ten thousand lines of log

uniApp问题清单与经验

传输层 选择性确认 SACK
![[important notice] the 2022 series of awards and recommendations of China graphics society were launched](/img/ae/2fe0cf9964e5fd3b18e5f295638d8b.png)
[important notice] the 2022 series of awards and recommendations of China graphics society were launched

Whitelabel Error Page访问

Dynamics 365Online Lookup查找字段多选

Practical application cases of drives

微信小程序:装B神器P图修改微信流量主小程序源码下载趣味恶搞图制作免服务器域名
redis 分片集群搭建与使用教程

内网穿透(nc)
随机推荐
《canvas》之第7章 变形操作
Campus errands wechat applet errands students with live new source code
【Qt 教程】QPushButton 按键和双击效果
Thanos store component
灵感收集·创意写作软件评测:Flomo、Obsidian Memo、Napkin、FlowUs
传输层 用户数据报协议(UDP)
Redis' data expiration clearing strategy and memory obsolescence strategy
精品商城拼团秒杀优惠折扣全功能完美双端自适应对接个人免签网站源码
部署搭建decentraland流程讲解
自动注入@Resource和@Autowired注解的区别:
Redis的事务机制
Goby full port scan
【重要通知】中国图象图形学学会2022年度系列奖励推荐工作启动
QRcode custom QR code middle picture
Kubernetes Pod 排错指南
[top] blog instructions, bulletin board, message board, about bloggers
内网穿透(nc)
Dynamics 365Online Lookup查找字段多选
Wechat applet: Halloween avatar box generation tool
Chapter 13 event operation of canvas