Redis学习3之单节点上redis集群搭建和使用

13 篇文章 0 订阅

单节点上redis集群搭建和使用:
环境:ubuntu14.04
redis-3.0.3

步骤
1.下载解压编译等请见:http://blog.csdn.net/xubo245/article/details/48318735
很简单,只是make需要点时间。

2.进入redis安装目录,我的安装在~/cloud下,建立多个文件夹

cd ~/cloud/redis-3.0.3
mkdir cluster
cp redis.conf cluster   //复制配置文件到cluster下
cp src/redis-server cluster //复制redis-server脚本到cluster下
cd cluster
mkdir 7000 7001 7002 7003 7004 7005

这里写图片描述

3.修改配置文件,redis.conf

vi redis.conf

文件需要修改几个地方:

port 7000  //非7000文件夹需要修改为对应文件夹端口,7001-7005
daemonize yes
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 5000
appendonly yes
logfile ./redis.log
 syslog-enabled yes

!!!非7000文件夹需要修改为对应文件夹端口,7001-7005,可以下面cp步骤后修改。
这里写图片描述
logfile为log文件

将redis.conf复制到7000-7005六个文件夹中:

cp redis.conf 7000
cp redis.conf 7001
cp redis.conf 7002
cp redis.conf 7003
cp redis.conf 7004
cp redis.conf 7005

4.运行redis-server
再在六个文件夹分别运行:

cd ../7000
 ../redis-server ./redis.conf 
 cd ../7001
 ../redis-server ./redis.conf 
 cd ../7002
 ../redis-server ./redis.conf 
 cd ../7003
 ../redis-server ./redis.conf 
 cd ../7004
 ../redis-server ./redis.conf 
 cd ../7005
 ../redis-server ./redis.conf 

这时可以进入日志查看:

cd ../7000
vi redis.log

log内容:

10689:M 10 Sep 19:47:15.794 # You requested maxclients of 10000 requiring at least 10032 max file descriptors.
10689:M 10 Sep 19:47:15.795 # Redis can't set maximum open files to 10032 because of OS error: Operation not permitted.
10689:M 10 Sep 19:47:15.795 # Current maximum open files is 4096. maxclients has been reduced to 4064 to compensate for low ulimit. If you need higher maxclients increase 'ulimit -n'.
10689:M 10 Sep 19:47:15.795 * Node configuration loaded, I'm 87ef8abfdfe8a3d1a74873d02a6f1ebd0eb9e115
10689:M 10 Sep 19:47:15.796 * Redis 3.0.3 (00000000/0) 64 bit, cluster mode, port 7000, pid 10689 ready to start.
10689:M 10 Sep 19:47:15.796 # Server started, Redis version 3.0.3
10689:M 10 Sep 19:47:15.797 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
10689:M 10 Sep 19:47:15.797 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
10689:M 10 Sep 19:47:15.797 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
10689:M 10 Sep 19:47:15.797 * The server is now ready to accept connections on port 7000

其中:10689:M 10 Sep 19:47:15.795 * Node configuration loaded, I’m 87ef8abfdfe8a3d1a74873d02a6f1ebd0eb9e115
因为nodes.conf不存在,所以每个节点被分配到一个新的ID

同样,可以查看进程ps -aux | grep redis:

xubo@xubo:~$ ps -aux | grep redis
xubo     10309  0.0  0.2  42308  8892 ?        Ssl  19:08   0:01 ../redis-server *:7004 [cluster]
xubo     10316  0.0  0.2  42308  8884 ?        Ssl  19:09   0:01 ../redis-server *:7002 [cluster]
xubo     10330  0.0  0.2  42308  8776 ?        Ssl  19:09   0:01 ../redis-server *:7005 [cluster]
xubo     10364  0.0  0.2  42308  8800 ?        Ssl  19:10   0:01 ../redis-server *:7001 [cluster]
xubo     10372  0.0  0.2  42308  8812 ?        Ssl  19:11   0:01 ../redis-server *:7003 [cluster]
xubo     10689  0.0  0.2  42304  8168 ?        Ssl  19:47   0:00 ../redis-server *:7000 [cluster]
xubo     10709  0.0  0.2  54000  7952 pts/36   S+   19:47   0:00 vi redis.log
xubo     10862  0.0  0.0  15944  2232 pts/31   S+   20:31   0:00 grep --color=auto redis

