redis主從連接不成功錯誤問題及解決
redis主從連接不成功錯誤
安裝完redis后,設(shè)置主從,在從服務(wù)器上運行
127.0.0.1:6379> slaveof 192.168.159.131 6379
slaveof <主服務(wù)器的IP> <主服務(wù)器redis的端口>
然后回到主服務(wù)器上,運行info replication
顯示如下:
127.0.0.1:6379> info replication # Replication role:master connected_slaves:0 master_repl_offset:0 repl_backlog_active:0 repl_backlog_size:1048576 repl_backlog_first_byte_offset:0 repl_backlog_histlen:0
問題出現(xiàn)了
從沒有連接上來。
查看主redis的日志文件
[1922] 22 Mar 22:04:24.971 * RDB: 0 MB of memory used by copy-on-write
[1544] 22 Mar 22:04:25.008 * Background saving terminated with success
[1544] 22 Mar 22:27:23.567 * Background saving started by pid 2079
[2079] 22 Mar 22:27:23.574 * DB saved on disk
[2079] 22 Mar 22:27:23.575 * RDB: 0 MB of memory used by copy-on-write
[1544] 22 Mar 22:27:23.604 * Background saving terminated with success
查看從服務(wù)器日志
有如下錯誤:
Error condition on socket for SYNC: No route to host
然后telnet 主的端口竟然不通,發(fā)現(xiàn)主服務(wù)器的iptables開著,關(guān)掉后就可以和主服務(wù)器的端口通了(生產(chǎn)環(huán)境添加iptables規(guī)則)。
但是發(fā)現(xiàn)還是從不能連上主,再看從的日志時
變成如下內(nèi)容:
[4399] 22 Mar 14:41:56.311 # MASTER aborted replication with an error: NOAUTH Authentication required.
[4399] 22 Mar 14:41:57.313 * Connecting to MASTER 192.168.159.131:6379
[4399] 22 Mar 14:41:57.313 * MASTER <-> SLAVE sync started
[4399] 22 Mar 14:41:57.313 * Non blocking connect for SYNC fired the event.
[4399] 22 Mar 14:41:57.314 * Master replied to PING, replication can continue...
[4399] 22 Mar 14:41:57.315 * (Non critical) Master does not understand REPLCONF listening-port: -NOAUTH Authentication required.
[4399] 22 Mar 14:41:57.315 * Partial resynchronization not possible (no cached master)
[4399] 22 Mar 14:41:57.316 # Unexpected reply to PSYNC from master: -NOAUTH Authentication required.
[4399] 22 Mar 14:41:57.317 * Retrying with SYNC...
[4399] 22 Mar 14:41:57.319 # MASTER aborted replication with an error: NOAUTH Authentication required.
網(wǎng)上查找有說是版本不一致造成的,但是我的版本都是一樣的。
最后找到了解決方法
原來是主從都開啟了密碼requirepass,導(dǎo)致不能驗證成功
在redis從服務(wù)器的配置文件里面添加如下內(nèi)容:
masterauth 123456
(123456是我的主redis的密碼,此參數(shù)是當(dāng)與主連接時的密碼驗證)
總結(jié)
這樣就解決了主從連接不成功問題~
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
高并發(fā)下Redis精確計數(shù)與時間窗口過期的方法詳解
在實時數(shù)據(jù)處理系統(tǒng)中,我們經(jīng)常需要統(tǒng)計某個事件在特定時間窗口內(nèi)的發(fā)生次數(shù),本文將詳細介紹如何基于 Redis 實現(xiàn)高性能、高可用的計數(shù)方案,需要的可以參考下2025-03-03
Redis數(shù)據(jù)類型之散列類型hash命令學(xué)習(xí)
這篇文章主要為大家介紹了Redis數(shù)據(jù)類型之散列類型hash命令學(xué)習(xí),有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-07-07
Redis數(shù)據(jù)備份與恢復(fù)方式的五種方式
本文主要介紹了Redis數(shù)據(jù)備份與恢復(fù)方式,包含了五種方式,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2024-07-07
Windows安裝Redis并添加本地自啟動服務(wù)的實例詳解
這篇文章主要介紹了Windows安裝Redis并添加本地自啟動服務(wù)的實例詳解,本文給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-11-11

