码迷,mamicode.com
首页 > 其他好文 > 详细

Redis学习笔记7--Redis集群搭建

时间:2017-06-03 15:17:03      阅读:241      评论:0      收藏:0      [点我收藏+]

标签:clu   setup   log   使用   cas   系统   install   rem   笔记   

在安装redis集群之前,要先安装一些环境

(1)安装zlib

确保系统安装zlib,否则gem install会报(no such file to load -- zlib)

zlib-1.2.6.tar  

./configure

make

make install

 

(2)安装ruby

ruby 使用本地yum安装也能使用(推荐)

编译安装:

这里不能使用make & make install

ruby1.9.2   

./configure -prefix=/usr/local/ruby  

make  

make install  

sudo cp ruby /usr/local/bin  

 

(3)安装rubygem:version(1.8.16)

# rubygems-1.8.24.tgz

cd /path/gem

sudo ruby setup.rb

 

 

(4)安装gem-redis:version(3.0.0)

 将网络放开,切换为淘宝源地址:

# gem source -l

# gem source --remove http://rubygems.org/

# gem sources -a https://ruby.taobao.org/

# gem source -l

gem install redis --version 3.0.0

 

报错信息:

ERROR: RDoc documentation generator not installed: no such file to load -- rdoc/rdoc

解决办法:

yum install ruby-rdoc -y

vi  redis.conf

 

##修改配置文件中的下面选项

port 7000

daemonize yes

cluster-enabled yes

cluster-config-file nodes-对应端口号.conf

cluster-node-timeout 5000

appendonly yes

bind ip地址

 

以配置文件分别启动这6redis实例

redis-server redis.conf指定以配置文件启动

--replicas 1代表一个主节点下面有一个副节点

./redis-trib.rb create --replicas 1 10.10.10.30:6379 10.10.10.30:6380 10.10.10.40:6381 10.10.10.40:6382 10.10.10.50:6383 10.10.10.50:6384

[root@localhost src]# ./redis-trib.rb create --replicas 1 10.10.10.30:6379 10.10.10.30:6380 10.10.10.40:6381 10.10.10.40:6382 10.10.10.50:6383 10.10.10.50:6384
>>> Creating cluster
>>> Performing hash slots allocation on 6 nodes...
Using 3 masters:
10.10.10.50:6383
10.10.10.40:6381
10.10.10.30:6379
Adding replica 10.10.10.40:6382 to 10.10.10.50:6383
Adding replica 10.10.10.50:6384 to 10.10.10.40:6381
Adding replica 10.10.10.30:6380 to 10.10.10.30:6379
M: 89626713538d146b7890e6f47c62c6aad78f53d2 10.10.10.30:6379
   slots:10923-16383 (5461 slots) master
S: 825e93a27442e225204ee30c59691d0d5e29fe26 10.10.10.30:6380
   replicates 89626713538d146b7890e6f47c62c6aad78f53d2
M: 4919bd2396b138160fd10946f762e0b5b7ef755f 10.10.10.40:6381
   slots:5461-10922 (5462 slots) master
S: 5f06981deeb179aee3671143d8dcfd4001896716 10.10.10.40:6382
   replicates f276f424f1807f2d381cd054ac7579e2b790d0cf
M: f276f424f1807f2d381cd054ac7579e2b790d0cf 10.10.10.50:6383
   slots:0-5460 (5461 slots) master
S: fb84aeb17bb628840f19566a0a2d89e60ab540cc 10.10.10.50:6384
   replicates 4919bd2396b138160fd10946f762e0b5b7ef755f
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 10.10.10.30:6379)
M: 89626713538d146b7890e6f47c62c6aad78f53d2 10.10.10.30:6379
   slots:10923-16383 (5461 slots) master
   1 additional replica(s)
S: 825e93a27442e225204ee30c59691d0d5e29fe26 10.10.10.30:6380
   slots: (0 slots) slave
   replicates 89626713538d146b7890e6f47c62c6aad78f53d2
S: 5f06981deeb179aee3671143d8dcfd4001896716 10.10.10.40:6382
   slots: (0 slots) slave
   replicates f276f424f1807f2d381cd054ac7579e2b790d0cf
S: fb84aeb17bb628840f19566a0a2d89e60ab540cc 10.10.10.50:6384
   slots: (0 slots) slave
   replicates 4919bd2396b138160fd10946f762e0b5b7ef755f
M: 4919bd2396b138160fd10946f762e0b5b7ef755f 10.10.10.40:6381
   slots:5461-10922 (5462 slots) master
   1 additional replica(s)
M: f276f424f1807f2d381cd054ac7579e2b790d0cf 10.10.10.50:6383
   slots:0-5460 (5461 slots) master
   1 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

 

 

连接redis集群必须指定IP地址和端口:

./redis-cli -h 10.10.10.30 -p 6379 -c

10.10.10.30:6379> set name1 qiangge

OK

10.10.10.30:6379> set name2 wanningxi

-> Redirected to slot [742] located at 10.10.10.50:6383

OK

10.10.10.50:6383> set name3 longge

OK

10.10.10.50:6383> set name4 xiaomin

-> Redirected to slot [8736] located at 10.10.10.40:6381

OK

10.10.10.40:6381> get name3

-> Redirected to slot [4807] located at 10.10.10.50:6383

"longge"

10.10.10.50:6383> get name2

"wanningxi"

10.10.10.50:6383> get name1

-> Redirected to slot [12933] located at 10.10.10.30:6379

"qiangge"

10.10.10.30:6379> get name

-> Redirected to slot [5798] located at 10.10.10.40:6381

"wanning"

10.10.10.40:6381>

 

 

 

 

Redis学习笔记7--Redis集群搭建

标签:clu   setup   log   使用   cas   系统   install   rem   笔记   

原文地址:http://www.cnblogs.com/asen0713/p/6937074.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!