Redis
集群
Docker
-
docker-compose.yml
services: redis: image: redis:7.4.0 container_name: redis volumes: - /etc/localtime:/etc/localtime:ro - /opt/redis/conf:/usr/local/etc/redis - /opt/redis/data:/data environment: - TZ=Asia/Shanghai command: - redis-server - /usr/local/etc/redis/redis.conf network_mode: host restart: always
-
redis.conf
bind 0.0.0.0 port 6379 appendonly yes loglevel notice cluster-enabled yes cluster-config-file nodes.conf cluster-node-timeout 5000 cluster-announce-ip x.x.x.x
-
启动
docker compose -f docker-compose.yml up -d
-
添加节点
redis-cli --cluster create 192.168.26.11:6379 192.168.26.12:6379 192.168.26.13:6379 192.168.26.14:6379 192.168.26.15:6379 192.168.26.16:6379 192.168.26.17:6379 192.168.26.18:6379 --cluster-replicas 1 docker exec -it redis redis-cli CLUSTER MEET x.x.x.x 6379 CLUSTER INFO CLUSTER NODES
单机
Docker
-
docker-compose.yml
services: redis: image: redis:7.4.0 container_name: redis volumes: - /etc/localtime:/etc/localtime:ro - /opt/redis/conf:/usr/local/etc/redis - /opt/redis/data:/data environment: - TZ=Asia/Shanghai command: - redis-server - /usr/local/etc/redis/redis.conf network_mode: host restart: always
-
redis.conf
bind 0.0.0.0 port 6379 appendonly yes loglevel notice
-
启动
docker compose -f docker-compose.yml up -d