Redis DB Master Slave设置完毕

时间:2013-04-20 08:09:23

标签: redis master slave

我已经为我的nodeJS应用程序安装了Redis,并将其配置为另一台运行在不同服务器上的Redis DB实例的从属设备。我可以让Redis(作为slave运行)的相同实例(不同的DB)充当本地安装的应用程序的Master吗?

提前致谢

1 个答案:

答案 0 :(得分:4)

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

任何从属实例都可以是一个或多个其他实例的主服务器。因此,您可以想象菊花链从属并构建分层复制系统。

现在,我的理解是您不需要您的slave来提供另一个Redis实例,而只是允许应用程序在从属实例的另一个数据库中执行读/写操作。

要允许它,您需要在slave配置中将slave-read-only参数的值设置为“no”:

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