品牌自适应网站建设,网站建设公司专业网站科技开发,东莞网站关键词排名,wordpress 小影简单说下自己测试搭建简单的redis集群的大体步骤#xff1a; 1.首先你的有6个redis#xff08;官方说最少6个#xff0c;3master#xff0c;3slave#xff09;#xff0c;可以先在一台机器上搭建#xff0c;搭建到多台上应该只需要改变启动命令即可#xff08;可能需要… 简单说下自己测试搭建简单的redis集群的大体步骤 1.首先你的有6个redis官方说最少6个3master3slave可以先在一台机器上搭建搭建到多台上应该只需要改变启动命令即可可能需要一些ssh无密钥什么的只是猜测 在网上随便可以找到的配置多个redis总体有两种方式一种是虚拟的貌似走的都是一个redis一种是将配置好的redis复制成六份配置相应的端口等我选择的后者显得更真实一些 然后把他们全部打开可以写一个脚本或者一个一个打开作为一个新世纪的年轻人我当然选择一个一个打开它们...... [rootlocalhost ~]# ps -ef | grep redis
root 3427 1 0 7月17 ? 00:02:59 src/redis-server *:6379
root 3454 1 0 7月17 ? 00:06:09 src/redis-server *:7001 [cluster]
root 3460 1 0 7月17 ? 00:06:19 src/redis-server *:7002 [cluster]
root 3467 1 0 7月17 ? 00:05:59 src/redis-server *:7003 [cluster]
root 3473 1 0 7月17 ? 00:05:59 src/redis-server *:7004 [cluster]
root 3477 1 0 7月17 ? 00:05:57 src/redis-server *:7005 [cluster]
root 5867 1 0 12:02 ? 00:00:06 src/redis-server *:7000 [cluster]
root 5938 5913 0 13:17 pts/1 00:00:00 grep --colorauto redis 2.将6个独立redis设置为集群so easy 一句话搞定。其中 --replicas 参数是将6台redis分别分配了主从关系master挂掉slave可以顶替但是还没有具体深入研究 ./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 在开启过程中可能会遇到很多问题各种奇怪的报错那就要安装ruby和gem的一些东东搞不明白是什么反正就是依赖吧~ 只能说按照这个来会绕开很多坑。 # yum install ruby-devel.x86_64# wget http://rubygems.global.ssl.fastly.net/gems/redis-3.2.1.gem
# gem install -l ./redis-3.2.1.gem 执行这些代码之后再去执行上面建立集群的命令如果成功的话会看到下面的样子 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: ad52e4f7c14da4b8b1e8e48603c9e5515a4cec7a 127.0.0.1:7000 slots:0-5460 (5461 slots) master
M: d3058a19483d7be5c30c042779e56130f6ebf074 127.0.0.1:7001 slots:5461-10922 (5462 slots) master
M: 5814305e71552ab45c44b9b8233681a63c3a57b1 127.0.0.1:7002 slots:10923-16383 (5461 slots) master
S: e50676757acbe7c6a21e8abf4eda26ababb08285 127.0.0.1:7003 replicates ad52e4f7c14da4b8b1e8e48603c9e5515a4cec7a
S: ab307ba26d6dabe8edb2f2a7287be6f01aa46d88 127.0.0.1:7004 replicates d3058a19483d7be5c30c042779e56130f6ebf074
S: 11174332eb6ad40c0327750536fa776d706caf85 127.0.0.1:7005 replicates 5814305e71552ab45c44b9b8233681a63c3a57b1
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: ad52e4f7c14da4b8b1e8e48603c9e5515a4cec7a 127.0.0.1:7000 slots:0-5460 (5461 slots) master
M: d3058a19483d7be5c30c042779e56130f6ebf074 127.0.0.1:7001 slots:5461-10922 (5462 slots) master
M: 5814305e71552ab45c44b9b8233681a63c3a57b1 127.0.0.1:7002 slots:10923-16383 (5461 slots) master
M: e50676757acbe7c6a21e8abf4eda26ababb08285 127.0.0.1:7003 slots: (0 slots) master replicates ad52e4f7c14da4b8b1e8e48603c9e5515a4cec7a
M: ab307ba26d6dabe8edb2f2a7287be6f01aa46d88 127.0.0.1:7004 slots: (0 slots) master replicates d3058a19483d7be5c30c042779e56130f6ebf074
M: 11174332eb6ad40c0327750536fa776d706caf85 127.0.0.1:7005 slots: (0 slots) master replicates 5814305e71552ab45c44b9b8233681a63c3a57b1
span stylecolor:#009900;[OK] All nodes agree about slots configuration./span Check for open slots... Check slots coverage...
span stylecolor:#009900;[OK] All 16384 slots covered./span/span 3.测试集群。 可以用下面的命令查看集群的状态从下面可以看出有4个master2个slave~~~这个是由于我太年轻kill了7000的redis又加入了进来原先他的slave 7003 也变成了master顶替了他。 [rootlocalhost src]# ./redis-trib.rb check 127.0.0.1:7000
Connecting to node 127.0.0.1:7000: OK
Connecting to node 127.0.0.1:7005: OK
Connecting to node 127.0.0.1:7003: OK
Connecting to node 127.0.0.1:7002: OK
Connecting to node 127.0.0.1:7001: OK
Connecting to node 127.0.0.1:7004: OKPerforming Cluster Check (using node 127.0.0.1:7000)
M: 4eb95ab689288dbb3ebf7ed380a0593ec9daa878 127.0.0.1:7000slots: (0 slots) master0 additional replica(s)
S: 11174332eb6ad40c0327750536fa776d706caf85 127.0.0.1:7005slots: (0 slots) slavereplicates 5814305e71552ab45c44b9b8233681a63c3a57b1
M: e50676757acbe7c6a21e8abf4eda26ababb08285 127.0.0.1:7003slots:0-5460 (5461 slots) master0 additional replica(s)
M: 5814305e71552ab45c44b9b8233681a63c3a57b1 127.0.0.1:7002slots:10923-16383 (5461 slots) master1 additional replica(s)
M: d3058a19483d7be5c30c042779e56130f6ebf074 127.0.0.1:7001slots:5461-10922 (5462 slots) master1 additional replica(s)
S: ab307ba26d6dabe8edb2f2a7287be6f01aa46d88 127.0.0.1:7004slots: (0 slots) slavereplicates d3058a19483d7be5c30c042779e56130f6ebf074
[OK] All nodes agree about slots configuration.Check for open slots...Check slots coverage...
[OK] All 16384 slots covered. 可以进入redis中玩一玩查了一下使用redis-cli命令的时候应该加上 -c 意思是在集群模式下否则你会以一种独立的redis进入然后各种moved报错。 看着存储位置跳来跳去貌似简单的集群也就搭建完成了。 [rootlocalhost src]# ./redis-cli -c -p 7000
127.0.0.1:7000 set qiang weikang
- Redirected to slot [1357] located at 127.0.0.1:7003
OK
127.0.0.1:7003 set qiang qiang
OK
127.0.0.1:7003 set weikang qiang
- Redirected to slot [12142] located at 127.0.0.1:7002
OK
127.0.0.1:7002 get qiang
- Redirected to slot [1357] located at 127.0.0.1:7003
qiang
127.0.0.1:7003 get weikang
- Redirected to slot [12142] located at 127.0.0.1:7002
qiang 转载于:https://www.cnblogs.com/lvcisco/p/10309513.html