2013-04-20 77 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同步给定的数据库,而不是另一个。配置始终适用于实例级别。

相关问题