使用Docker compose搭建Redis高可用哨兵集群

一、前言

本教程主要用于使用Docker compose在centos服务器中快速搭建redis哨兵集群,对redis配置相对较少,如果要对redis进行配置,只需要进行文件

二、Docker安装

Docker安装和使用教程

三、搭建Redis主从集群

  1. 创建一个文件夹(名字自取,这里使用Redis-Sentinel),其结构如下

    • 文件夹结构:

      Redis-Sentinel
      |-- master-slave  存储主从集群配置文件
      `-- sentinel   存储所有哨兵配置文件
          |-- sentinel1   存储哨兵1配置文件
          |-- sentinel2   存储哨兵2配置文件
          `-- sentinel3   存储哨兵3配置文件
      
      
    • 指令:

      mkdir -p Redis-Sentinel/master-slave Redis-Sentinel/sentinel/sentinel1 Redis-Sentinel/sentinel/sentinel2 Redis-Sentinel/sentinel/sentinel3
      
  2. 进入master-slave文件夹下:

cd master-slave
  1. 编写docker-compose.yml文件

    • 创建docker-compose.yml文件

      vim docker-compose.yml
      
    • 编辑docker-compose.yml文件

      services:
        master:
          image: redis
          container_name: redis-master
          networks:
            - redisco
          command: bash -c "redis-server --protected-mode no --slave-announce-ip 43.143.212.194 --slave-announce-port 6379"
          ports:
            - 6379:6379
        slave1:
          image: redis
          container_name: redis-slave-1
          networks:
            - redisco
          ports:
            - 6380

你可能感兴趣的:(Redis,docker,redis,容器,sentinel)