美文网首页
redis-cluster部署

redis-cluster部署

作者: 斜阳独倚东楼 | 来源:发表于2020-03-30 16:52 被阅读0次

    redis cluster: 自动,master+slave复制和读写分离,master+slave高可用和主备切换,支持多个master的hash slot支持数据分布式存储

    2.在三台机器上启动6个redis实例

    正式环境下,建议都是说在6台机器上去搭建,至少3台机器,保证,每个master都跟自己的slave不在同一台机器上,如果是6台自然更好,一个master+一个slave就死了

    mkdir -p /etc/redis-cluster

    mkdir -p /var/log/redis

    mkdir -p /var/redis/7001

    port 7001

    cluster-enabled yes

    cluster-config-file /etc/redis-cluster/node-7001.conf

    cluster-node-timeout 15000

    daemonize yes

    pidfile /var/run/redis_7001.pid

    dir /var/redis/7001

    logfile /var/log/redis/7001.log

    bind 192.168.31.187

    appendonly yes

    3.安装脚本

    yum install -y ruby

    yum install -y rubygems

    gem install redis

    如果出现ruby版本太低(通过https://www.jianshu.com/p/7a625eb8cde0进行升级)

    cp /usr/local/redis-3.2.8/src/redis-trib.rb /usr/local/bin

    redis-trib.rb create --replicas 1 192.168.31.187:7001 192.168.31.187:7002 192.168.31.19:7003 192.168.31.19:7004 192.168.31.227:7005 192.168.31.227:7006

    redis-trib.rb check 192.168.31.187:7001

    4.新增机器 (在其中一台机子上新增)master水平扩容

    mkdir -p /var/redis/7007

    port 7007

    cluster-enabled yes

    cluster-config-file /etc/redis-cluster/node-7007.conf

    cluster-node-timeout 15000

    daemonize yes

    pidfile /var/run/redis_7007.pid

    dir /var/redis/7007

    logfile /var/log/redis/7007.log

    bind 192.168.31.227

    appendonly yes

    redis-trib.rb add-node 192.168.31.227:7007 192.168.31.187:7001

    redis-trib.rb check 192.168.31.187:7001

    reshard一些数据过去

    resharding的意思就是把一部分hash slot从一些node上迁移到另外一些node上

    redis-trib.rb reshard 192.168.31.187:7001

    要把之前3个master上,总共4096个hashslot迁移到新的第四个master上去

    How many slots do you want to move (from 1 to 16384)?

    1000

    5、添加node作为slave

    eshop-cache03

    mkdir -p /var/redis/7008

    port 7008

    cluster-enabled yes

    cluster-config-file /etc/redis-cluster/node-7008.conf

    cluster-node-timeout 15000

    daemonize yes

    pidfile /var/run/redis_7008.pid

    dir /var/redis/7008

    logfile /var/log/redis/7008.log

    bind 192.168.31.227

    appendonly yes

    redis-trib.rb add-node --slave --master-id 28927912ea0d59f6b790a50cf606602a5ee48108 192.168.31.227:7008 192.168.31.187:7001

    6.删除node

    先用resharding将数据都移除到其他节点,确保node为空之后,才能执行remove操作

    redis-trib.rb del-node 192.168.31.187:7001 bd5a40a6ddccbd46a0f4a2208eb25d2453c2a8db

    相关文章

      网友评论

          本文标题:redis-cluster部署

          本文链接:https://www.haomeiwen.com/subject/urkkuhtx.html