docker compose 搭建rdis集群

目录

  • 1、安装pip
  • 2、升级pip
  • 3、安装docker compose
  • 4、查看 docker compose版本
  • 5、先安装 docker compose
  • 6、docker-compose文件书写
  • 7、执行compose命令
  • 8、建立 配置文件
  • 9、执行 建立集群命令
  • 10、参考

1、安装pip

yum -y install epel-release
yum -y install python-pip

2、升级pip

pip install --upgrade pip

3、安装docker compose

pip install docker-compose

4、查看 docker compose版本

docker-compose -version

5、先安装 docker compose

6、docker-compose文件书写

docker-compose.yml

version: '3.4'
services:
  node1:
    image: redis:5.0.5
    container_name: redis-node1
    restart: always
    ports:
      - 6061:6061
      - 16061:16061
    volumes:
      - /home/smb/data/redis-cluster/node1:/data
      - /home/smb/config/redis-cluster/node1:/usr/local/etc/redis
    command:
      redis-server /usr/local/etc/redis/redis.conf
       
  node2:
    image: redis:5.0.5
    container_name: redis-node2
    restart: always
    ports:
      - 6062:6062
      - 16062:16062
    volumes:
      - /home/smb/data/redis-cluster/node2:/data
      - /home/smb/config/redis-cluster/node2:/usr/local/etc/redis
    command:
      redis-server /usr/local/etc/redis/redis.conf
       
       
  node3:
    image: redis:5.0.5
    container_name: redis-node3
    restart: always
    ports:
      - 6063:6063
      - 16063:16063
    volumes:
      - /home/smb/data/redis-cluster/node3:/data
      - /home/smb/config/redis-cluster/node3:/usr/local/etc/redis
    command:
      redis-server /usr/local/etc/redis/redis.conf
       
  node4:
    image: redis:5.0.5
    container_name: redis-node4
    restart: always
    ports:
      - 6064:6064
      - 16064:16064
    volumes:
      - /home/smb/data/redis-cluster/node4:/data
      - /home/smb/config/redis-cluster/node4:/usr/local/etc/redis
    command:
      redis-server /usr/local/etc/redis/redis.conf
       
  node5:
    image: redis:5.0.5
    container_name: redis-node5
    restart: always
    ports:
      - 6065:6065
      - 16065:16065
    volumes:
      - /home/smb/data/redis-cluster/node5:/data
      - /home/smb/config/redis-cluster/node5:/usr/local/etc/redis
    command:
      redis-server /usr/local/etc/redis/redis.conf
       
  node6:
    image: redis:5.0.5
    container_name: redis-node6
    restart: always
    ports:
      - 6066:6066
      - 16066:16066
    volumes:
      - /home/smb/data/redis-cluster/node6:/data
      - /home/smb/config/redis-cluster/node6:/usr/local/etc/redis
    command:
      redis-server /usr/local/etc/redis/redis.conf

7、执行compose命令

docker-compose up -d

8、建立 配置文件

例子
mkdir -p /home/smb/data/redis-cluster/node1
vi /home/bdf/data/redis-cluster/node1/redis.conf

例子:

protected-mode no
port 6061
pidfile /var/run/redis_6061.pid
cluster-enabled yes
cluster-config-file nodes_6061.conf
appendonly yes
cluster-announce-ip 10.9.44.12
cluster-announce-port 6061
cluster-announce-bus-port 16061

修改配置文件 (注意这个文件复制6份放到每个节点配置文件下)

# bind 127.0.0.1 //加上注释#
protected-mode no //关闭保护模式
port 6061  //绑定自定义端口
# daemonize yes //禁止redis后台运行
pidfile /var/run/redis_6061.pid
cluster-enabled yes //开启集群 把注释#去掉
cluster-config-file nodes_6061.conf //集群的配置 配置文件首次启动自动生成
appendonly yes //开启aof
cluster-announce-ip 10.xx.xx.xx   //要宣布的IP地址。nat模式要指定宿主机IP
cluster-announce-port 6061  //要宣布的数据端口。
cluster-announce-bus-port 16061  //要宣布的集群总线端口

docker compose 搭建rdis集群_第1张图片
docker compose 搭建rdis集群_第2张图片

9、执行 建立集群命令

docker run --rm -it zvelo/redis-trib create --replicas 1 10.9.44.12:6061 10.9.44.12:6062 10.9.44.12:6063 10.9.44.12:6064 10.9.44.12:6065 10.9.44.12:6066

10、参考

https://blog.csdn.net/alinyua/article/details/80936940
https://www.cnblogs.com/tswcypy/p/11458704.html

你可能感兴趣的:(docker)