显示集群中有7000-7005都在运行。

5.安装:

cd redis-3.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:7005

第一次会显示报错:

xubo@xubo:~/cloud/redis-3.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:7005
/usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- redis (LoadError)
    from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from ./redis-trib.rb:25:in `<main>'

需要安装ruby和rubygems

sudo yum install ruby
sudo yum install  rubygems-integration 

报错:

xubo@xubo:~/cloud/redis-3.0.3/src$ sudo apt-get install rubygems-integration 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  account-plugin-windows-live kde-l10n-engb kde-l10n-zhcn libupstart1
Use 'apt-get autoremove' to remove them.
Suggested packages:
  bundler
The following NEW packages will be installed:
  rubygems-integration
0 upgraded, 1 newly installed, 0 to remove and 1 not upgraded.
Need to get 5,340 B of archives.
After this operation, 66.6 kB of additional disk space will be used.
Get:1 http://cn.archive.ubuntu.com/ubuntu/ trusty/main rubygems-integration all 1.5 [5,340 B]
Fetched 5,340 B in 0s (42.1 kB/s)                 
Selecting previously unselected package rubygems-integration.
(Reading database ... 289437 files and directories currently installed.)
Preparing to unpack .../rubygems-integration_1.5_all.deb ...
Unpacking rubygems-integration (1.5) ...
Setting up rubygems-integration (1.5) ...

需要安装包: account-plugin-windows-live kde-l10n-engb kde-l10n-zhcn libupstart1
于是就:

sudo apt-get install account-plugin-windows-live kde-l10n-engb kde-l10n-zhcn lib

ruby和rubygems这时能顺利yum安装。
运行redis还会继续报错:

xubo@xubo:~/cloud/redis-3.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:7005
/usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- redis (LoadError)
    from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from ./redis-trib.rb:25:in `<main>'

还会报错,提示不能加载redis,是因为缺少redis和ruby的接口,使用gem 安装:

gem install redis

gem之后能顺利安装和运行

6.安装成功:

xubo@xubo:~/cloud/redis-3.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:7005
>>> 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
Adding replica 127.0.0.1:7003 to 127.0.0.1:7000
Adding replica 127.0.0.1:7004 to 127.0.0.1:7001
Adding replica 127.0.0.1:7005 to 127.0.0.1:7002
M: 87ef8abfdfe8a3d1a74873d02a6f1ebd0eb9e115 127.0.0.1:7000
   slots:0-5460 (5461 slots) master
M: 07dbe7d13669451a8bdf31ea7d8d30e654a84954 127.0.0.1:7001
   slots:5461-10922 (5462 slots) master
M: 7f5ad4dc90ba1f2c8557ce5522436fc1cf4c6084 127.0.0.1:7002
   slots:10923-16383 (5461 slots) master
S: b5ee3eedebf7319ac07f2497828390f5fa075c39 127.0.0.1:7003
   replicates 87ef8abfdfe8a3d1a74873d02a6f1ebd0eb9e115
S: 039c98b646b95f0d912a0b5b80b9aba764fd453a 127.0.0.1:7004
   replicates 07dbe7d13669451a8bdf31ea7d8d30e654a84954
S: 300125efa46f10c64e9db9835691889cde49bd61 127.0.0.1:7005
   replicates 7f5ad4dc90ba1f2c8557ce5522436fc1cf4c6084
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: 87ef8abfdfe8a3d1a74873d02a6f1ebd0eb9e115 127.0.0.1:7000
   slots:0-5460 (5461 slots) master
M: 07dbe7d13669451a8bdf31ea7d8d30e654a84954 127.0.0.1:7001
   slots:5461-10922 (5462 slots) master
M: 7f5ad4dc90ba1f2c8557ce5522436fc1cf4c6084 127.0.0.1:7002
   slots:10923-16383 (5461 slots) master
M: b5ee3eedebf7319ac07f2497828390f5fa075c39 127.0.0.1:7003
   slots: (0 slots) master
   replicates 87ef8abfdfe8a3d1a74873d02a6f1ebd0eb9e115
