迁移服务器而不丢失任何数据且不停机的最佳方法(?)

发布于 2024-09-04 07:48:41 字数 242 浏览 5 评论 0原文

这是一个自由职业者提出的方法论问题,其推论是关于 MySQL 的。有没有一种方法可以从旧的专用服务器迁移到新的服务器,而不会在中间丢失任何数据,并且不会造成停机?在过去,我不得不在新服务器启动(即所有文件传输,系统启动并准备就绪)和旧服务器关闭(数据仍然传输到旧服务器直到新服务器)之间丢失MySQL数据。一个人接管)。还有一小段时间,两者都会关闭,以便 DNS 等刷新。

MySQL/root 有没有办法轻松传输在特定时间范围内更新/插入的所有数据?

This is a methodology question from a freelancer, with a corollary on MySQL.. Is there a way to migrate from an old dedicated server to a new one without losing any data in-between - and with no downtime? In the past, I've had to lose MySQL data between the time when the new server goes up (i.e., all files transferred, system up and ready), and when I take the old server down (data still transferred to old until new one takes over). There is also a short period where both are down for DNS, etc., to refresh.

Is there a way for MySQL/root to easily transfer all data that was updated/inserted between a certain time frame?

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

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

发布评论

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

评论(5

ζ澈沫 2024-09-11 07:48:41

我会制作一个抱歉页面,将其放在旧服务器上,将所有数据传输到新服务器,然后切换 DNS。虽然会有停机时间。

I'd make a sorry page, put it up on the old server, transfer all data to the new one and then switch DNS. Though there will be a downtime.

眼睛会笑 2024-09-11 07:48:41

我喜欢做的是关闭站点并开始使用以下命令将数据库移动到其他服务器:2,然后将所有文件(php ..etc)移动到其他服务器(如果您有一些存储数据或每小时更改文件,例如图像上传)。并将旧服务器指向新的数据库服务器,同时 DNS 更改为全部到新服务器。

What I like to do is close the site and starting to move DB to other server using these commands: 2, then move all files (php ..etc) to the other server (if you have some store data or change files every hour, like image upload). and point the old server to the new DB server while the DNS is changing to all to the new server.

寄人书 2024-09-11 07:48:41

最长的停机时间来自 DNS 切换 - 可能需要几个小时甚至几天的时间,直到所有客户端缓存都过期。

为了避免这种情况:

  1. 在新服务器上设置应用程序来访问旧服务器上的数据库,或者只是使用 nginx 将 http 请求代理到旧服务器,具体取决于更可接受的方式。
  2. 然后进行 DNS 切换,一些客户端转到 ld 服务器,一些客户端转到新服务器,在这里您可以等待 24+ 小时以确保所有请求都转到新服务器,
  3. 同时 DNS 切换 - 排练 mysql 转换。
    • 制作一个“抱歉/维护页面”,有很多指南如何使用重写来做到这一点。无论如何你都会需要它
    • 如果时间可以接受,测量转储-传输-恢复数据库的速度 - 这是最简单的,但请记住留出一些余量
    • 如果之前的速度太慢 - 您可以尝试之前答案中建议的 binlog 方法
    • 通过使新服务器成为旧服务器的 mysql slave 可以实现最短的停机时间,在幕后它只是动态地从主服务器下载 binlog,您将节省传输数据的时间。整个日志,很可能在最小负载期间,从站将仅落后主站几秒钟,并且一旦应用程序被关闭,很快就会赶上,请参阅如何强制从站赶上
  4. 编写一个脚本,为您完成所有转换 - 启用维护模式,锁定主数据库,等待从属设备赶上,使从属设备成为新的主设备,用新数据库替换应用程序配置,禁用维护,切换应用程序等。这样您可以节省时间在自己输入命令时,在临时环境上进行测试以避免可能的错误(还记得设置更大的 mysql 超时,以防万一从属设备落后很多)
  5. 这里通过运行上一步中的脚本来进行转换本身

此外,如果您使用文件上传到本地文件系统 - 这些也需要同步,并且在很多文件上这比数据库更痛苦,因为即使 rsync 扫描更改也可能需要很多时间。

The longest downtime is from DNS switch - can take several hours and even days till all clients caches are expired.

To avoid it:

  1. set up application on new server to access DB on old one, or just proxy http requests with nginx to the old one, depending on what is more acceptable.
  2. then goes DNS switch, some clients go to ld server, some to new, here you can wait for 24+ hours to make sure all requests go to new server
  3. While DNS switches - rehearse mysql transition.
    • make a 'sorry/maintanance page', there're plenty of guides how to do that usung rewrites. You'll need it anyway
    • measure how fast you can dump-transfer-restore db, if time is acceptable - this is the simplest, but remember to give some margin
    • if previous is too slow - you can try binlog method suggested in previos answer
    • minimal downtime can be achieved by making new server a mysql slave to the old one, under the hood it is just downloads binlog from master on-the-fly and you will save time on transferring the whole log, most probably during minimal load slave will be just several seconds behind master and catch up very quickly once app is taken down, see how to force slave to catch up.
  4. Write a script, that does all transition for you - enables maintenance mode, locks master db, waits till slave catches up, makes slave a new master, replaces app config with new db, disables maintenance, switches app etc. This way you save time on typing commands youself, test on staging environment to avoid possible errors (also remember to set larger mysql timeout, just in case slave is a lot behind)
  5. here goes the transition itself, by running script from previous step

Also if you use file uploads to a local filesystem - these need to be synced too and on lots of files this is more pain than with db, because even rsync scan for changes can take a lot of time.

阳光的暖冬 2024-09-11 07:48:41

当然。在源服务器上启用 bin 日志记录。启动后,进行数据库转储并将其传输到新服务器并导入。然后,当您准备好进行切换时,更改 DNS(让更改在您工作时传播),然后在两台服务器上关闭该站点。将二进制日志复制到新服务器,并从转储的日期/时间开始再次运行它们。

Sure. Enable bin logging on the source server. After that is started, make a DB dump and transfer it to the new server and import it. Then, when you're ready to make the switch, change DNS (let the change propagate while you're working), then take the site down on both servers. Copy the binlogs to the new server and run them again starting at the date/time of the dump.

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