記一次遇到的Redis集羣報錯問題——[ERR] Nodes don't agree about configuration!的解決方案

最近在研究搭建redis集羣。根據redis的官方文檔,搭建redis集羣至少需要6臺機器:3臺機器作爲master節點,負責處理數據請求,以及參與集羣選舉投票,採用過半通過機制,所有需要2n+1(n >= 1)個節點;3臺機器作爲slave節點,作爲master的備份節點。當master節點掛掉後,slave節點便提升爲master節點。受限於硬件環境配置,我選擇了使用3臺機器來搭建redis的方案。在每臺機器上分別啓動master進程和slave進程,然後第二臺機器的slave進程作爲第一臺機器的master進程的備份,依次類推。可以保證在這3臺機器中的一臺機器掛掉的情況下,redis集羣還能正常工作。

安裝redis的官方文檔搭建完redis集羣后,redis集羣正常工作。但是在測試時發現一個問題,就是多啓動幾次master進程和slave進程,讓redis自動切換角色後,redis集羣不能正常工作,使用redis-trib.rb check 127.0.0.1:6379命令檢測集羣運行狀況,redis報出了下面的錯誤信息:

[ERR] Nodes don't agree about configuration!
>>> Check for open slots...
[WARNING] Node 192.168.103.153:6379 has slots in importing state (107,415,1672,2204,3400).
[WARNING] The following slots are open: 107,415,1672,2204,3400
>>> Check slots coverage...
[OK] All 16384 slots covered.

這個問題在谷歌上查詢了很久也沒查到答案,後來通過檢查redis的配置文件redis.conf文件才找到原因,原來是在master進程和slave進程分別使用的配置文件中,我將這appendfilename一項配置成了同一個值:

############################## APPEND ONLY MODE ###############################

# By default Redis asynchronously dumps the dataset on disk. This mode is
# good enough in many applications, but an issue with the Redis process or
# a power outage may result into a few minutes of writes lost (depending on
# the configured save points).
#
# The Append Only File is an alternative persistence mode that provides
# much better durability. For instance using the default data fsync policy
# (see later in the config file) Redis can lose just one second of writes in a
# dramatic event like a server power outage, or a single write if something
# wrong with the Redis process itself happens, but the operating system is
# still running correctly.
#
# AOF and RDB persistence can be enabled at the same time without problems.
# If the AOF is enabled on startup Redis will load the AOF, that is the file
# with the better durability guarantees.
#
# Please check http://redis.io/topics/persistence for more information

appendonly yes

# The name of the append only file (default: "appendonly.aof")

appendfilename "appendonly.aof

這個配置項是redis持久化數據到本地磁盤的文件名稱,當使用了同一個名稱時,master進程和slave進程都向這個數據庫寫入數據,造成了數據錯亂,集羣不能正常工作,修改appendfilename爲不同的值後,問題得以解決。

發佈了12 篇原創文章 · 獲贊 3 · 訪問量 1萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章