本篇內(nèi)容介紹了“怎么實(shí)現(xiàn)redis主從復(fù)制”的有關(guān)知識(shí),在實(shí)際案例的操作過程中,不少人都會(huì)遇到這樣的困境,接下來就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!
讓客戶滿意是我們工作的目標(biāo),不斷超越客戶的期望值來自于我們對(duì)這個(gè)行業(yè)的熱愛。我們立志把好的技術(shù)通過有效、簡(jiǎn)單的方式提供給客戶,將通過不懈努力成為客戶在信息化領(lǐng)域值得信任、有價(jià)值的長(zhǎng)期合作伙伴,公司提供的服務(wù)項(xiàng)目有:域名與空間、網(wǎng)頁空間、營(yíng)銷軟件、網(wǎng)站建設(shè)、安達(dá)網(wǎng)站維護(hù)、網(wǎng)站推廣。
架構(gòu)
主 192.168.2.222
從 192.168.2.187
從 192.168.2.188
從庫配置文件添加:
從 192.168.2.187
從 192.168.2.188
[root@rac1 config]# pwd
/usr/local/redis/config
[root@rac1 config]# vim redis.conf
#添加
slaveof 192.168.2.222 6379
重啟數(shù)據(jù)庫
[root@rac1 config]# redis-cli -p 6379 shutdown
[root@rac1 config]# redis-server redis.conf
驗(yàn)證數(shù)據(jù)同步
主庫2.222
[root@cjcos src]# redis-cli
127.0.0.1:6379> set station dba
OK
127.0.0.1:6379> get station
"dba"
從庫2.187
[root@rac1 config]# redis-cli
127.0.0.1:6379> get station
"dba"
從庫2.188
[root@rac2 config]# redis-cli
127.0.0.1:6379> get station
"dba"
主庫2.222查看同步信息
127.0.0.1:6379> info replication
# Replication
role:master
connected_slaves:2
slave0:ip=192.168.2.187,port=6379,state=online,offset=11208,lag=1
slave1:ip=192.168.2.188,port=6379,state=online,offset=11208,lag=1
master_replid:231ff9d15411b50038a43bb0726580f4dd788f80
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:11208
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:11208
同步日志
主庫2.222
----redis.log
8511:M 23 Mar 2020 14:53:51.841 * Background saving terminated with success
8511:M 23 Mar 2020 14:53:51.842 * Synchronization with replica 192.168.2.187:6379 succeeded
8511:M 23 Mar 2020 14:53:57.272 * Replica 192.168.2.188:6379 asks for synchronization
8511:M 23 Mar 2020 14:53:57.272 * Full resync requested by replica 192.168.2.188:6379
8511:M 23 Mar 2020 14:53:57.272 * Starting BGSAVE for SYNC with target: disk
8511:M 23 Mar 2020 14:53:57.272 * Background saving started by pid 8528
8528:C 23 Mar 2020 14:53:57.326 * DB saved on disk
8528:C 23 Mar 2020 14:53:57.327 * RDB: 0 MB of memory used by copy-on-write
常見問題:
同步失敗,日志如下:
----redis.log
29884:S 23 Mar 2020 14:50:29.152 * Connecting to MASTER 192.168.2.222:6379
29884:S 23 Mar 2020 14:50:29.152 * MASTER <-> REPLICA sync started
29884:S 23 Mar 2020 14:50:29.152 * Non blocking connect for SYNC fired the event.
29884:S 23 Mar 2020 14:50:29.153 # Error reply to PING from master: '-DENIED Redis is running in protected mode because protected mode is enabled, no bind address was specified, no authentication password is requested to clients. In this mode connections are only accepted from the loopback interface. If you want to connect'
解決方案:
---配置文件redis.conf添加:
bind 0.0.0.0
“怎么實(shí)現(xiàn)Redis主從復(fù)制”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識(shí)可以關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實(shí)用文章!