M: 039c98b646b95f0d912a0b5b80b9aba764fd453a 127.0.0.1:7004
   slots: (0 slots) master
   replicates 07dbe7d13669451a8bdf31ea7d8d30e654a84954
M: 300125efa46f10c64e9db9835691889cde49bd61 127.0.0.1:7005
   slots: (0 slots) master
   replicates 7f5ad4dc90ba1f2c8557ce5522436fc1cf4c6084
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

7.运行测试:
使用redis-cli命令进入集群环境

redis-cli -c -p 7000

使用redis-benchmark测试:

xubo@xubo:~$ redis-benchmark -p 7000
====== PING_INLINE ======
  100000 requests completed in 0.84 seconds
  50 parallel clients
  3 bytes payload
  keep alive: 1

99.84% <= 1 milliseconds
99.89% <= 2 milliseconds
99.90% <= 4 milliseconds
99.99% <= 5 milliseconds
100.00% <= 5 milliseconds
118906.06 requests per second

====== PING_BULK ======
  100000 requests completed in 0.84 seconds
  50 parallel clients
  3 bytes payload
  keep alive: 1

99.83% <= 1 milliseconds
99.95% <= 3 milliseconds
100.00% <= 3 milliseconds
119617.22 requests per second

====== SET ======
  100000 requests completed in 0.81 seconds
  50 parallel clients
  3 bytes payload
  keep alive: 1

99.95% <= 2 milliseconds
100.00% <= 2 milliseconds
123001.23 requests per second

====== GET ======
  100000 requests completed in 0.82 seconds
  50 parallel clients
  3 bytes payload
  keep alive: 1

99.92% <= 1 milliseconds
100.00% <= 1 milliseconds
122100.12 requests per second

====== INCR ======
  100000 requests completed in 0.81 seconds
  50 parallel clients
  3 bytes payload
  keep alive: 1

99.96% <= 1 milliseconds
100.00% <= 1 milliseconds
123001.23 requests per second

====== LPUSH ======
  100000 requests completed in 1.60 seconds
  50 parallel clients
  3 bytes payload
  keep alive: 1

99.07% <= 1 milliseconds
99.75% <= 2 milliseconds
99.92% <= 3 milliseconds
99.92% <= 4 milliseconds
100.00% <= 4 milliseconds
62695.92 requests per second

====== LPOP ======
  100000 requests completed in 1.67 seconds
  50 parallel clients
  3 bytes payload
  keep alive: 1

99.87% <= 1 milliseconds
99.87% <= 2 milliseconds
99.87% <= 3 milliseconds
99.99% <= 4 milliseconds
100.00% <= 4 milliseconds
60024.01 requests per second

====== SADD ======
  100000 requests completed in 0.82 seconds
  50 parallel clients
  3 bytes payload
  keep alive: 1

99.96% <= 1 milliseconds
100.00% <= 1 milliseconds
122249.38 requests per second

====== SPOP ======
  100000 requests completed in 0.83 seconds
  50 parallel clients
  3 bytes payload
  keep alive: 1

99.95% <= 1 milliseconds
100.00% <= 1 milliseconds
121065.38 requests per second

====== LPUSH (needed to benchmark LRANGE) ======
  100000 requests completed in 1.64 seconds
  50 parallel clients
  3 bytes payload
  keep alive: 1

99.71% <= 1 milliseconds
99.90% <= 3 milliseconds
99.90% <= 4 milliseconds
99.95% <= 5 milliseconds
100.00% <= 5 milliseconds
61012.81 requests per second

====== LRANGE_100 (first 100 elements) ======
  100000 requests completed in 2.00 seconds
  50 parallel clients
  3 bytes payload
  keep alive: 1

99.79% <= 1 milliseconds
99.90% <= 2 milliseconds
99.92% <= 3 milliseconds
99.96% <= 4 milliseconds
100.00% <= 4 milliseconds
49900.20 requests per second

====== LRANGE_300 (first 300 elements) ======
  100000 requests completed in 5.09 seconds
  50 parallel clients
  3 bytes payload
  keep alive: 1

