feat: add more

This commit is contained in:
Sun-ZhenXing
2025-10-06 21:48:39 +08:00
parent f330e00fa0
commit 3c609b5989
120 changed files with 7698 additions and 59 deletions

View File

@@ -0,0 +1,21 @@
# App version
VALKEY_VERSION="8.0-alpine"
# Password for authentication
VALKEY_PASSWORD="passw0rd"
# Node ports (host)
VALKEY_PORT_1=7001
VALKEY_PORT_2=7002
VALKEY_PORT_3=7003
VALKEY_PORT_4=7004
VALKEY_PORT_5=7005
VALKEY_PORT_6=7006
# Cluster bus ports (host)
VALKEY_BUS_PORT_1=17001
VALKEY_BUS_PORT_2=17002
VALKEY_BUS_PORT_3=17003
VALKEY_BUS_PORT_4=17004
VALKEY_BUS_PORT_5=17005
VALKEY_BUS_PORT_6=17006

View File

@@ -0,0 +1,66 @@
# Valkey Cluster
[English](./README.md) | [中文](./README.zh.md)
This service deploys a Valkey cluster with 6 nodes (3 masters and 3 replicas).
## Services
- `valkey-node-1` to `valkey-node-6`: Six Valkey cluster nodes.
- `valkey-cluster-init`: Initialization service that creates the cluster.
## Environment Variables
| Variable Name | Description | Default Value |
| ------------------- | --------------------------- | ------------- |
| VALKEY_VERSION | Valkey image version | `8.0-alpine` |
| VALKEY_PASSWORD | Password for authentication | `passw0rd` |
| VALKEY_PORT_1-6 | Host ports for nodes | 7001-7006 |
| VALKEY_BUS_PORT_1-6 | Host ports for cluster bus | 17001-17006 |
Please modify the `.env` file as needed for your use case.
## Volumes
- `valkey_data_1` to `valkey_data_6`: Volumes for storing Valkey data for each node.
## Cluster Configuration
The cluster is configured with:
- **6 nodes**: 3 masters and 3 replicas
- **Replication factor**: 1 (each master has 1 replica)
- **Hash slots**: Automatically distributed across masters
- **Automatic failover**: Enabled
## Connection
Connect to the cluster using any Valkey/Redis client with cluster mode enabled:
```bash
# Using valkey-cli
valkey-cli -c -h localhost -p 7001 -a passw0rd
# Using redis-cli (compatible)
redis-cli -c -h localhost -p 7001 -a passw0rd
```
## Notes
- The `valkey-cluster-init` service runs once to create the cluster and then stops.
- If you need to recreate the cluster, remove all volumes and restart.
- For production, consider using at least 6 nodes on different machines.
- The cluster requires all nodes to be reachable from each other.
## Scaling
To add more nodes to the cluster:
1. Add new node services to `docker-compose.yaml`
2. Start the new nodes
3. Use `valkey-cli --cluster add-node` to add them to the cluster
4. Rebalance the hash slots if needed
## License
Valkey is licensed under the BSD 3-Clause License.

View File

@@ -0,0 +1,66 @@
# Valkey 集群
[English](./README.md) | [中文](./README.zh.md)
此服务用于部署包含 6 个节点3 个主节点和 3 个副本)的 Valkey 集群。
## 服务
- `valkey-node-1``valkey-node-6`: 六个 Valkey 集群节点。
- `valkey-cluster-init`: 创建集群的初始化服务。
## 环境变量
| 变量名 | 说明 | 默认值 |
| ------------------- | ------------------ | ------------ |
| VALKEY_VERSION | Valkey 镜像版本 | `8.0-alpine` |
| VALKEY_PASSWORD | 认证密码 | `passw0rd` |
| VALKEY_PORT_1-6 | 节点的主机端口 | 7001-7006 |
| VALKEY_BUS_PORT_1-6 | 集群总线的主机端口 | 17001-17006 |
请根据实际需求修改 `.env` 文件。
## 卷
- `valkey_data_1``valkey_data_6`: 用于存储每个节点的 Valkey 数据的卷。
## 集群配置
集群配置如下:
- **6 个节点**: 3 个主节点和 3 个副本
- **复制因子**: 1每个主节点有 1 个副本)
- **哈希槽**: 自动分布在主节点之间
- **自动故障转移**: 已启用
## 连接
使用任何启用集群模式的 Valkey/Redis 客户端连接到集群:
```bash
# 使用 valkey-cli
valkey-cli -c -h localhost -p 7001 -a passw0rd
# 使用 redis-cli兼容
redis-cli -c -h localhost -p 7001 -a passw0rd
```
## 注意事项
- `valkey-cluster-init` 服务运行一次以创建集群,然后停止。
- 如果需要重新创建集群,请删除所有卷并重新启动。
- 对于生产环境,建议在不同的机器上使用至少 6 个节点。
- 集群要求所有节点彼此可达。
## 扩展
要向集群添加更多节点:
1.`docker-compose.yaml` 中添加新的节点服务
2. 启动新节点
3. 使用 `valkey-cli --cluster add-node` 将它们添加到集群
4. 如果需要,重新平衡哈希槽
## 许可证
Valkey 使用 BSD 3-Clause 许可证授权。

