溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

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

發(fā)布時(shí)間:2021-11-09 11:11:34 來源:億速云 閱讀:288 作者:小新 欄目:關(guān)系型數(shù)據(jù)庫(kù)

這篇文章給大家分享的是有關(guān)Redis如何修改redis-trib.rb使其import支持密碼的內(nèi)容。小編覺得挺實(shí)用的,因此分享給大家做個(gè)參考,一起跟隨小編過來看看吧。

需求,現(xiàn)在需要將一個(gè)單機(jī)redis數(shù)據(jù)遷移至redis-cluster集群中,兩遍都是開啟了密碼模式的,無密碼模式直接import就可以了!現(xiàn)在帶密碼我試了下import工具發(fā)現(xiàn)并不支持密碼模式,修改下redis-trib.rb腳本即可支持密碼認(rèn)證了

target端如何支持密碼上篇博客已經(jīng)說明

以下修改為支持source端(單節(jié)點(diǎn)端)

修改地方為:

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

感謝各位的閱讀!關(guān)于“Redis如何修改redis-trib.rb使其import支持密碼”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,讓大家可以學(xué)到更多知識(shí),如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到吧!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI