這篇文章給大家分享的是有關(guān)redis如何修改redis-trib.rb使其import支持密碼的內(nèi)容。小編覺得挺實用的,因此分享給大家做個參考,一起跟隨小編過來看看吧。
網(wǎng)站建設(shè)哪家好,找成都創(chuàng)新互聯(lián)!專注于網(wǎng)頁設(shè)計、網(wǎng)站建設(shè)、微信開發(fā)、小程序定制開發(fā)、集團(tuán)企業(yè)網(wǎng)站建設(shè)等服務(wù)項目。為回饋新老客戶創(chuàng)新互聯(lián)還提供了宜黃免費建站歡迎大家使用!
需求,現(xiàn)在需要將一個單機(jī)redis數(shù)據(jù)遷移至redis-cluster集群中,兩遍都是開啟了密碼模式的,無密碼模式直接import就可以了!現(xiàn)在帶密碼我試了下import工具發(fā)現(xiàn)并不支持密碼模式,修改下redis-trib.rb腳本即可支持密碼認(rèn)證了
target端如何支持密碼上篇博客已經(jīng)說明
以下修改為支持source端(單節(jié)點端)
修改地方為:
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)容可以對大家有一定的幫助,讓大家可以學(xué)到更多知識,如果覺得文章不錯,可以把它分享出去讓更多的人看到吧!