我已经为我的NodeJS应用程序安装了Redis,并将其配置为另一台运行在不同服务器上的Redis数据库的从库。那么,我能否让这个作为从库运行的同一实例(不同的数据库)的Redis充当本地安装的应用程序的主库吗?
提前致谢。
我已经为我的NodeJS应用程序安装了Redis,并将其配置为另一台运行在不同服务器上的Redis数据库的从库。那么,我能否让这个作为从库运行的同一实例(不同的数据库)的Redis充当本地安装的应用程序的主库吗?
提前致谢。
是的,你可以这样做,但有一个重要限制。
任何从属实例都可以成为一个或多个其他实例的主实例。因此,您可以想象将从属实例链接起来建立分层复制系统。
现在,我的理解是,您不需要让您的从属实例向另一个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