2013-04-20 75 views
3

我爲我的nodeJS應用程序安裝了Redis,並將其配置爲另一臺運行在不同服務器上的另一個Redis DB實例的從服務器。我是否可以將Redis(作爲從服務器運行)的相同實例(不同數據庫)作爲主服務器用於本地安裝的應用程序?Redis DB Master Slave設置

在此先感謝

回答

4

是的,你可以,但有一個大警告

任何從設備實例都可以是一個或多個其他實例的主設備。所以你可以想象菊花鏈奴隸和建立一個分層複製系統。

現在,我的理解是你不需要你的奴隸餵養另一個Redis實例,但只是允許應用程序在另一個從實例數據庫中執行讀/寫操作。

要允許它,你需要設置奴隸只讀參數的值,以對從配置「不」:

# You can configure a slave instance to accept writes or not. Writing against 
# a slave instance may be useful to store some ephemeral data (because data 
# written on a slave will be easily deleted after resync with the master) but 
# may also cause problems if clients are writing to it because of a 
# misconfiguration. 
# 
# Since Redis 2.6 by default slaves are read-only. 
# 
# Note: read only slaves are not designed to be exposed to untrusted clients 
# on the internet. It's just a protection layer against misuse of the instance. 
# Still a read only slave exports by default all the administrative commands 
# such as CONFIG, DEBUG, and so forth. To a limited extend you can improve 
# security of read only slaves using 'rename-command' to shadow all the 
# administrative/dangerous commands. 
slave-read-only no 

現在,所有的寫操作,你會在這種情況下運行將是短暫。如果主站和從站之間的鏈接丟失,則從站將再次與主站完全同步。您在從站上設置的所有數據將丟失。如果您停止並重新啓動從站,您也將丟失所有臨時數據。

它可能或可能不適合您的需求。

沒有辦法在數據庫級別參數同步(或持久性選項)。你不能告訴Redis同步給定的數據庫,而不是另一個。配置始終適用於實例級別。

相關問題