View File

@@ -0,0 +1,145 @@
x-default: &default
restart: unless-stopped
volumes:
- &localtime /etc/localtime:/etc/localtime:ro
- &timezone /etc/timezone:/etc/timezone:ro
logging:
driver: json-file
options:
max-size: 100m
x-valkey-node: &valkey-node
<<: *default
image: valkey/valkey:${VALKEY_VERSION:-8.0-alpine}
volumes:
- *localtime
- *timezone
command:
- valkey-server
- --cluster-enabled
- "yes"
- --cluster-config-file
- nodes.conf
- --cluster-node-timeout
- "5000"
- --appendonly
- "yes"
- --requirepass
- ${VALKEY_PASSWORD:-passw0rd}
- --masterauth
- ${VALKEY_PASSWORD:-passw0rd}
deploy:
resources:
limits:
cpus: '0.50'
memory: 512M
reservations:
cpus: '0.25'
memory: 256M
services:
valkey-node-1:
<<: *valkey-node
container_name: valkey-node-1
ports:
- "${VALKEY_PORT_1:-7001}:6379"
- "${VALKEY_BUS_PORT_1:-17001}:16379"
volumes:
- *localtime
- *timezone
- valkey_data_1:/data
valkey-node-2:
<<: *valkey-node
container_name: valkey-node-2
ports:
- "${VALKEY_PORT_2:-7002}:6379"
- "${VALKEY_BUS_PORT_2:-17002}:16379"
volumes:
- *localtime
- *timezone
- valkey_data_2:/data
valkey-node-3:
<<: *valkey-node
container_name: valkey-node-3
ports:
- "${VALKEY_PORT_3:-7003}:6379"
- "${VALKEY_BUS_PORT_3:-17003}:16379"
volumes:
- *localtime
- *timezone
- valkey_data_3:/data
valkey-node-4:
<<: *valkey-node
container_name: valkey-node-4
ports:
- "${VALKEY_PORT_4:-7004}:6379"
- "${VALKEY_BUS_PORT_4:-17004}:16379"
volumes:
- *localtime
- *timezone
- valkey_data_4:/data
valkey-node-5:
<<: *valkey-node
container_name: valkey-node-5
ports:
- "${VALKEY_PORT_5:-7005}:6379"
- "${VALKEY_BUS_PORT_5:-17005}:16379"
volumes:
- *localtime
- *timezone
- valkey_data_5:/data
valkey-node-6:
<<: *valkey-node
container_name: valkey-node-6
ports:
- "${VALKEY_PORT_6:-7006}:6379"
- "${VALKEY_BUS_PORT_6:-17006}:16379"
volumes:
- *localtime
- *timezone
- valkey_data_6:/data
valkey-cluster-init:
<<: *default
image: valkey/valkey:${VALKEY_VERSION:-8.0-alpine}
container_name: valkey-cluster-init
depends_on:
- valkey-node-1
- valkey-node-2
- valkey-node-3
- valkey-node-4
- valkey-node-5
- valkey-node-6
command:
- sh
- -c
- |
sleep 10
valkey-cli -a ${VALKEY_PASSWORD:-passw0rd} --cluster create \
valkey-node-1:6379 \
valkey-node-2:6379 \
valkey-node-3:6379 \
valkey-node-4:6379 \
valkey-node-5:6379 \
valkey-node-6:6379 \
--cluster-replicas 1 \
--cluster-yes
restart: "no"
deploy:
resources:
limits:
cpus: '0.10'
memory: 128M
volumes:
valkey_data_1:
valkey_data_2:
valkey_data_3:
valkey_data_4:
valkey_data_5:
valkey_data_6: