redis 3.0 压缩包下载:
百度云 ---链接:http://pan.baidu.com/s/1i5quyzz 密码:7kka
当前解压redis,包含了dependency 目录;
dependency 目录 包含了所需要的ruby,redis.gem,rubygems;
1、ruby 源码安装;
[[email protected] ruby-2.2.2]# ./configure --prefix=/usr/local/ruby
[[email protected] ruby-2.2.2]# make &&make install
安装完成配置环境变量 /usr/local/ruby/bin
2、安装rubygems;
[[email protected] rubygems-2.4.7]# ruby setup.rb
3、gem指定源表;
[[email protected] rubygems-2.4.7]# gem install -l /home/redis3.0/dependency/redis-3.0.6.gem
注:把压缩包原本的ruby和rubtgems 删掉重新解压;否则编译会出现问题;
redis 安装
client 1:
1、当前解压redis包含三个基础配置节点
从上图可以看出,分别是7001、7002、7003
redis-common.conf为当前三个节点的公共配置文件(默认开启rdb,关闭aof)
2、进入7001下面,查看如下
编辑redis-7001.conf文件:
注:当前红色框中的配置路径如果有更改,需配置路径信息。
注: 删除 nodes-7001.conf 节点配置文件,该配置文件创建集群节点时会自动生产,不删除启动集群会报错;7002,7003 根据上述进行相同配置操作;
3、在redis目录下创建log文件夹
mkdir log
4、启动当前配置好的节点
src/redis-server conf/7001/redis-7001.conf > log/redis-7001.log 2>&1 &
src/redis-server conf/7002/redis-7002.conf > log/redis-7002.log 2>&1 &
src/redis-server conf/7003/redis-7003.conf > log/redis-7003.log 2>&1 &
client 2:
根据client 1 进行相同配置操作;其中节点建议将7001、7002、7003 改为 7004、7005、7006 ;其余不变;
启动当前配置好的节点
src/redis-server conf/7004/redis-7004.conf > log/redis-7004.log 2>&1 &
src/redis-server conf/7005/redis-7005.conf > log/redis-7005.log 2>&1 &
src/redis-server conf/7006/redis-7006.conf > log/redis-7006.log 2>&1 &
启动集群
[[email protected] redis3.0]#
[[email protected] redis3.0]# /home/cattsoft/redis3.0/src/redis-trib.rb create --replicas 1 172.51.46.10:7001 172.51.46.10:7002 172.51.46.10:7003 172.51.46.11:7004 172.51.46.11:7005 172.51.46.11:7006
>>> Creating cluster
Connecting to node 172.51.46.10:7001: OK
Connecting to node 172.51.46.10:7002: OK
Connecting to node 172.51.46.10:7003: OK
Connecting to node 172.51.46.11:7004: OK
Connecting to node 172.51.46.11:7005: OK
Connecting to node 172.51.46.11:7006: OK
>>> Performing hash slots allocation on 6 nodes...
Using 3 masters:
172.51.46.10:7001
172.51.46.11:7004
172.51.46.10:7002
Adding replica 172.51.46.11:7005 to 172.51.46.10:7001
Adding replica 172.51.46.10:7003 to 172.51.46.11:7004
Adding replica 172.51.46.11:7006 to 172.51.46.10:7002
M: f8ca2cfd45213e51fe00aa90e4f8bb2d661b56ae 172.51.46.10:7001
slots:0-5460 (5461 slots) master
M: 2556b9dacd53e7f7344a8964c1e59d44a4a45091 172.51.46.10:7002
slots:10923-16383 (5461 slots) master
S: 27fca5f41cfe0387e8b1f3133251f45ae0d01c73 172.51.46.10:7003
replicates 564ed966653081e9b1834b8bd56bd379b13ece4f
M: 564ed966653081e9b1834b8bd56bd379b13ece4f 172.51.46.11:7004
slots:5461-10922 (5462 slots) master
S: 54b3a75fd7dd3006c8600852ed1ee9029885f55d 172.51.46.11:7005
replicates f8ca2cfd45213e51fe00aa90e4f8bb2d661b56ae
S: 119232a9a68a4baa4d653207c18da249e8e9fa31 172.51.46.11:7006
replicates 2556b9dacd53e7f7344a8964c1e59d44a4a45091
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 172.51.46.10:7001)
M: f8ca2cfd45213e51fe00aa90e4f8bb2d661b56ae 172.51.46.10:7001
slots:0-5460 (5461 slots) master
M: 2556b9dacd53e7f7344a8964c1e59d44a4a45091 172.51.46.10:7002
slots:10923-16383 (5461 slots) master
M: 27fca5f41cfe0387e8b1f3133251f45ae0d01c73 172.51.46.10:7003
slots: (0 slots) master
replicates 564ed966653081e9b1834b8bd56bd379b13ece4f
M: 564ed966653081e9b1834b8bd56bd379b13ece4f 172.51.46.11:7004
slots:5461-10922 (5462 slots) master
M: 54b3a75fd7dd3006c8600852ed1ee9029885f55d 172.51.46.11:7005
slots: (0 slots) master
replicates f8ca2cfd45213e51fe00aa90e4f8bb2d661b56ae
M: 119232a9a68a4baa4d653207c18da249e8e9fa31 172.51.46.11:7006
slots: (0 slots) master
replicates 2556b9dacd53e7f7344a8964c1e59d44a4a45091
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
[[email protected] redis3.0]#
至此,集群启动成功;
查看集群状态:
[[email protected] redis3.0]# src/redis-trib.rb check 172.51.46.10:7001
Connecting to node 172.51.46.10:7001: OK
Connecting to node 172.51.46.11:7005: OK
Connecting to node 172.51.46.10:7002: OK
Connecting to node 172.51.46.10:7003: OK
Connecting to node 172.51.46.11:7004: OK
Connecting to node 172.51.46.11:7006: OK
>>> Performing Cluster Check (using node 172.51.46.10:7001)
M: f8ca2cfd45213e51fe00aa90e4f8bb2d661b56ae 172.51.46.10:7001
slots:0-5460 (5461 slots) master
1 additional replica(s)
S: 54b3a75fd7dd3006c8600852ed1ee9029885f55d 172.51.46.11:7005
slots: (0 slots) slave
replicates f8ca2cfd45213e51fe00aa90e4f8bb2d661b56ae
M: 2556b9dacd53e7f7344a8964c1e59d44a4a45091 172.51.46.10:7002
slots:10923-16383 (5461 slots) master
1 additional replica(s)
S: 27fca5f41cfe0387e8b1f3133251f45ae0d01c73 172.51.46.10:7003
slots: (0 slots) slave
replicates 564ed966653081e9b1834b8bd56bd379b13ece4f
M: 564ed966653081e9b1834b8bd56bd379b13ece4f 172.51.46.11:7004
slots:5461-10922 (5462 slots) master
1 additional replica(s)
S: 119232a9a68a4baa4d653207c18da249e8e9fa31 172.51.46.11:7006
slots: (0 slots) slave
replicates 2556b9dacd53e7f7344a8964c1e59d44a4a45091
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
测试:
[[email protected] redis3.0]# ./bin/redis-cli -c -p 7002
127.0.0.1:7002> set a1 999
-> Redirected to slot [7785] located at 172.51.46.11:7004
OK
172.51.46.11:7004>
[[email protected] redis3.0]# ./bin/redis-cli -c -p 7001
127.0.0.1:7001> get a1
-> Redirected to slot [7785] located at 172.51.46.11:7004
"999"
172.51.46.11:7004>
[[email protected] redis3.0]# ./bin/redis-cli -c -p 7003
127.0.0.1:7003> get a1
-> Redirected to slot [7785] located at 172.51.46.11:7004
"999"
172.51.46.11:7004>
[[email protected] redis3.0]#
redis 常见问题:
1、[ERR] Node 172.51.46.11:7001 is not empty. Either the nodealready knows other nodes (check with CLUSTER NODES) or contains some
解决办法:
1)将每个节点下aof、rdb、nodes.conf本地备份文件删除;
3)之后再执行脚本,成功执行;
2、/lib/redis/client.rb:85:in `call‘: ERR Slot 0 is already busy 巴拉巴拉的错误;
建议:修复集群
src/redis-trib.rb fix 127.0.0.1:7001
修复每个节点7001、7002、7003、7004、7005、7006 ;
注:其余问题,百度都比较容易找到解决办法,在此不再一一枚举说明;