version: '3'

services:

  redis1:
    image: redis:6.2.13
    container_name: redis1
    networks:
      yewu-network:
        ipv4_address: 192.168.177.71
    command: redis-server --port 7001 --cluster-enabled yes --cluster-config-file nodes.conf --cluster-node-timeout 5000 --requirepass FjcpIvWHVSfrZlry --appendonly yes --appendfilename "appendonly.aof" --save ""
    restart: always
    ports:
      - 7001:7001
    volumes:
      - ./redis1-data:/data

  redis2:
    image: redis:6.2.13
    container_name: redis2
    networks:
      yewu-network:
        ipv4_address: 192.168.177.72
    command: redis-server --port 7002 --cluster-enabled yes --cluster-config-file nodes.conf --cluster-node-timeout 5000 --requirepass FjcpIvWHVSfrZlry --appendonly yes --appendfilename "appendonly.aof" --save ""
    restart: always
    ports:
      - 7002:7002
    volumes:
      - ./redis2-data:/data

  redis3:
    image: redis:6.2.13
    container_name: redis3
    networks:
      yewu-network:
        ipv4_address: 192.168.177.73
    command: redis-server --port 7003 --cluster-enabled yes --cluster-config-file nodes.conf --cluster-node-timeout 5000 --requirepass FjcpIvWHVSfrZlry --appendonly yes --appendfilename "appendonly.aof" --save ""
    restart: always
    ports:
      - 7003:7003
    volumes:
      - ./redis3-data:/data

  redis4:
    image: redis:6.2.13
    container_name: redis4
    networks:
      yewu-network:
        ipv4_address: 192.168.177.74
    command: redis-server --port 7004 --cluster-enabled yes --cluster-config-file nodes.conf --cluster-node-timeout 5000 --requirepass FjcpIvWHVSfrZlry --appendonly yes --appendfilename "appendonly.aof" --save ""
    restart: always
    ports:
      - 7004:7004
    volumes:
      - ./redis4-data:/data

  redis5:
    image: redis:6.2.13
    container_name: redis5
    networks:
      yewu-network:
        ipv4_address: 192.168.177.75
    command: redis-server --port 7005 --cluster-enabled yes --cluster-config-file nodes.conf --cluster-node-timeout 5000 --requirepass FjcpIvWHVSfrZlry --appendonly yes --appendfilename "appendonly.aof" --save ""
    restart: always
    ports:
      - 7005:7005
    volumes:
      - ./redis5-data:/data

  redis6:
    image: redis:6.2.13
    container_name: redis6
    networks:
      yewu-network:
        ipv4_address: 192.168.177.76
    command: redis-server --port 7006 --cluster-enabled yes --cluster-config-file nodes.conf --cluster-node-timeout 5000 --requirepass FjcpIvWHVSfrZlry --appendonly yes --appendfilename "appendonly.aof" --save ""
    restart: always
    ports:
      - 7006:7006
    volumes:
      - ./redis6-data:/data


networks:
  yewu-network:
    driver: bridge
    ipam:
      config:
        - subnet: 192.168.177.0/24
    name: yewu-network

部署redis

(1)创建集群

redis-cli -h 192.168.177.71 -p 7001 -a FjcpIvWHVSfrZlry --cluster create 192.168.177.71:7001 192.168.177.72:7002 192.168.177.73:7003 192.168.177.74:7004 192.168.177.75:7005 192.168.177.76:7006 --cluster-replicas 1

2023-11-03T02:26:44.png

(2)连接集群

redis-cli -h 192.168.177.71 -p 7001 -a FjcpIvWHVSfrZlry

(3)查看集群状态是否正常

2023-11-03T02:27:05.png

最后修改:2023 年 11 月 03 日
如果觉得我的文章对你有用,请随意赞赏