6个节点是不是应该配置成3组主从模式?
时间: 2024-03-22 19:39:14 浏览: 48
是的,您说得对。Redis Cluster 的节点应该配置成 3 组主从模式,每一组有 1 个主节点和 1 个或多个从节点。这样可以保证 Redis Cluster 的高可用性和数据冗余。在 YAML 文件中,您需要按照主从模式的方式配置 `StatefulSet` 和 `redis.conf` 文件。
下面是一个配置 6 个节点、3 组主从模式的 Redis Cluster 的 YAML 配置文件示例(假设每组主从节点分别为 `redis-0`、`redis-1`、`redis-2`):
```yaml
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: redis-cluster
namespace: default
spec:
serviceName: redis-cluster
replicas: 6
selector:
matchLabels:
app: redis-cluster
template:
metadata:
labels:
app: redis-cluster
spec:
affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: app
operator: In
values:
- redis-cluster
topologyKey: "kubernetes.io/hostname"
containers:
- name: redis
image: redis:6.2.5-alpine
command:
- sh
- -c
- "redis-server /redis/redis.conf"
ports:
- containerPort: 6379
name: client
- containerPort: 16379
name: gossip
volumeMounts:
- name: redis-conf
mountPath: /redis
resources:
limits:
cpu: 100m
memory: 128Mi
requests:
cpu: 100m
memory: 128Mi
volumes:
- name: redis-conf
configMap:
name: redis-cluster-config
items:
- key: redis.conf
path: redis.conf
---
apiVersion: v1
kind: Service
metadata:
name: redis-cluster
namespace: default
spec:
type: ClusterIP
selector:
app: redis-cluster
ports:
- name: client
port: 6379
targetPort: 6379
- name: gossip
port: 16379
targetPort: 16379
---
apiVersion: v1
kind: ConfigMap
metadata:
name: redis-cluster-config
namespace: default
data:
redis.conf: |
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 5000
appendonly yes
protected-mode no
cluster-announce-ip {{POD_IP}}
cluster-announce-port 6379
cluster-announce-bus-port 16379
cluster-announce-node-type {{NODE_TYPE}}
cluster-announce-require-auth {{AUTH_PASS}}
requirepass {{AUTH_PASS}}
masterauth {{AUTH_PASS}}
```
其中,`{{POD_IP}}` 为 Kubernetes 中的 Pod IP 地址,`{{NODE_TYPE}}` 为节点类型(`master` 或 `slave`),`{{AUTH_PASS}}` 为 Redis 访问的密码。您需要根据实际情况替换这些变量的值。
阅读全文