迁移服务器而不丢失任何数据且不停机的最佳方法(?)
这是一个自由职业者提出的方法论问题,其推论是关于 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我会制作一个抱歉页面,将其放在旧服务器上,将所有数据传输到新服务器,然后切换 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.
我喜欢做的是关闭站点并开始使用以下命令将数据库移动到其他服务器: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.
最长的停机时间来自 DNS 切换 - 可能需要几个小时甚至几天的时间,直到所有客户端缓存都过期。
为了避免这种情况:
slave
可以实现最短的停机时间,在幕后它只是动态地从主服务器下载 binlog,您将节省传输数据的时间。整个日志,很可能在最小负载期间,从站将仅落后主站几秒钟,并且一旦应用程序被关闭,很快就会赶上,请参阅如何强制从站赶上。此外,如果您使用文件上传到本地文件系统 - 这些也需要同步,并且在很多文件上这比数据库更痛苦,因为即使 rsync 扫描更改也可能需要很多时间。
The longest downtime is from DNS switch - can take several hours and even days till all clients caches are expired.
To avoid it:
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.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.
查看 MySQL 二进制日志。
Check out the MySQL binary log.
当然。在源服务器上启用 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.