官方提供了脚本建立集群的工具,咱们参照官方的指导进行建立集群以我本测试环境为例:html
/usr/local/soft/redis-cluster/redis-3.2.1/utils/create-clusternode
进入脚本目录后执行集群建立失败,以下:redis
[root@bogon create-cluster]# ./create-cluster create ../../src/redis-trib.rb:24:in `require': no such file to load -- rubygems (LoadError) from ../../src/redis-trib.rb:24
经过查找官方文档说明,ruby
The redis-trib
utility is in the src
directory of the Redis source code distribution. You need to install redis
gem to be able to run redis-trib
.(....须要经过安装redis gem来运行redis-trib)bash
gem install redis
系统没有安装gem,先安装gem。工具
1)yum install ruby测试
2)安装rubygemsui
ruby setup.rb --help
安装提示ruby版本需大于1.8.7,则须要手动安装ruby。从【ruby源】下载安装包后解压进行安装。spa
[root@bogon create-cluster]# gem install redis ERROR: Loading command: install (LoadError) cannot load such file -- zlib ERROR: While executing gem ... (NoMethodError) undefined method `invoke_with_build_args' for nil:NilClass
进入ruby安装目录/usr/local/soft/ruby/ruby-2.1.7/ext/zlib,手动编译安装zlib。.net
[root@bogon create-cluster]# gem install redis ERROR: While executing gem ... (Gem::Exception) Unable to require openssl, install OpenSSL and rebuild ruby (preferred) or use non-HTTPS sources
yum install openssl-devel
yum install openssl
进入ruby安装目录/usr/local/soft/ruby/ruby-2.1.7/ext/openssl,手动编译安装openssl
上述安装成功后,从新执行gem install redis
[root@bogon openssl]# gem install redis Fetching: redis-3.3.1.gem (100%) Successfully installed redis-3.3.1 Parsing documentation for redis-3.3.1 Installing ri documentation for redis-3.3.1 Done installing documentation for redis after 1 seconds 1 gem installed
进入脚本建立集群的目录/usr/local/soft/redis-cluster/redis-3.2.1/utils/create-cluster启动节点后建立集群。
1)启动6个节点
[root@bogon create-cluster]# ./create-cluster start Starting 20001 Starting 20002 Starting 20003 Starting 20004 Starting 20005 Starting 20006
2)建立集群,3主3从
[root@bogon create-cluster]# ./create-cluster create >>> Creating cluster >>> Performing hash slots allocation on 6 nodes... Using 3 masters: 127.0.0.1:20001 127.0.0.1:20002 127.0.0.1:20003 Adding replica 127.0.0.1:20004 to 127.0.0.1:20001 Adding replica 127.0.0.1:20005 to 127.0.0.1:20002 Adding replica 127.0.0.1:20006 to 127.0.0.1:20003 M: d3bef4dff6260735c0ff12b8add62636c2bc7e4f 127.0.0.1:20001 slots:0-5460 (5461 slots) master M: 351691e42b2207cf0322dbf4904c9b9fc6e6d18a 127.0.0.1:20002 slots:5461-10922 (5462 slots) master M: 54f86341f254d453f5e9221ecc6ab1623fdc7ed2 127.0.0.1:20003 slots:10923-16383 (5461 slots) master S: cbf8299efc5ef5422d3f160f54d7f7fb5452d613 127.0.0.1:20004 replicates d3bef4dff6260735c0ff12b8add62636c2bc7e4f S: 43a8538ace038e638ecc98c162bedfe4ed43798c 127.0.0.1:20005 replicates 351691e42b2207cf0322dbf4904c9b9fc6e6d18a S: 83df222815c36c773c2494486a03ffcd3367210a 127.0.0.1:20006 replicates 54f86341f254d453f5e9221ecc6ab1623fdc7ed2 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:20001) M: d3bef4dff6260735c0ff12b8add62636c2bc7e4f 127.0.0.1:20001 slots:0-5460 (5461 slots) master M: 351691e42b2207cf0322dbf4904c9b9fc6e6d18a 127.0.0.1:20002 slots:5461-10922 (5462 slots) master M: 54f86341f254d453f5e9221ecc6ab1623fdc7ed2 127.0.0.1:20003 slots:10923-16383 (5461 slots) master M: cbf8299efc5ef5422d3f160f54d7f7fb5452d613 127.0.0.1:20004 slots: (0 slots) master replicates d3bef4dff6260735c0ff12b8add62636c2bc7e4f M: 43a8538ace038e638ecc98c162bedfe4ed43798c 127.0.0.1:20005 slots: (0 slots) master replicates 351691e42b2207cf0322dbf4904c9b9fc6e6d18a M: 83df222815c36c773c2494486a03ffcd3367210a 127.0.0.1:20006 slots: (0 slots) master replicates 54f86341f254d453f5e9221ecc6ab1623fdc7ed2 [OK] All nodes agree about slots configuration. >>> Check for open slots... >>> Check slots coverage... [OK] All 16384 slots covered.
参考资料:
https://rubygems.org/pages/download/
https://ruby.taobao.org/
http://www.runoob.com/ruby/ruby-installation-unix.html
http://stackoverflow.com/questions/9727908/cannot-load-such-file-zlib-even-after-using-rvm-pkg-install-zlib
http://blog.csdn.net/kenera/article/details/25962587