温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Redis如何修改redis-trib.rb使其import支持密码

发布时间:2021-11-09 11:11:34 来源:亿速云 阅读:270 作者:小新 栏目:关系型数据库

这篇文章给大家分享的是有关Redis如何修改redis-trib.rb使其import支持密码的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。

需求,现在需要将一个单机redis数据迁移至redis-cluster集群中,两遍都是开启了密码模式的,无密码模式直接import就可以了!现在带密码我试了下import工具发现并不支持密码模式,修改下redis-trib.rb脚本即可支持密码认证了

target端如何支持密码上篇博客已经说明

以下修改为支持source端(单节点端)

修改地方为:

def import_cluster_cmd(argv,opt)
    source_addr = opt['from']
    xputs ">>> Importing data from #{source_addr} to cluster #{argv[1]}"
    use_copy = opt['copy']
    use_replace = opt['replace']
    #use_password = opt['password']   这行注释
    # Check the existing cluster.
    load_cluster_info_from_node(argv[0])
    check_cluster
    # Connect to the source node.
    xputs ">>> Connecting to the source Redis instance"
    src_host,src_port,use_password = source_addr.split(":") ##这行修改添加密码
    source = Redis.new(:host =>src_host, :port =>src_port, :password =>use_password) ##这行

使用如下:

[root@ip-172-31-40-224 src]# /usr/local/src/redis-4.0.8/src/redis-trib.rb import --from 172.31.40.224:6381:inH7HkD7iXoxKZCi --copy   172.31.40.224:6379
>>> Importing data from 172.31.40.224:6381:inH7HkD7iXoxKZCi to cluster 
>>> Performing Cluster Check (using node 172.31.40.224:6379)
M: d5a1288c289dc27c014b34a0ec8280d2d4215747 172.31.40.224:6379
   slots:0-5460 (5461 slots) master
   1 additional replica(s)
S: 7475145029eeccdc91b8db415377888130868199 172.31.40.224:6380
   slots: (0 slots) slave
   replicates c78d49f041e386723fd921cea19421e34c0262b6
M: c78d49f041e386723fd921cea19421e34c0262b6 172.31.40.14:6379
   slots:10923-16383 (5461 slots) master
   1 additional replica(s)
M: 4164f6a49979952479e98ccde18e463e125dd438 172.31.35.125:6379
   slots:5461-10922 (5462 slots) master
   1 additional replica(s)
S: 725078c24574874197707b177375ee8dbf462099 172.31.35.125:6380
   slots: (0 slots) slave
   replicates d5a1288c289dc27c014b34a0ec8280d2d4215747
S: 5a1cbcec8b540dd5d7ce6268942386ce6e48878f 172.31.40.14:6380
   slots: (0 slots) slave
   replicates 4164f6a49979952479e98ccde18e463e125dd438
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
>>> Connecting to the source Redis instance
*** Importing 3 keys from DB 0
Migrating chen1 to 172.31.35.125:6379: OK
Migrating chen to 172.31.40.224:6379: OK
Migrating chen2 to 172.31.35.125:6379: OK

感谢各位的阅读!关于“Redis如何修改redis-trib.rb使其import支持密码”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI