Redis 主/从复制 - 单点故障?

发布于 2024-10-12 23:06:36 字数 116 浏览 2 评论 0原文

如何在零停机的情况下升级到较新版本的 Redis? Redis 从站是只读的,因此您似乎必须关闭主站,并且在您等待它重新加载数据库时,您的站点将处于只读状态 45 秒或更长时间。

有办法解决这个问题吗?

How does one upgrade to a newer version of Redis with zero downtime? Redis slaves are read-only, so it seems like you'd have to take down the master and your site would be read-only for 45 seconds or more while you waited for it to reload the DB.

Is there a way around this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

我不会写诗 2024-10-19 23:06:36

Redis 团队对此

核心步骤有非常好的文档:

  • 将新的 Redis 实例设置为当前 Redis 实例的从属实例。为此,您需要一台不同的服务器,或者一台具有足够 RAM 来保持两个 Redis 实例同时运行的服务器。
  • 如果您使用单个服务器,请确保从属实例在与主实例不同的端口中启动,否则从属实例将根本无法启动。
  • 等待复制初始同步完成(检查从属日志文件)。
  • 使用 INFO 确保主设备和从设备中的密钥数量相同。使用 redis-cli 检查从站是否按您的意愿工作并正在回复您的命令。
  • 配置所有客户端以便使用新实例(即从属实例)。
  • 一旦您确定主站不再接收任何查询(您可以使用 MONITOR 命令检查这一点),请使用 SLAVEOF NO ONE 命令选择从站为主站,然后关闭主站。

完整文档:

无需停机即可升级或重新启动 Redis 实例

Redis Team has very good documentation on this

Core Steps:

  • Setup your new Redis instance as a slave for your current Redis instance. In order to do so you need a different server, or a server that has enough RAM to keep two instances of Redis running at the same time.
  • If you use a single server, make sure that the slave is started in a different port than the master instance, otherwise the slave will not be able to start at all.
  • Wait for the replication initial synchronization to complete (check the slave log file).
  • Make sure using INFO that there are the same number of keys in the master and in the slave. Check with redis-cli that the slave is working as you wish and is replying to your commands.
  • Configure all your clients in order to use the new instance (that is, the slave).
  • Once you are sure that the master is no longer receiving any query (you can check this with the MONITOR command), elect the slave to master using the SLAVEOF NO ONE command, and shut down your master.

Full Documentation:

Upgrading or restarting a Redis instance without downtime

绝不服输 2024-10-19 23:06:36

当节点离线时,使用 SLAVEOF 命令将从节点提升为主节点,然后当你将其重新上线时,将其设置为从节点,它将从在线节点复制所有数据。

您可能还需要确保您的客户端可以适当地处理更改/丢失的主节点。

如果您想真正变得更奇特,您可以设置您的客户端,以便在检测到写入主服务器的错误时升级从服务器。

When taking the node offline, promote the slave to master using the SLAVEOF command, then when you bring it back online you set it up as a slave and it will copy all data from the online node.

You may also need to make sure your client can handle changed/missing master nodes appropriately.

If you want to get really fancy, you can set up your client to promote a slave if it detects an error writing to the master.

っ左 2024-10-19 23:06:36

您可以使用 Redis Sentinel 来执行此操作,哨兵会自动将从站提升为新的主站。
您可以在这里找到更多信息http://redis.io/topics/sentinel

Sentinel是一个用于管理redis服务器的系统,它持续监控redis master和slave,每当master宕机时,它会自动将slave提升为master。当旧主站启动时,它将成为新主站的从站。

这里不会有停机时间或需要手动配置配置文件。
您可以访问上面的链接以了解如何为您的 Redis 服务器配置哨兵。

You can use Redis Sentinel for doing this, the sentinel will automatically promote a slave as new master.
you can find more info here http://redis.io/topics/sentinel.

Sentinel is a system used to manage redis servers , it monitors the redis master and slaves continuously, and whenever a master goes down it will automatically promote a slave in to master. and when the old master is UP it will be made as slave of the new master.

Here there will be no downtime or manual configuration of config file is needed.
You can visit above link to find out how to configure sentinel for your redis servers.

小糖芽 2024-10-19 23:06:36

请注意,您可能需要检查并设置以下配置才能写入您的从站。
(“从 Redis 2.6 开始,默认从站是只读的”)

redis-cli config set slave-read-only no

-- 示例

-bash-4.1$ redis-cli info
 Server
redis_version:2.6.9

-bash-4.1$ redis-cli slaveof admin2.mypersonalsite.com 6379
OK

-bash-4.1$ redis-cli set temp 42
(error) READONLY You can't write against a read only slave.

-bash-4.1$ redis-cli slaveof no one
OK

-bash-4.1$ redis-cli set temp 42
OK

-bash-4.1$ redis-cli get temp
"42"


-bash-4.1$ redis-cli config set slave-read-only no
OK

-bash-4.1$ redis-cli slaveof admin2.mypersonalsite.com 6379
OK

-bash-4.1$ redis-cli set temp 42
OK

-bash-4.1$ redis-cli get temp
"42"

Note, you may have to check and set the following config to write to your slave.
("Since Redis 2.6 by default slaves are read-only")

redis-cli config set slave-read-only no

-- Example

-bash-4.1$ redis-cli info
 Server
redis_version:2.6.9

-bash-4.1$ redis-cli slaveof admin2.mypersonalsite.com 6379
OK

-bash-4.1$ redis-cli set temp 42
(error) READONLY You can't write against a read only slave.

-bash-4.1$ redis-cli slaveof no one
OK

-bash-4.1$ redis-cli set temp 42
OK

-bash-4.1$ redis-cli get temp
"42"


-bash-4.1$ redis-cli config set slave-read-only no
OK

-bash-4.1$ redis-cli slaveof admin2.mypersonalsite.com 6379
OK

-bash-4.1$ redis-cli set temp 42
OK

-bash-4.1$ redis-cli get temp
"42"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文