redis-cluster 添加密码设置

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了redis-cluster 添加密码设置相关的知识,希望对你有一定的参考价值。

参考技术A 1、修改配置文件

在每个节点的配置文件里面增加密码选项,一定要加上 masterauth,不然 Redirected 的时候会失败。

masterauth   redispassword

requirepass redispassword

修改后需要重启节点。

2、动态修改

连接每个节点进行动态配置,然后 config rewrite 将配置同步到配置文件中,不需要重启节点。

$ redis-cli -p 7001 -c>config   set   masterauth redispassword

 > config   set   requirepass redispassword

> config rewrite

注意:以上方法都必须要求每个节点的密码保持一致,不然 Redirected 的时候会失败。

redis-cluster分布式集群安装部署

/opt/redis-3.2.8/src/redis-trib.rb 这个命令是基于Ruby域名编写的,所以需要有Ruby环境才可以运行,所以要准备redis的Ruby环境。

1.安装Ruby环境

yum -y install ruby ruby-devel
yum -y install rubygems

2.添加淘宝的Ruby

[[email protected] ~]#gem sources --remove http://rubygems.org/   http://rubygems.org/ removed from sources
 添加淘宝ruby源;
[[email protected] ~]#gem sources --add https://ruby.taobao.org/   https://ruby.taobao.org/ added to sources
查看现有ruby源;
[[email protected] ~]#gem sources -l
*** CURRENT SOURCES ***
https://ruby.taobao.org/

3.安装curl和RVM

[[email protected] ~]#sudo yum install curl -y

安装RVM

[[email protected] ~]#curl -L get.rvm.io | bash -s stable
[[email protected] ~]#source/usr/local/rvm/scripts/rvm

查看rvm库中已知的ruby版本

[[email protected] ~]#rvm list known   
MRI Rubies
[ruby-]2.0.0[-p648]
[ruby-]2.1[.10]
[ruby-]2.2[.7]
[ruby-]2.3[.4]
[ruby-]2.4[.1]
**安装一个ruby版本**
[[email protected] ~]#rvm install 2.3.4  #### 这里要选择正确 

[[email protected] ~]# ruby --version
ruby 1.8.7 (2013-06-27 patchlevel 374) [x86_64-linux]

[[email protected] ~]# rvm --create ruby-2.3.4
Warning! PATH is not properly set up, ‘/usr/local/rvm/gems/ruby-2.3.4/bin‘ is not available.
         Usually this is caused by shell initialization files. Search for ‘PATH=...‘ entries.
         You can also re-add RVM to your profile by running: ‘rvm get stable --auto-dotfiles‘.
         To fix it temporarily in this shell session run: ‘rvm use ruby-2.3.4‘.
         To ignore this error add rvm_silence_path_mismatch_check_flag=1 to your ~/.rvmrc file.
Using /usr/local/rvm/gems/ruby-2.3.4

查看当前的Ruby的版本:

[[email protected] ~]# 
[[email protected] ~]# ruby --version
ruby 2.3.4p301 (2017-03-30 revision 58214) [x86_64-linux]
[[email protected] ~]# gem install redis --version 3.2.8
ERROR:  Could not find a valid gem ‘redis‘ (= 3.2.8) in any repository

报错,于是换个redis的版本,安装成功

[[email protected] ~]# gem install redis --version 3.2.1
Fetching: redis-3.2.1.gem (100%)
Successfully installed redis-3.2.1
Parsing documentation for redis-3.2.1
Installing ri documentation for redis-3.2.1
Done installing documentation for redis after 2 seconds
1 gem installed

redis-trib.rb 出现如下帮助信息说明安装成功

[[email protected] ~]# /opt/redis-3.2.8/src/redis-trib.rb
Usage: redis-trib <command> <options> <arguments ...>

  create          host1:port1 ... hostN:portN
                  --replicas <arg>
  check           host:port
  info            host:port
  fix             host:port
                  --timeout <arg>
  reshard         host:port
                  --from <arg>
                  --to <arg>
                  --slots <arg>
                  --yes
                  --timeout <arg>
                  --pipeline <arg>
  rebalance       host:port
                  --weight <arg>
                  --auto-weights
                  --use-empty-masters
                  --timeout <arg>
                  --simulate
                  --pipeline <arg>
                  --threshold <arg>
  add-node        new_host:new_port existing_host:existing_port
                  --slave
                  --master-id <arg>
  del-node        host:port node_id
  set-timeout     host:port milliseconds
  call            host:port command arg arg .. arg
  import          host:port
                  --from <arg>
                  --copy
                  --replace
  help            (show this help)

For check, fix, reshard, del-node, set-timeout you can specify the host and port of any working node in the cluster.
[[email protected] ~]# 

以上是关于redis-cluster 添加密码设置的主要内容,如果未能解决你的问题,请参考以下文章

Redis-Cluster操作命令大全

redis-cluster集群配置和主从

redis-cluster分布式集群安装部署

ruby-2.4.6和redis-4.1.3.gem环境下的redis-cluster集群中的bug

Redis-Cluster

Redis-cluster 集群操作命令