• Redis 3.2.8集群+Sentinel部署


    Redis3.2.8集群搭建

    采用官方推荐的三主三从分片方案,本例中所有节点部署在一台主机上。

    软件安装:

    tar zxvf redis-3.2.8.tar.gz

    cd  redis-3.2.8

    make

    make install 

    mkdir redis-cluster

    根据端口号,创建六个节点

    mkdir redis-cluser/6379、6380、6381、6382、6383、6384

    拷贝配置文件到各个节点:

    cp redis.conf  redis-cluser/6379、6380、6381、6382、6383、6384

    修改配置文件:

    vim redis-cluser/6379、6380、6381、6382、6383、6384/redis.conf

    port    #端口号

    pidfile #pid文件

    logfile "/data/local/redis-cluster/6379/redis.log"  #日志文件

    cluster-enabled yes  #开启集群模式

    cluster-config-file nodes-6380.conf

    若需要远程连接,需要注释掉bind 127.0.0.1 改为 bind 0.0.0.0

    启动:redis-server 6379、6380、81、82、83、84/redis.conf

    安装redis-trib.rb工具:

    安装依赖组件:yum install ruby ruby-devel rubygems rpm-build

    gem install redis

    # redis-trib.rb create --replicas 1 127.0.0.1:6379 127.0.0.1:6380 127.0.0.1:6381 127.0.0.1:6382 127.0.0.1:6383 127.0.0.1:6384

    创建集群,每个节点有一个从节点

    >>> Creating cluster
    >>> Performing hash slots allocation on 6 nodes...
    Using 3 masters:
    127.0.0.1:6379
    127.0.0.1:6380
    127.0.0.1:6381
    Adding replica 127.0.0.1:6382 to 127.0.0.1:6379
    Adding replica 127.0.0.1:6383 to 127.0.0.1:6380
    Adding replica 127.0.0.1:6384 to 127.0.0.1:6381
    M: 46af51f0d193f3e76b322537bc11f9570ca13930 127.0.0.1:6379
       slots:0-5460 (5461 slots) master
    M: 3caa86acc90199cd882475dc08622fdd522cf9a8 127.0.0.1:6380
       slots:5461-10922 (5462 slots) master
    M: 01152da2da00e48384714c609241d2f83ca7bdc9 127.0.0.1:6381
       slots:10923-16383 (5461 slots) master
    S: 825f0c904c8337d6eb8b5685e9b46fe36f7e9e99 127.0.0.1:6382
       replicates 46af51f0d193f3e76b322537bc11f9570ca13930
    S: 0c01889b111948f334950e84aea677658d91f1bc 127.0.0.1:6383
       replicates 3caa86acc90199cd882475dc08622fdd522cf9a8
    S: 567f1760b13de130a63396cc4e6983af5f6bca24 127.0.0.1:6384
       replicates 01152da2da00e48384714c609241d2f83ca7bdc9
    Can I set the above configuration? (type 'yes' to accept): 

    yes:

    >>> Nodes configuration updated
    >>> Assign a different config epoch to each node
    >>> Sending CLUSTER MEET messages to join the cluster
    Waiting for the cluster to join..
    >>> Performing Cluster Check (using node 127.0.0.1:6379)
    M: 46af51f0d193f3e76b322537bc11f9570ca13930 127.0.0.1:6379
       slots:0-5460 (5461 slots) master
       1 additional replica(s)
    S: 0c01889b111948f334950e84aea677658d91f1bc 127.0.0.1:6383
       slots: (0 slots) slave
       replicates 3caa86acc90199cd882475dc08622fdd522cf9a8
    S: 825f0c904c8337d6eb8b5685e9b46fe36f7e9e99 127.0.0.1:6382
       slots: (0 slots) slave
       replicates 46af51f0d193f3e76b322537bc11f9570ca13930
    S: 567f1760b13de130a63396cc4e6983af5f6bca24 127.0.0.1:6384
       slots: (0 slots) slave
       replicates 01152da2da00e48384714c609241d2f83ca7bdc9
    M: 3caa86acc90199cd882475dc08622fdd522cf9a8 127.0.0.1:6380
       slots:5461-10922 (5462 slots) master
       1 additional replica(s)
    M: 01152da2da00e48384714c609241d2f83ca7bdc9 127.0.0.1:6381
       slots:10923-16383 (5461 slots) master
       1 additional replica(s)
    [OK] All nodes agree about slots configuration.
    >>> Check for open slots...
    >>> Check slots coverage...
    [OK] All 16384 slots covered.

    注:使用redis-trib.rb create --replicas 1 这种方式创建主从集群的前提是,至少有6个节点,3主3从

     sentinel

    sentinel.conf:

    注释默认相关配置,添加master监控:

    sentinel monitor master1 127.0.0.1 6379 2
    sentinel down-after-milliseconds master1 60000
    sentinel failover-timeout master1 180000
    sentinel parallel-syncs master1 1
    
    sentinel monitor master2 127.0.0.1 6380 2
    sentinel down-after-milliseconds master2 60000
    sentinel failover-timeout master2 180000
    sentinel parallel-syncs master2 1
    
    sentinel monitor master3 127.0.0.1 6381 2
    sentinel down-after-milliseconds master3 60000
    sentinel failover-timeout master3 180000
    sentinel parallel-syncs master3 1

     #redis-server sentinel.conf --sentinel &

    98310:X 21 Apr 09:50:47.694 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
    98310:X 21 Apr 09:50:47.695 # Sentinel ID is 5c014c848accbbec31b53187b9434356f27ad074
    98310:X 21 Apr 09:50:47.695 # +monitor master master2 127.0.0.1 6380 quorum 2
    98310:X 21 Apr 09:50:47.695 # +monitor master master3 127.0.0.1 6381 quorum 2
    98310:X 21 Apr 09:50:47.695 # +monitor master master1 127.0.0.1 6379 quorum 2

    配置后台启动:

    sentinel.conf,添加:

    daemonize yes

    启动:

    #redis-server sentinel.conf --sentinel 

     ========================华丽分割======================

    Redis 3.2 1主1从配置:

    主:

    cluster-enabled no

    logfile /data/local/redis-cluster/6379/redis.log

    requirepass password

    从:

    cluster-enabled no

    logfile /data/local/redis-cluster/6380/redis.log

    requirepass password

    slaveof 127.0.0.1 6379

    masterauth password   必须要注定同步master时的认证密码,否则同步失败。

    启动redis,查看主从状态:

    #redis-cli -p 6380
    >auth password
    >info 
    
    
    ...
    # Replication
    role:slave
    master_host:127.0.0.1
    master_port:6379
    master_link_status:up
    ...
  • 相关阅读:
    IEEEXtreme 10.0
    IEEEXtreme 10.0
    IEEEXtreme 10.0
    IEEEXtreme 10.0
    IEEEXtreme 10.0
    IEEEXtreme 10.0
    Python/Anaconda多版本共存的解决方案
    玩转树莓派
    通过远程桌面连接树莓派
    树莓派的初次启动设置
  • 原文地址:https://www.cnblogs.com/ahaii/p/6740537.html
Copyright © 2020-2023  润新知