2.17% <= 1 milliseconds
99.63% <= 2 milliseconds
99.80% <= 3 milliseconds
99.88% <= 4 milliseconds
99.95% <= 5 milliseconds
100.00% <= 6 milliseconds
100.00% <= 6 milliseconds
19638.65 requests per second

====== LRANGE_500 (first 450 elements) ======
  100000 requests completed in 7.31 seconds
  50 parallel clients
  3 bytes payload
  keep alive: 1

0.04% <= 1 milliseconds
83.89% <= 2 milliseconds
99.73% <= 3 milliseconds
99.87% <= 4 milliseconds
99.97% <= 5 milliseconds
100.00% <= 6 milliseconds
100.00% <= 6 milliseconds
13687.38 requests per second

====== LRANGE_600 (first 600 elements) ======
  100000 requests completed in 9.45 seconds
  50 parallel clients
  3 bytes payload
  keep alive: 1

0.04% <= 1 milliseconds
7.72% <= 2 milliseconds
98.71% <= 3 milliseconds
99.59% <= 4 milliseconds
99.80% <= 5 milliseconds
99.90% <= 6 milliseconds
99.95% <= 7 milliseconds
99.99% <= 8 milliseconds
100.00% <= 9 milliseconds
100.00% <= 9 milliseconds
10586.49 requests per second

====== MSET (10 keys) ======
  100000 requests completed in 1.05 seconds
  50 parallel clients
  3 bytes payload
  keep alive: 1

99.84% <= 1 milliseconds
99.90% <= 3 milliseconds
100.00% <= 4 milliseconds
100.00% <= 4 milliseconds
95510.98 requests per second

Creating a Redis Cluster using the create-cluster script
使用create-cluster 脚本创建redis cluster

create-cluster start
create-cluster create
create-cluster stop

需要到redis-3.0.3/utils/create-cluster目录下运行脚本:

cd redis-3.0.3/utils/create-cluster
xubo@xubo:~/cloud/redis-3.0.3/utils/create-cluster$ ./create-cluster start
Starting 30001
Starting 30002
Starting 30003
Starting 30004
Starting 30005
Starting 30006
xubo@xubo:~/cloud/redis-3.0.3/utils/create-cluster$ 
xubo@xubo:~/cloud/redis-3.0.3/utils/create-cluster$ 
xubo@xubo:~/cloud/redis-3.0.3/utils/create-cluster$ ./create-cluster create
>>> Creating cluster
Connecting to node 127.0.0.1:30001: OK
Connecting to node 127.0.0.1:30002: OK
Connecting to node 127.0.0.1:30003: OK
Connecting to node 127.0.0.1:30004: OK
Connecting to node 127.0.0.1:30005: OK
Connecting to node 127.0.0.1:30006: OK
>>> Performing hash slots allocation on 6 nodes...
Using 3 masters:
127.0.0.1:30001
127.0.0.1:30002
127.0.0.1:30003
Adding replica 127.0.0.1:30004 to 127.0.0.1:30001
Adding replica 127.0.0.1:30005 to 127.0.0.1:30002
Adding replica 127.0.0.1:30006 to 127.0.0.1:30003
M: c46e85a095180e445bfd7e3ab28869f04ab83a07 127.0.0.1:30001
   slots:0-5460 (5461 slots) master
M: fed25a3be11d72a361a5614841854eaebd80f204 127.0.0.1:30002
   slots:5461-10922 (5462 slots) master
M: 39a60c2ede3f4ce0f436b79b4d9f8aebf028c1ba 127.0.0.1:30003
   slots:10923-16383 (5461 slots) master
S: b8c3863f0edcac82553740bb14afab5e952dcc28 127.0.0.1:30004
   replicates c46e85a095180e445bfd7e3ab28869f04ab83a07
S: 9dfe48bc9b49ef8333e9581b0b664e9bc4254d8c 127.0.0.1:30005
   replicates fed25a3be11d72a361a5614841854eaebd80f204
S: edb8d74389289a9d6afc28d65eb63f8463c201bf 127.0.0.1:30006
   replicates 39a60c2ede3f4ce0f436b79b4d9f8aebf028c1ba
