redis cluster 设置密码做集群时gem下client.rb文件修改
redis cluster 设置密码做集群时gem下client.rb文件修改
来源 https://www.cnblogs.com/shihaiming/p/5949772.html
redis节点有设置密码,然后在创建集群的时候没有设置密码的命令
./redis-trib.rb create --replicas 1 127.0.0.1:6381 127.0.0.1:6382 127.0.0.1:6383 127.0.0.1:6384127.0.0.1:6385 127.0.0.1:6386
Connecting to node 127.0.0.1:6381: [ERR] Sorry, can't connect to node 127.0.0.1:6381
JedisCluster类也没有设置密码的方法,只能在JedisPool中设置
集群创建前需要修改gem的redis工具下的一个文件,我这里是默认安装,路径如下:/usr/lib/ruby/gems/1.8/gems/redis-3.2.1/lib/redis/client.rb ,修改内容如下:
,我这里的测试是,添加密码后重建了集群;
至于已运行的集群,如何添加密码
对每一个节点用命令设置密码或修改每一个节点的配置文件中密码项后重启,需要验证
- config set masterauth abc
- config set requirepass abc
- config rewrite
集群构建成功前的redis配置:
port 8000
cluster-enabled yes
cluster-config-file "nodes-8000.conf"
cluster-node-timeout 15000
dir "/opt/redisdata"
appendonly yes
appendfilename "appendonly-8000.aof"
logfile "/opt/redisdata/8000.log"
daemonize yes
pidfile "/var/run/redis-8000.pid"
dbfilename "dump-8000.rdb"
cluster-require-full-coverage no
集群构建成功后的redis配置:
port 8004
cluster-enabled yes
cluster-config-file "nodes-8004.conf"
cluster-node-timeout 15000
dir "/opt/redisdata"
appendonly yes
appendfilename "appendonly-8004.aof"
logfile "/opt/redisdata/8004.log"
daemonize yes
pidfile "/var/run/redis-8004.pid"
dbfilename "dump-8004.rdb"
cluster-require-full-coverage no
# Generated by CONFIG REWRITE
requirepass "abc"
masterauth "abc"