Redis数据库主从设置

3

我已经为我的NodeJS应用程序安装了Redis,并将其配置为另一台运行在不同服务器上的Redis数据库的从库。那么,我能否让这个作为从库运行的同一实例(不同的数据库)的Redis充当本地安装的应用程序的主库吗?

提前致谢。

1个回答

4

是的,你可以这样做,但有一个重要限制

任何从属实例都可以成为一个或多个其他实例的主实例。因此,您可以想象将从属实例链接起来建立分层复制系统。

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

为了允许它,您需要在从属配置中将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同步给定的数据库而不是另一个数据库。配置始终应用于实例级别。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接