Can I set the above configuration? (type 'yes' to accept): create-cluster stop.^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H
*** Aborting...
xubo@xubo:~/cloud/redis-3.0.3/utils/create-cluster$ ./create-cluster create
>>> Creating cluster
Connecting to node 127.0.0.1:30001: OK
Connecting to node 127.0.0.1:30002: OK
Connecting to node 127.0.0.1:30003: OK
Connecting to node 127.0.0.1:30004: OK
Connecting to node 127.0.0.1:30005: OK
Connecting to node 127.0.0.1:30006: OK
>>> Performing hash slots allocation on 6 nodes...
Using 3 masters:
127.0.0.1:30001
127.0.0.1:30002
127.0.0.1:30003
Adding replica 127.0.0.1:30004 to 127.0.0.1:30001
Adding replica 127.0.0.1:30005 to 127.0.0.1:30002
Adding replica 127.0.0.1:30006 to 127.0.0.1:30003
M: c46e85a095180e445bfd7e3ab28869f04ab83a07 127.0.0.1:30001
   slots:0-5460 (5461 slots) master
M: fed25a3be11d72a361a5614841854eaebd80f204 127.0.0.1:30002
   slots:5461-10922 (5462 slots) master
M: 39a60c2ede3f4ce0f436b79b4d9f8aebf028c1ba 127.0.0.1:30003
   slots:10923-16383 (5461 slots) master
S: b8c3863f0edcac82553740bb14afab5e952dcc28 127.0.0.1:30004
   replicates c46e85a095180e445bfd7e3ab28869f04ab83a07
S: 9dfe48bc9b49ef8333e9581b0b664e9bc4254d8c 127.0.0.1:30005
   replicates fed25a3be11d72a361a5614841854eaebd80f204
S: edb8d74389289a9d6afc28d65eb63f8463c201bf 127.0.0.1:30006
   replicates 39a60c2ede3f4ce0f436b79b4d9f8aebf028c1ba
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:30001)
M: c46e85a095180e445bfd7e3ab28869f04ab83a07 127.0.0.1:30001
   slots:0-5460 (5461 slots) master
M: fed25a3be11d72a361a5614841854eaebd80f204 127.0.0.1:30002
   slots:5461-10922 (5462 slots) master
M: 39a60c2ede3f4ce0f436b79b4d9f8aebf028c1ba 127.0.0.1:30003
   slots:10923-16383 (5461 slots) master
M: b8c3863f0edcac82553740bb14afab5e952dcc28 127.0.0.1:30004
   slots: (0 slots) master
   replicates c46e85a095180e445bfd7e3ab28869f04ab83a07
M: 9dfe48bc9b49ef8333e9581b0b664e9bc4254d8c 127.0.0.1:30005
   slots: (0 slots) master
   replicates fed25a3be11d72a361a5614841854eaebd80f204
M: edb8d74389289a9d6afc28d65eb63f8463c201bf 127.0.0.1:30006
   slots: (0 slots) master
   replicates 39a60c2ede3f4ce0f436b79b4d9f8aebf028c1ba
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
xubo@xubo:~/cloud/redis-3.0.3/utils/create-cluster$ create-cluster stop
create-cluster: command not found
xubo@xubo:~/cloud/redis-3.0.3/utils/create-cluster$ ./create-cluster stop
Stopping 30001
Stopping 30002
Stopping 30003
Stopping 30004
Stopping 30005
Stopping 30006

可以看到create后:

