官方提供了脚本创建集群的工具,我们参照官方的指导进行创建集群以我本测试环境为例:
/usr/local/soft/redis-cluster/redis-3.2.1/utils/create-cluster
进入脚本目录后执行集群创建失败,如下:
[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
通过查找官方文档说明,
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)
gem install redis
系统没有安装gem,先安装gem。
1)yum install ruby
2)安装rubygems
ruby setup.rb --help
安装提示ruby版本需大于1.8.7,则需要手动安装ruby。从【ruby源】下载安装包后解压进行安装。
[root@bogon create-cluster]# gem install redisERROR: Loading command: install (LoadError) cannot load such file -- zlibERROR: 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。
[root@bogon create-cluster]# gem install redisERROR: 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 redisFetching: redis-3.3.1.gem (100%)Successfully installed redis-3.3.1Parsing documentation for redis-3.3.1Installing ri documentation for redis-3.3.1Done installing documentation for redis after 1 seconds1 gem installed
进入脚本创建集群的目录/usr/local/soft/redis-cluster/redis-3.2.1/utils/create-cluster启动节点后创建集群。
1)启动6个节点
[root@bogon create-cluster]# ./create-cluster startStarting 20001Starting 20002Starting 20003Starting 20004Starting 20005Starting 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:20001127.0.0.1:20002127.0.0.1:20003Adding replica 127.0.0.1:20004 to 127.0.0.1:20001Adding replica 127.0.0.1:20005 to 127.0.0.1:20002Adding replica 127.0.0.1:20006 to 127.0.0.1:20003M: d3bef4dff6260735c0ff12b8add62636c2bc7e4f 127.0.0.1:20001 slots:0-5460 (5461 slots) masterM: 351691e42b2207cf0322dbf4904c9b9fc6e6d18a 127.0.0.1:20002 slots:5461-10922 (5462 slots) masterM: 54f86341f254d453f5e9221ecc6ab1623fdc7ed2 127.0.0.1:20003 slots:10923-16383 (5461 slots) masterS: cbf8299efc5ef5422d3f160f54d7f7fb5452d613 127.0.0.1:20004 replicates d3bef4dff6260735c0ff12b8add62636c2bc7e4fS: 43a8538ace038e638ecc98c162bedfe4ed43798c 127.0.0.1:20005 replicates 351691e42b2207cf0322dbf4904c9b9fc6e6d18aS: 83df222815c36c773c2494486a03ffcd3367210a 127.0.0.1:20006 replicates 54f86341f254d453f5e9221ecc6ab1623fdc7ed2Can 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 clusterWaiting 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) masterM: 351691e42b2207cf0322dbf4904c9b9fc6e6d18a 127.0.0.1:20002 slots:5461-10922 (5462 slots) masterM: 54f86341f254d453f5e9221ecc6ab1623fdc7ed2 127.0.0.1:20003 slots:10923-16383 (5461 slots) masterM: cbf8299efc5ef5422d3f160f54d7f7fb5452d613 127.0.0.1:20004 slots: (0 slots) master replicates d3bef4dff6260735c0ff12b8add62636c2bc7e4fM: 43a8538ace038e638ecc98c162bedfe4ed43798c 127.0.0.1:20005 slots: (0 slots) master replicates 351691e42b2207cf0322dbf4904c9b9fc6e6d18aM: 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