1. 程式人生 > >記一次redis主從連線的錯誤

記一次redis主從連線的錯誤

Redis版本 redis-4.0.11
安裝後多例項均可正常使用,將其中一個例項設定為從伺服器後,呼叫info replication報master_link_status:down;
外部原因:
1.因為redis部署在阿里雲伺服器上,首先在阿里雲控制檯開放各redis例項的埠;
2.使用系統為ubuntu,設定ufw allow 各例項埠
步驟一:開啟log日誌,
設定log等級為debug,loglevel debug
設定log檔案路徑為: logfile “/usr/local/redis/log/redislog_16378.log”
步驟二:
日誌內容如下所示:
slave:
11613:S 22 Aug 22:14:56.796 * Connecting to MASTER 47.95.212.99:16379
11613:S 22 Aug 22:14:56.796 * MASTER <-> SLAVE sync started
11613:S 22 Aug 22:14:56.799 * Non blocking connect for SYNC fired the event.
11613:S 22 Aug 22:14:56.802 * Master replied to PING, replication can continue…
11613:S 22 Aug 22:14:56.804 * (Non critical) Master does not understand REPLCONF listening-port: -NOAUTH Authentication required.
11613:S 22 Aug 22:14:56.807 * (Non critical) Master does not understand REPLCONF capa: -NOAUTH Authentication required.
11613:S 22 Aug 22:14:56.807 * Partial resynchronization not possible (no cached master)
11613:S 22 Aug 22:14:56.809 # Unexpected reply to PSYNC from master: -NOAUTH Authentication required.
11613:S 22 Aug 22:14:56.809 * Retrying with SYNC…
11613:S 22 Aug 22:14:56.812 # MASTER aborted replication with an error: NOAUTH Authentication required.
master:
11599:M 22 Aug 22:14:47.055 - Accepted 175.169.183.207:8917
11599:M 22 Aug 22:14:47.261 * Slave 175.169.183.207:16379 asks for synchronization
11599:M 22 Aug 22:14:47.261 * Full resync requested by slave 175.169.183.207:16379
11599:M 22 Aug 22:14:47.261 * Starting BGSAVE for SYNC with target: disk
11599:M 22 Aug 22:14:47.262 * Background saving started by pid 11603
11603:C 22 Aug 22:14:47.266 * DB saved on disk
11603:C 22 Aug 22:14:47.266 * RDB: 6 MB of memory used by copy-on-write
11599:M 22 Aug 22:14:47.357 * Background saving terminated with success
11599:M 22 Aug 22:14:47.357 * Synchronization with slave 175.169.183.207:16379 succeeded
11599:M 22 Aug 22:14:47.443 - Reading from client: Connection reset by peer
11599:M 22 Aug 22:14:47.443 # Connection with slave client id #3 lost.
經查slave未設定主伺服器密碼

解決方式:redis.conf中新增如下設定—> masterauth password
指定密碼後
輸入info replication
role:slave
master_host:47.95.212.99
master_port:16379
master_link_status:up
master_last_io_seconds_ago:7
master_sync_in_progress:0
slave_repl_offset:28
slave_priority:100
slave_read_only:1
connected_slaves:0
master_replid:fc628a2b0f62b1c7175847ea1c7ac72169263b73
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:28
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:28
連線成功
效果圖