https://cache.ruby-lang.org/pub/ruby/2.6/ruby-2.6.0.tar.gz
wget https://cache.ruby-china.com/pub/ruby/2.6/ruby-2.6.0.tar.gz
[root@redis01 ruby-2.6.0]# wget https://cache.ruby-china.com/pub/ruby/2.6/ruby-2.6.0.tar.gz
[root@redis01 ruby-2.6.0]# tar xf ruby-2.6.0.tar.gz
[root@redis01 ruby-2.6.0]# cd ruby-2.6.0
[root@redis01 ruby-2.6.0]# ./configure —prefix=/opt/ruby-2.6.0
make && make install
创建软连接
[root@redis01 ruby-2.6.0]# ln -s /opt/ruby-2.6.0 /opt/ruby[root@redis01 ruby-2.6.0]# ll /opttotal 0drwxr-xr-x. 6 root root 56 Jan 12 16:54 python3lrwxrwxrwx. 1 root root 7 Jan 14 17:37 redis -> redis-5drwxr-xr-x. 5 root root 114 Jan 18 00:07 redis-5lrwxrwxrwx. 1 root root 15 Jan 18 01:26 ruby -> /opt/ruby-2.6.0drwxr-xr-x. 6 root root 56 Jan 18 01:25 ruby-2.6.0
添加全局环境变量
[root@redis01 ruby-2.6.0]# echo 'PATH="/opt/ruby/bin:$PATH"'>>/etc/profile[root@redis01 ruby-2.6.0]# source /etc/profile[root@redis01 ruby-2.6.0]# gem -v3.0.1[root@redis01 ruby-2.6.0]# ruby -vruby 2.6.0p0 (2018-12-25 revision 66547) [x86_64-linux][root@redis01 ruby-2.6.0]#
[root@redis01 ruby-2.6.0]# vim /root/.gemrc
[sources]
https://mirrors.tuna.tsinghua.edu.cn/rubygems/
[root@redis01 ruby-2.6.0]# gem sources l
Failed to load /root/.gemrc because it doesn’t contain valid YAML hash
CURRENT SOURCES
https://rubygems.org/
[root@redis01 ruby-2.6.0]# gem install redis
Failed to load /root/.gemrc because it doesn’t contain valid YAML hash
Fetching redis-4.1.0.gem
Successfully installed redis-4.1.0
Parsing documentation for redis-4.1.0
Installing ri documentation for redis-4.1.0
Done installing documentation for redis after 0 seconds
1 gem installed
[root@redis01 ruby-2.6.0]#
[root@redis01 ~]# find / -name redis-trib.rb/root/tools/redis-5.0.3/src/redis-trib.rb
[root@redis01 data]# cd cluster-test/[root@redis01 cluster-test]# ls7000 7002 7004 redis-7000.conf redis-7002.conf redis-7004.conf7001 7003 7005 redis-7001.conf redis-7003.conf redis-7005.conf[root@redis01 cluster-test]# redis-server redis-7000.conf[root@redis01 cluster-test]# redis-server redis-7000.conf[root@redis01 cluster-test]# redis-server redis-7001.conf[root@redis01 cluster-test]# redis-server redis-7002.conf[root@redis01 cluster-test]# redis-server redis-7003.conf[root@redis01 cluster-test]# redis-server redis-7004.conf[root@redis01 cluster-test]# redis-server redis-7005.conf[root@redis01 cluster-test]# ps -ef |grep redisroot 84433 1 0 16:13 ? 00:00:00 redis-server *:7000 [cluster]root 84445 1 0 16:13 ? 00:00:00 redis-server *:7001 [cluster]root 84453 1 0 16:13 ? 00:00:00 redis-server *:7002 [cluster]root 84462 1 0 16:13 ? 00:00:00 redis-server *:7003 [cluster]root 84471 1 0 16:13 ? 00:00:00 redis-server *:7004 [cluster]root 84480 1 0 16:13 ? 00:00:00 redis-server *:7005 [cluster]root 84490 83509 0 16:13 pts/0 00:00:00 grep --color=auto redis[root@redis01 cluster-test]# /root/tools/redis-5.0.3/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:7005WARNING: redis-trib.rb is not longer available!You should use redis-cli instead.All commands and features belonging to redis-trib.rb have been movedto redis-cli.In order to use them you should call redis-cli with the --clusteroption followed by the subcommand name, arguments and options.Use the following syntax:redis-cli --cluster SUBCOMMAND [ARGUMENTS] [OPTIONS]Example:redis-cli --cluster create 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 --cluster-replicas 1To get help about all subcommands, type:redis-cli --cluster help
上述的无法使用,原因在于此:(官方说明) 简言之:版本不同导致的,redis 5 已经弃用了之前的方式
The first example, that is, the cluster creation, will be shown using both
redis-cliin Redis 5 andredis-tribin Redis 3 and 4. However all the next examples will only useredis-cli, since as you can see the syntax is very similar, and you can trivially change one command line into the other by usingredis-trib.rb helpto get info about the old syntax. Important: note that you can use Redis 5redis-cliagainst Redis 4 clusters without issues if you wish. To create your cluster for Redis 5 withredis-clisimply type:
redis-cli --cluster create 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 \--cluster-replicas 1Using
redis-trib.rbfor Redis 4 or 3 type:
./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
[root@redis01 cluster-test]# redis-cli --cluster create 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 --cluster-replicas 1>>> Performing hash slots allocation on 6 nodes...Master[0] -> Slots 0 - 5460Master[1] -> Slots 5461 - 10922Master[2] -> Slots 10923 - 16383Adding replica 127.0.0.1:7003 to 127.0.0.1:7000Adding replica 127.0.0.1:7004 to 127.0.0.1:7001Adding replica 127.0.0.1:7005 to 127.0.0.1:7002>>> Trying to optimize slaves allocation for anti-affinity[WARNING] Some slaves are in the same host as their masterM: ebe673291e667448261fa0fa69aaf456ca401810 127.0.0.1:7000slots:[0-5460] (5461 slots) masterM: 2fbbf2910cbadc908df41fa21a270794046ed0d0 127.0.0.1:7001slots:[5461-10922] (5462 slots) masterM: b02df74489dc025eab598ec124fe51e62ff47041 127.0.0.1:7002slots:[10923-16383] (5461 slots) masterS: db36f1d1c12a8dd5f973146af184d926c90ac164 127.0.0.1:7003replicates 2fbbf2910cbadc908df41fa21a270794046ed0d0S: 6545a7673f0d947440ae644d0e760e4578ec77c3 127.0.0.1:7004replicates b02df74489dc025eab598ec124fe51e62ff47041S: 1881b58b72eab8dc1d335c8c2158ed9097b5094b 127.0.0.1:7005replicates ebe673291e667448261fa0fa69aaf456ca401810Can I set the above configuration? (type 'yes' to accept):
该选项--cluster-replicas 1意味着我们希望每个创建的主库都有一个从库
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:7000)
M: ebe673291e667448261fa0fa69aaf456ca401810 127.0.0.1:7000
slots:[0-5460] (5461 slots) master
1 additional replica(s)
S: 6545a7673f0d947440ae644d0e760e4578ec77c3 127.0.0.1:7004
slots: (0 slots) slave
replicates b02df74489dc025eab598ec124fe51e62ff47041
M: b02df74489dc025eab598ec124fe51e62ff47041 127.0.0.1:7002
slots:[10923-16383] (5461 slots) master
1 additional replica(s)
M: 2fbbf2910cbadc908df41fa21a270794046ed0d0 127.0.0.1:7001
slots:[5461-10922] (5462 slots) master
1 additional replica(s)
S: 1881b58b72eab8dc1d335c8c2158ed9097b5094b 127.0.0.1:7005
slots: (0 slots) slave
replicates ebe673291e667448261fa0fa69aaf456ca401810
S: db36f1d1c12a8dd5f973146af184d926c90ac164 127.0.0.1:7003
slots: (0 slots) slave
replicates 2fbbf2910cbadc908df41fa21a270794046ed0d0
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
测试集群存储
[root@redis01 cluster-test]# redis-cli -p 7000 -c
127.0.0.1:7000>
127.0.0.1:7000>
127.0.0.1:7000>
127.0.0.1:7000>
127.0.0.1:7000> keys *
(empty list or set)
127.0.0.1:7000> set addr 123
-> Redirected to slot [12790] located at 127.0.0.1:7002
OK
127.0.0.1:7002>
以下节点解释
127.0.0.1:7000> set addr 123 -> Redirected to slot [12790] located at 127.0.0.1:7002 OK 127.0.0.1:7002>
7000 节点存放数据 仔细看数据已经存放在了 7002 节点 并且已经自动切换到了 7002 节点
redis-cluster 会默认将不同的key,进行CRC16算法,进行分配到不同槽位中
127.0.0.1:7004> set add fas
-> Redirected to slot [1943] located at 127.0.0.1:7000
OK
127.0.0.1:7000>
重新分配虚拟槽
检查节点的集群状态
[root@redis01 cluster-test]# redis-cli --cluster check 127.0.0.1:7000
127.0.0.1:7000 (ebe67329...) -> 2 keys | 5461 slots | 1 slaves.
127.0.0.1:7002 (b02df744...) -> 1 keys | 5461 slots | 1 slaves.
127.0.0.1:7001 (2fbbf291...) -> 0 keys | 5462 slots | 1 slaves.
[OK] 3 keys in 3 masters.
0.00 keys per slot on average.
>>> Performing Cluster Check (using node 127.0.0.1:7000)
M: ebe673291e667448261fa0fa69aaf456ca401810 127.0.0.1:7000
slots:[0-5460] (5461 slots) master
1 additional replica(s)
S: 6545a7673f0d947440ae644d0e760e4578ec77c3 127.0.0.1:7004
slots: (0 slots) slave
replicates b02df74489dc025eab598ec124fe51e62ff47041
M: b02df74489dc025eab598ec124fe51e62ff47041 127.0.0.1:7002
slots:[10923-16383] (5461 slots) master
1 additional replica(s)
M: 2fbbf2910cbadc908df41fa21a270794046ed0d0 127.0.0.1:7001
slots:[5461-10922] (5462 slots) master
1 additional replica(s)
S: 1881b58b72eab8dc1d335c8c2158ed9097b5094b 127.0.0.1:7005
slots: (0 slots) slave
replicates ebe673291e667448261fa0fa69aaf456ca401810
S: db36f1d1c12a8dd5f973146af184d926c90ac164 127.0.0.1:7003
slots: (0 slots) slave
replicates 2fbbf2910cbadc908df41fa21a270794046ed0d0
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
