当前位置:网站首页>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
边栏推荐
猜你喜欢

类模板案例-【数组类封装】
![[practical chapter of correlation analysis] why can't Bi software do correlation analysis](/img/f2/4f99deb63b1beffae90b8a1fb270d1.png)
[practical chapter of correlation analysis] why can't Bi software do correlation analysis

微信小程序:全新獨家雲開發微群人脈

Installation and removal of cover for CPU protection on desktop motherboard

Stable currency risk profile: are usdt and usdc safe?

matplotlib直方图,柱状图

BYD has three years left

微信小程序:万圣节头像框生成工具

驱动器实际运用案例

Transport layer user datagram protocol (UDP)
随机推荐
Kubernetes pod troubleshooting guide
Redis master-slave replication principle
Laravel - composer installs the specified laravel version
Wechat applet: install B artifact and P diagram, modify wechat traffic main applet source code, Download funny joke diagram, make server free domain name
【jenkins】pipeline控制多job顺序执行,进行定时持续集成
Wechat applet: repair collection interface version cloud development expression package
东莞虎门券商公司股票开户哪个更好更安全?
c语言入门教程–-6循环语句
Redis' cache avalanche, cache breakdown, cache penetration, cache preheating, and cache degradation
By proxy, by buyout, the wild era of domestic end-to-end travel is waiting for the next "eternal robbery"
织梦dedecms资源素材教程下载网站模板源码(带手机移动端)附安装教程
systemd调试
Underlying implementation principle of five data structures of redis
Why is redis so fast? Is redis single threaded or multi-threaded?
《canvas》之第11章 canvas状态
Nuscenes configuration information about radar
校园转转二手市场源码
Redis' data expiration clearing strategy and memory obsolescence strategy
微信小程序:全新獨家雲開發微群人脈
PostgreSql学习(基于菜鸟课程)