• 基于docker搭建redis集群三主三从


    #拉去镜像(注:我这里拉取过了,和你们显示的有出入

    [root@centos-linux ~]# docker pull redis

     

    [root@centos-linux ~]# docker images

     

      #创建集群目录

    [root@centos-linux ~]# mkdir redis-cluster-d
    [root@centos-linux ~]# cd redis-cluster-d/

    #创建执行文件

    [root@centos-linux redis-cluster-d]# vi redis-cluster.tmpl

    文件内容

    port ${PORT}
    
    masterauth 123456
    
    requirepass 123456
    
    cluster-enabled yes
    
    cluster-config-file nodes.conf
    
    cluster-node-timeout 5000
    
    cluster-announce-ip 127.0.0.1
    
    cluster-announce-port ${PORT}
    
    cluster-announce-bus-port 1${PORT}
    
    appendonly yes

     #使用命令:在 redis-cluster下生成conf和data目标,并生成配置信息

    [root@centos-linux redis-cluster-d]# for port in `seq 7001 7006`; do 
    > mkdir -p ./${port}/conf 
    >  && PORT=${port} envsubst < ./redis-cluster.tmpl > ./${port}/conf/redis.conf 
    > && mkdir -p ./${port}/data; 
    > done

    #后会生成一下目录

     #创建六个redis容器

    [root@centos-linux redis-cluster-d]# for port in `seq 7001 7006`; do
    > docker run -d --net=host -v /root/redis-cluster-d/${port}/conf/redis.conf:/etc/redis/redis.conf -v /root/redis-cluster-d/${port}/data:/data --restart always --name=redis-${port}  redis redis-server /etc/redis/redis.conf;
    > done

    #进入容器

    [root@centos-linux redis-cluster-d]# docker exec -it redis-7001 bash
    root@centos-linux:/data# redis-cli -a 123456 --cluster create 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005 127.0.0.1:7006 --cluster-replicas 1

     #成功案例,您可以往下执行这个操作

    root@centos-linux:/data# redis-cli -c -a 123456  -h 127.0.0.1  -p 7001
    Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
    127.0.0.1:7001> CLUSTER NODES
    d18b5b8bc8d2774278d02ca5ecfa7c025fa9f7ac 127.0.0.1:7002@17002 master - 0 1599118838500 2 connected 5461-10922
    3c3bbdce11728349eb90dfca026e41f00766aff9 127.0.0.1:7006@17006 slave 98ce25ac939261ce8df525644c91370b453a172d 0 1599118839003 1 connected
    85a963da313fe027aab61447aa57f615a2588735 127.0.0.1:7003@17003 master - 0 1599118837000 3 connected 10923-16383
    98ce25ac939261ce8df525644c91370b453a172d 127.0.0.1:7001@17001 myself,master - 0 1599118837000 1 connected 0-5460
    5c286fe58f43e19e8d2f8e749b4b93bc8a169b49 127.0.0.1:7005@17005 slave 85a963da313fe027aab61447aa57f615a2588735 0 1599118837997 3 connected
    a8a07776bb87eca78c56fe80e48dfafbd4d49390 127.0.0.1:7004@17004 slave d18b5b8bc8d2774278d02ca5ecfa7c025fa9f7ac 0 1599118837494 2 connected
    127.0.0.1:7001> 

     #######****************插播一个错误*****************###########

    #下面标记红的waiting一直停不下来,说明创建集群的ip和redis.conf的ip对不上

    去往学习的路上,请多多指教。。。。

    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.
  • 相关阅读:
    一行命令搞定node.js 版本升级
    doesn't contain a valid partition table 解决方法
    debian kill 进程等命令
    FastDFS配置说明(中英文)
    FastDFS问题汇总
    FastDFS常见命令
    FastDFS安装配置手册
    windows 与Linux 互传文件
    FtpClient中文乱码问题解决
    windows 配置host
  • 原文地址:https://www.cnblogs.com/name-lizonglin/p/13607646.html
Copyright © 2020-2023  润新知