问题:
[root@cdh1 cluster1]# /opt/model/redis-3.2.10/src/redis-trib.rb create --replicas 1 172.17.10.152:6379 172.17.10.153:6379 172.17.10.154:6379 172.17.10.153:6380 172.17.10.154:6380 172.17.10.152:6380
>>> Creating cluster
[ERR] Sorry, can't connect to node 172.17.10.152:6379
解决方法一:版本没问题呀。redis-3.2.1.gem 都安装上了肯定没问题了!
ruby : 2.0(>1.9.2或者更高版本)
rubygem: 2.0 (>1.8.16或者更高版本)
gem-redis: 3.2.1(>3.0.0或者更高版本)
问题分析:
首先需要注释掉密码,#requirepass redis6379!
其次需要绑定一个ip地址,不能缺省bind 172.17.10.152,,切记切记!!!!!
排查过程:
/usr/local/bin/redis-cli -h 172.17.10.152 -p 6379#必须加上-h参数!!!
执行 keys * ,发现错误:
(error) DENIED Redis is running in protected mode because protected mode is enabled, no bind address was specified, no authentication password is requested to clients. In this mode connections are only accepted from the loopback interface. If you want to connect from external computers to Redis you may adopt one of the following solutions: 1) Just disable protected mode sending the command 'CONFIG SET protected-mode no' from the loopback interface by connecting to Redis from the same host the server is running, however MAKE SURE Redis is not publicly accessible from internet if you do so. Use CONFIG REWRITE to make this change permanent. 2) Alternatively you can just disable the protected mode by editing the Redis configuration file, and setting the protected mode option to 'no', and then restarting the server. 3) If you started the server manually just for testing, restart it with the '--protected-mode no' option. 4) Setup a bind address or an authentication password. NOTE: You only need to do one of the above things in order for the server to start accepting connections from the outside.
翻译:这就是连不上的原因所在!!
由于启用了保护模式,没有指定绑定地址,也没有向客户机请求身份验证密码,所以拒绝Redis在保护模式下运行。在这种模式下,连接只能从环回接口接受。如果你想从外部计算机连接到复述,你可能采取的解决方案:1)只是禁用保护模式发送命令的配置设置保护模式没有从loopback接口连接到复述同一主机服务器正在运行,然而确保复述,不是公开从互联网访问如果你这样做。使用配置重写使此更改永久。2)也可以通过编辑Redis配置文件,将保护模式选项设置为“no”,然后重启服务器,禁用保护模式。3)如果您只是为了测试而手动启动服务器,请使用“——保护模式no”选项重新启动服务器。4)设置绑定地址或身份验证密码。注意:您只需要做上述其中一件事,服务器就可以开始接受来自外部的连接
解决方法二:rubygem版本太低啦啊?如果你的版本已经符合要求,你就不是版本问题,要么是redis设置了密码,需要去掉。要么是没有绑定bind:使用方法一来解决即可!不要被解决方法二坑啦!
ruby -v
gem -v
ruby : 1.9.2或者更高版本
rubygem: 1.8.16或者更高版本
gem-redis: 3.0.0或者更高版本
1) ./redis-trib.rb create --replicas 1 cdh5:6379 cdh4:6379 cdh3:6379 cdh5:6389 cdh4:6389 cdh3:6389
报错:
>>> Creating cluster
Connecting to node cdh5:6379: [ERR] Sorry, can't connect to node cdh5:6379
可能的问题:
第一: ruby 和rubygem 版本太低,安装新版本。
安装 ruby 和rubygem
ftp://ftp.ruby-lang.org/pub/ruby/ 下载ruby-2.3.1.tar.gz ,上传到cdh5服务器目录:/usr/local/src目录
cd /usr/local/src
tar -zxvf ruby-2.3.1.tar.gz
cd ruby-2.3.1
./configure && make && make install
安装gem-redis:ruby和redis的接口:
下载 redis-3.0.0.gem 执行:
gem install -l redis-3.0.0.gem
报错:
ERROR: While executing gem ... (Gem::Exception)
Unable to require openssl, install OpenSSL and rebuild ruby (preferred) or use non-HTTPS sources
解决方法:http://www.openssl.org/source/下载:openssl-1.0.1u.tar.gz 注意:一定要下载1.0.1版本 其他版本怎么试都不行!!!!
tar -xzvf openssl-1.0.1u.tar.gz
cd openssl-1.0.1u
./config -fPIC --prefix=/usr/local/openssl enable-shared
./config -t
make && make install
进入ruby源码[/usr/local/src/ruby-2.3.0]目录下的ext/openssl 目录:
ruby extconf.rb --with-openssl-include=/usr/local/openssl/include/ --with-openssl-lib=/usr/local/openssl/lib
显示如下说明正确:[root@localhost openssl]# make
compiling ossl_pkey_dsa.c
compiling openssl_missing.c
compiling ossl_x509name.c
compiling ossl_pkey_rsa.c
.............................................中间略.............................................
compiling ossl_bn.c
compiling ossl.c
linking shared-object openssl.so
make && make install
再次执行:gem install -l redis-3.0.0.gem
配置环境变量:
export OPENSSL=/usr/local/openssl/bin
export PATH=$OPENSSL:$PATH:$HOME/bin
如果查看版本报错:ruby -v 、 gem -v
openssl: error while loading shared libraries: libssl.so.1.1: cannot open shared object file: No such file or directory
则执行:ln -s /usr/local/lib64/libssl.so.1.1 /usr/lib64/libssl.so.1.1
ln -s /usr/local/lib64/libcrypto.so.1.1 /usr/lib64/libcrypto.so.1.1
如果发现报错:cannot load such file -- zlib ruby ------可以参考本人另外一篇文章:
http://blog.csdn.net/wumiqing1/article/details/53606557
-------------到此:ruby rubygem gem-redis已经安装完毕-------
cd /usr/local/src/redis-3.0.1/src/
./redis-trib.rb create --replicas 1 10.222.128.30:6379 10.222.128.29:6379 10.222.128.28:6379
10.222.128.30:6389 10.222.128.29:6389 10.222.128.28:6389
一定要注意些ip,不能写hostname 要不然不支持!用户也要切换正确,本人用户 su - redis_6379!!!!
如果还是报错:Creating cluster Connecting to node ****:6379: [ERR] Sorry, can't connect to node ****:6379
解决方法:检查redis配置:
vi redis.conf
cluster-enabled yes
cluster-config-file nodes-6379.conf
cluster-node-timeout 5000
确保这些不被注释:
并清除: cluster-config-file 对应的配置文件!重启redis
再次执行:./redis-trib.rb create --replicas 1 10.222.128.30:6379 10.222.128.29:6379 10.222.128.28:6379
10.222.128.30:6389 10.222.128.29:6389 10.222.128.28:6389