xubo@xubo:~/cloud/redis-3.0.3/utils/create-cluster$ ps -aux |grep redis
xubo     10309  0.0  0.2  42308  8896 ?        Ssl  19:08   0:03 ../redis-server *:7004 [cluster]
xubo     10316  0.0  0.2  42308 11000 ?        Ssl  19:09   0:03 ../redis-server *:7002 [cluster]
xubo     10330  0.0  0.2  42308  8848 ?        Ssl  19:09   0:03 ../redis-server *:7005 [cluster]
xubo     10364  0.0  0.2  42308 10976 ?        Ssl  19:10   0:03 ../redis-server *:7001 [cluster]
xubo     10372  0.0  0.5  54596 23320 ?        Ssl  19:11   0:08 ../redis-server *:7003 [cluster]
xubo     10689  0.6  0.5  58688 22356 ?        Ssl  19:47   0:48 ../redis-server *:7000 [cluster]
xubo     10709  0.0  0.2  54000  7952 pts/36   S+   19:47   0:00 vi redis.log
xubo     12550  0.0  0.2  42304  9116 ?        Ssl  21:44   0:00 ../../src/redis-server *:30001 [cluster]                              
xubo     12554  0.0  0.2  42304  9112 ?        Ssl  21:44   0:00 ../../src/redis-server *:30002 [cluster]                               
xubo     12558  0.0  0.2  42304  9124 ?        Ssl  21:44   0:00 ../../src/redis-server *:30003 [cluster]                            
xubo     12562  0.0  0.2  42304  8992 ?        Ssl  21:44   0:00 ../../src/redis-server *:30004 [cluster]                                
xubo     12566  0.0  0.2  42304  9116 ?        Ssl  21:44   0:00 ../../src/redis-server *:30005 [cluster]                                    
xubo     12570  0.0  0.2  42304  8992 ?        Ssl  21:44   0:00 ../../src/redis-server *:30006 [cluster]       
xubo     12596  0.0  0.0  15944  2284 pts/38   S+   21:56   0:00 grep --color=auto redis

遇到的问题:
create-cluster stop之后,在运行create-cluster start没有报错,但运行create-cluster create报错:

xubo@xubo:~/cloud/redis-3.0.3/utils/create-cluster$ ./create-cluster create
>>> Creating cluster
Connecting to node 127.0.0.1:30001: OK
[ERR] Node 127.0.0.1:30001 is not empty. Either the node already knows other nodes (check with CLUSTER NODES) or contains some key in database 0.

显示节点Node 127.0.0.1:30001 已经非空

运行:

xubo@xubo:~/cloud/redis-3.0.3/utils/create-cluster$ redis-cli -c -p 7000
127.0.0.1:7000> keys *
1) "hello"
2) "mylist"
127.0.0.1:7000> set xubo ustc
OK
127.0.0.1:7000> keys *
1) "xubo"
2) "hello"
3) "mylist"
127.0.0.1:7000> set xubo1213 ustc
-> Redirected to slot [14945] located at 127.0.0.1:7002
OK
127.0.0.1:7002> set xubo245 ustc
-> Redirected to slot [1360] located at 127.0.0.1:7000
OK
127.0.0.1:7000> set xubo901 ustc
-> Redirected to slot [14817] located at 127.0.0.1:7002
OK
127.0.0.1:7002> set xubo1011 ustc
OK
127.0.0.1:7002> set xubo10111 ustc
-> Redirected to slot [7009] located at 127.0.0.1:7001
OK
127.0.0.1:7001> get xubo1011
-> Redirected to slot [13379] located at 127.0.0.1:7002
"ustc"

显示slot号和located的位置。
在对应的端口节点确实能看到:

xubo@xubo:~$ redis-cli -c -p 7002
127.0.0.1:7002> keys *
1) "xubo1213"
127.0.0.1:7002> keys *
1) "xubo1213"
127.0.0.1:7002> keys *
1) "xubo901"
2) "xubo1213"
127.0.0.1:7002> keys *
1) "xubo1011"
2) "xubo901"
3) "xubo1213"
127.0.0.1:7002> 

而且端口号会自动跳转:

xubo@xubo:~$ redis-cli -c -p 7001
127.0.0.1:7001> keys *
1) "xubo10111"
127.0.0.1:7001> get xubo245
-> Redirected to slot [1360] located at 127.0.0.1:7000
"ustc"
127.0.0.1:7000> keys *
1) "xubo"
2) "xubo245"
3) "hello"
4) "mylist"
127.0.0.1:7000> get xubo10111
-> Redirected to slot [7009] located at 127.0.0.1:7001
"ustc"
127.0.0.1:7001> keys *
1) "xubo10111"
127.0.0.1:7001> 

参考资料:
【1】 http://redis.io/topics/cluster-tutorial
【2】 http://redis.io/topics/cluster-spec
【3】 http://blog.csdn.net/xu470438000/article/details/42971091

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值