标签:单机版 name cluster -- max redis 6379 集群
可能格式不怎么好看,就是提供一个思路
1、编写一个config文件,给挂载到k8s容器里。这个文件是从网上找的,这个脚本没什么改的,redis的配置文件,可以根据自己的需求做修改
添加config.yaml文件
apiVersion: v1
kind: ConfigMap
metadata:
name: redis-cluster-config
data:
fix-ip.sh: |
#!/bin/sh
CLUSTER_CONFIG="/data/nodes.conf"
if [ -f ${CLUSTER_CONFIG} ]; then
if [ -z "${POD_IP}" ]; then
echo "Unable to determine Pod IP address!"
exit 1
fi
echo "Updating my IP to ${POD_IP} in ${CLUSTER_CONFIG}"
sed -i.bak -e '/myself/ s/[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}/'${POD_IP}'/' ${CLUSTER_CONFIG}
fi
exec "$@"
redis.conf: |
cluster-enabled yes
cluster-config-file /data/nodes.conf
cluster-node-timeout 10000
protected-mode no
daemonize no
pidfile /var/run/redis.pid
port 6379
tcp-backlog 511
bind 0.0.0.0
timeout 3600
tcp-keepalive 1
loglevel verbose
logfile /data/redis.log
databases 16
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir /data
appendonly yes
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
lua-time-limit 20000
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-entries 512
list-max-ziplist-value 64
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
2、编写一个server文件,做k8s里redis集群节点通信使用
添加一个server.yaml
apiVersion: v1
kind: Service
metadata:
name: redis-cluster
labels:
app: redis-cluster
spec:
ports:
- port: 6379
name: redis
clusterIP: None
selector:
app: redis-cluster
3、编写redis的pod资源文件,里面需要注意的几点,1、镜像用redis6.0以上的,我这边使用的是7.2的。2、我使用的的是volumeClaimTemplates做redis的节点数据持久化处理,因为这种集群搭建,每个pod都会有自己的数据目录,由storageClass去自动生成pvc是最方便的。
添加pod.yaml
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: redis-cluster
spec:
serviceName: redis-cluster
replicas: 6
selector:
matchLabels:
app: redis-cluster
template:
metadata:
labels:
app: redis-cluster
spec:
containers:
- name: redis
image: redis:7.2.1
ports:
- containerPort: 6379
command: ["/etc/redis/fix-ip.sh", "redis-server", "/etc/redis/redis.conf"]
env:
- name: POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
volumeMounts:
- name: redis-config
mountPath: /etc/redis/
readOnly: false
- name: redis-data
mountPath: /data
volumes:
- name: redis-config
configMap:
name: redis-cluster-config
defaultMode: 0755
volumeClaimTemplates:
- metadata:
name: redis-data
spec:
storageClassName: "nas-c"
accessModes:
- ReadWriteMany
resources:
requests:
storage: 50Gi
4、这几步做完,至少redis的pod是能正常启动了,然后开始初始化集群
1、获取这几个redis-pod的ip:kubectl get pods -l app=redis-cluster -o jsonpath='{range.items[*]}{.status.podIP}:6379'。
2、初始化集群:redis-cli --cluster create 10.100.166.152:6379 10.100.104.80:6379 10.100.103.133:6379 10.100.199.215:6379 10.100.206.241:6379 10.100.3.108:6379 --cluster-replicas 1
上面这几个ip信息,注意用空格隔开。
3、进入一个pod,使用命令redis-cli 进入redis的交互界面
命令cluster info
命令cluster nodes
都可以查看集群信息
5、redis集群模式,官方给的规则是只有db0,也可以自己去改配置文件新增db数量
6、数据导入:redis-cli --cluster import 127.0.0.1:6379 --cluster-from 10.100.33.188:6379 --cluster-copy --cluster-replace
找个有redis-cli命令的客户端就可以执行,
import 127.0.0.1:6379 是目标redis信息,
--cluster-from 10.100.33.188:6379 是有原始数据的redis信息。
--cluster-copy 是表示数据只复制,不用消费掉老数据,这样如果迁移错误,也不会有太大问题
标签:单机版,
name,
cluster,
--,
max,
redis,
6379,
集群
From: https://www.cnblogs.com/2019peng/p/18367498