docker搭建redisCluster集群

假設(shè)當(dāng)前目錄為/data/db/redis

  1. 下載redis配置文件 http://download.redis.io/redis-stable/redis.conf
  2. 創(chuàng)建config目錄,將下載的redis.conf復(fù)制到config目錄,修改如下信息
#bind 127.0.0.1               #注釋掉地址綁定
port 700*                    #3份配置文件,從7001到7003
appendonly yes                #允許持久化
cluster-enable yes             #啟用集群
cluster-config-file nodes-700*.conf  #存放節(jié)點(diǎn)配置信息的文件名,從7001到7003
cluster-node-timeout 15000        #節(jié)點(diǎn)失效檢測(cè)的超時(shí)時(shí)間

在config目錄下分別創(chuàng)建redis-7001.conf, redis-7002.conf, redis-7003.conf

  1. 創(chuàng)建7001, 7002, 7003目錄
  2. 創(chuàng)建docker-compose.yml文件
version: "3.8"
services:
  redis-master1:
    image: redis:latest
    container_name: redis-7001
    #stdin_open: true
    tty: true
    restart: always
    network_mode: host  #需要為host模式
    privileged: true
    volumes:
    - /data/db/redis/config/redis-7001.conf:/usr/local/etc/redis/redis.conf
    - ./7001:/data
    command:
      redis-server /usr/local/etc/redis/redis.conf
  redis-master2:
    image: redis:latest
    container_name: redis-7002
    tty: true
    restart: always
    network_mode: host
    privileged: true
    volumes:
    - /data/db/redis/config/redis-7002.conf:/usr/local/etc/redis/redis.conf
    - ./7002:/data
    command:
      redis-server /usr/local/etc/redis/redis.conf
  redis-master3:
    image: redis:latest
    container_name: redis-7003
    tty: true
    restart: always
    network_mode: host
    privileged: true
    volumes:
    - /data/db/redis/config/redis-7003.conf:/usr/local/etc/redis/redis.conf
    - ./7003:/data
    command:
      redis-server /usr/local/etc/redis/redis.conf
  1. 啟動(dòng)redis服務(wù)
docker-compose up -d
  1. 進(jìn)入其中一臺(tái)容器,進(jìn)行集群創(chuàng)建
docker exec -it redis-7001 bash
redis-cli --cluster create 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 --cluster-replicas 0

此時(shí)根據(jù)命令行提示輸入yes,即可創(chuàng)建集群成功

注:
官方備注,網(wǎng)絡(luò)模式需要為host


image.png
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 在企業(yè)應(yīng)用中,對(duì)于數(shù)據(jù)的固化一般采用數(shù)據(jù)庫,但是數(shù)據(jù)庫的吞吐量還是存在一定的問題的,在高并發(fā)高吞吐要求時(shí),一般會(huì)直...
    丁小晶的晶小丁閱讀 65,073評(píng)論 4 11
  • 在我的docker安裝redis里,已經(jīng)說明過docker安裝redis的流程,對(duì)于redis的安裝下面文章很多部...
    szgl_lucifer閱讀 12,914評(píng)論 1 23
  • Redis集群 使用redis做緩存工具 實(shí)現(xiàn)系統(tǒng)高可用,redis需要做主備。使用redis做分片集群。 向業(yè)務(wù)...
    tanghuibook閱讀 611評(píng)論 0 0
  • 一、 簡介redis cluster是一個(gè)提供在多個(gè)redis間節(jié)點(diǎn)間共享數(shù)據(jù)的程序集。redis 集群通過分區(qū)來...
    谷悅古月閱讀 797評(píng)論 0 1
  • 久違的晴天,家長會(huì)。 家長大會(huì)開好到教室時(shí),離放學(xué)已經(jīng)沒多少時(shí)間了。班主任說已經(jīng)安排了三個(gè)家長分享經(jīng)驗(yàn)。 放學(xué)鈴聲...
    飄雪兒5閱讀 7,809評(píng)論 16 22

友情鏈接更多精彩內(nèi)容