zoukankan      html  css  js  c++  java
  • Redis集群环境安装指南

    环境

    RHLinux-6.4-64-EN, 红帽6.4 64位,英文正式公布版。

    Redis3.0.0

    • redis2.x版本号还不支持集群,3.0版本号将会支持,如今3.0版本号还在开发中,如今是beta-3版本号(截止2014-5-8),但功能是可用的。
    • 下载Redis3.0.0 beta-3版本号,点击这里下载。
    • Redis3的安装能够參照之前的单机安装指南操作。

    创建Redis集群实例

    • 创建集群节点的目录,先创建cluster-test目录,再以port为名称创建子目录。这里我们要创建6个Redis实例,3个作为master,3个作为slave。
    1
    2
    3
    
    mkdir cluster-test
    cd cluster-test
    mkdir 7000 7001 7002 7003 7004 7005
    
    • 在每一个目录以下创建创建Redis配置文件,注意依据不同实例的port号改动以下的配置文件,nodes.conf文件为Redis实例启动时自己主动生成。
    1
    2
    3
    4
    5
    
    port 7000
    cluster-enabled yes
    cluster-config-file nodes.conf
    cluster-node-timeout 5000
    appendonly yes
    
    • 开6个terminal窗体,分别启动这6个Redis实例。
    1
    2
    
    cd 7000
    ../redis-server ./redis.conf
    
    • 当成功启动后,能看到每一个terminal出现以下的字样,是由于node.conf文件不存在,所以给每一个实例分配了一个新的ID。
    1
    
    [82462] 26 Nov 11:56:55.329 * No cluster configuration found, I'm 97a3a64667477371c4479320d683e4c8db5858b1
    

    创建集群

    • 如今Redis的6个实例都已经启动了,如今来開始创建集群。创建集群用到了一个ruby文件,放在redis3文件夹的src子文件夹下,找到后运行下面命令。这里的-replicas 1表示每一个master配备1个slave,后面的參数就是6个实例的ip加port,以空格隔开。
    1
    2
    3
    
    cd redis-3.0.0-beta3/src
    ./redis-trib.rb create --replicas 1 127.0.0.1:7000 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
    
    • 运行命令后会提示你是否接受提示的配置信息,默认的是前3台作为master机器,后3台作为slave机器,输入yes,出现最后的信息表示集群已经创建好了。
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    
    Creating cluster
    Connecting to node 127.0.0.1:7000: OK
    Connecting to node 127.0.0.1:7001: OK
    Connecting to node 127.0.0.1:7002: OK
    Connecting to node 127.0.0.1:7003: OK
    Connecting to node 127.0.0.1:7004: OK
    Connecting to node 127.0.0.1:7005: OK >>>
    Performing hash slots allocation on 6 nodes...
    Using 3 masters: 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002
    127.0.0.1:7000 replica #1 is 127.0.0.1:7003
    127.0.0.1:7001 replica #1 is 127.0.0.1:7004
    127.0.0.1:7002 replica #1 is 127.0.0.1:7005
    M: 9991306f0e50640a5684f1958fd754b38fa034c9 127.0.0.1:7000 slots:0-5460 (5461 slots) master
    M: e68e52cee0550f558b03b342f2f0354d2b8a083b 127.0.0.1:7001 slots:5461-10921 (5461 slots) master
    M: 393c6df5eb4b4cec323f0e4ca961c8b256e3460a 127.0.0.1:7002 slots:10922-16383 (5462 slots) master
    S: 48b728dbcedff6bf056231eb44990b7d1c35c3e0 127.0.0.1:7003
    S: 345ede084ac784a5c030a0387f8aaa9edfc59af3 127.0.0.1:7004
    S: 3375be2ccc321932e8853234ffa87ee9fde973ff 127.0.0.1:7005
    Can I set the above configuration? (type 'yes' to accept): yes
    
    Nodes configuration updated >>>
    Sending CLUSTER MEET messages to join the cluster Waiting for the cluster to join... >>>
    Performing Cluster Check (using node 127.0.0.1:7000)
    M: ebbb890e899244e4a2a6303826a29543ebf9885d 127.0.0.1:7000
       slots:0-5460 (5461 slots) master
    M: ebbb890e899244e4a2a6303826a29543ebf9885d 127.0.0.1:7001
       slots:5461-10922 (5462 slots) master
    M: 73c22198cd1d0782ec24e3c9b03378030891c9a3 127.0.0.1:7002
       slots:10923-16383 (5461 slots) master
    M: c785d85b95d7bdc28ec90384ab8a5885b289542c 127.0.0.1:7003
       slots: (0 slots) master
       replicates b949ea2d9c822ff069521a354b4ed48855ac6203
    M: 570c472fe553ba3c9d0fb3ba16fcdb8579b4fc86 127.0.0.1:7004
       slots: (0 slots) master
       replicates ebbb890e899244e4a2a6303826a29543ebf9885d
    M: f86667ec42cff41a5666162a912713173f5306d7 127.0.0.1:7005
       slots: (0 slots) master
       replicates 73c22198cd1d0782ec24e3c9b03378030891c9a3
    [OK] All nodes agree about slots configuration.
    >>> Check for open slots...
    >>> Check slots coverage...
    [OK] All 16384 slots covered.
    

    PS: 安装过程还发现RedHat系统上没有安装ruby,须要先安装ruby,并且公司机器还不能上网下载安装,仅仅能通过离线的方式安装ruby,这里有离线安装的文档能够參考一下:https://rvm.io/rvm/offline

    验证

    能够使用Redis3.0的redis-cliclient进行验证,须要加上-c參数,表示集群的意思。

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    
    $ redis-cli -c -p 7000
    redis 127.0.0.1:7000> set foo bar
    -> Redirected to slot [12182] located at 127.0.0.1:7002
    OK
    redis 127.0.0.1:7002> set hello world
    -> Redirected to slot [866] located at 127.0.0.1:7000
    OK
    redis 127.0.0.1:7000> get foo
    -> Redirected to slot [12182] located at 127.0.0.1:7002
    "bar"
    redis 127.0.0.1:7000> get hello
    -> Redirected to slot [866] located at 127.0.0.1:7000
    "world"
    

    很多其它的资料能够參考这里:http://redis.io/topics/cluster-tutorial

  • 相关阅读:
    剑指Offer-11.二进制中1的个数(C++/Java)
    剑指Offer-10.矩形覆盖(C++/Java)
    剑指Offer-9.变态跳台阶(C++/Java)
    UVA 1608 Non-boring sequence 不无聊的序列(分治,中途相遇)
    UVA1607 Gates 与非门电路 (二分)
    UVA 1451 Average平均值 (数形结合,斜率优化)
    UVA 1471 Defense Lines 防线 (LIS变形)
    UVA 1606 Amphiphilic Carbon Molecules 两亲性分子 (极角排序或叉积,扫描法)
    UVA 11134 FabledRooks 传说中的车 (问题分解)
    UVA 1152 4 Values Whose Sum is Zero 和为0的4个值 (中途相遇)
  • 原文地址:https://www.cnblogs.com/mengfanrong/p/4197233.html
Copyright © 2011-2022 走看看