简体   繁体   English

将二进制日志文件推送到MySQL从站

[英]Pushing binary log files to MySQL slave

I am using MySQL to store log data from a number of sensors on-board a boat, and would like to replicate that database to a read only instance of MySQL on a web server. 我正在使用MySQL存储来自船上多个传感器的日志数据,并希望将该数据库复制到Web服务器上的MySQL只读实例。

The web server has a static ip, but the log server will have a dynamic ip address from behind different routers depending where the boat is. Web服务器具有静态ip,但是日志服务器将从船尾的不同路由器后面获得动态ip地址。

As far as I can understand from reading around, binary log files are usually requested by a slave from the master, which is not feasible in my application. 据我阅读所了解,二进制日志文件通常由主服务器的从属服务器请求,这在我的应用程序中不可行。

Is it possible to 'push' binary log files to a remote slave to achieve updates for the read only MySQL database? 是否可以将二进制日志文件“推送”到远程从站以实现对只读MySQL数据库的更新?

Any pointers other than using MySQL dump files with scripts would be much appreciated. 除了将MySQL转储文件与脚本一起使用以外,任何其他指针都将不胜感激。

Unfortunately MySQL replication depends on IP address of the master. 不幸的是,MySQL复制取决于主服务器的IP地址。 So if master changes IP address you will get replication error on replica. 因此,如果主服务器更改了IP地址,您将在副本服务器上收到复制错误。 But this is not so bad because MySQL replication is quite robust. 但这还不错,因为MySQL复制非常健壮。

But you must set long enough "expire_logs_days" on your master to make sure you will have all bin logs available even after some longer time without connection - especially if your boat will be long time without internet connection. 但是您必须在主服务器上设置足够长的“ expire_logs_days”,以确保即使在较长时间没有连接后,所有bin日志仍然可用-特别是如果您的船很长时间没有互联网连接。 Of course to store huge amount of bin logs you need to have huge disks - or better disk array to avoid errors. 当然,要存储大量的bin日志,您需要具有大的磁盘-或更好的磁盘阵列以避免错误。

And master must be able run without crashes so there will be no problems with the continuity of bin logs on master. 而且主服务器必须能够运行而不会崩溃,因此主服务器上bin日志的连续性不会有问题。

Maybe you will find some inspiration in following possibilities: 也许您会从以下可能性中找到灵感:

Scenario 1 - try to use VPN 方案1-尝试使用VPN

I am not network guru but you could try to use VPN from your master on boat to replica using OpenVPN or ZeroTier or something similar using other internet server with static address which will be accessible for both machines. 我不是网络专家,但是您可以尝试使用OpenVPN或ZeroTier或其他类似的具有静态地址的Internet服务器从船上的主人使用VPN复制到两台机器上。 This way you will create your virtual network and will address master with IP in this VPN. 这样,您将创建您的虚拟网络,并将在此VPN中使用IP寻址主服务器。 May probably require to repeatedly modify VPN from your master when it moves and changes its dynamic IP. 可能需要在主服务器移动和更改其动态IP时反复修改其主人的VPN。

Scenario 2 - change IP of master on replica when necessary: 方案2-必要时更改副本服务器上主服务器的IP:

I am not network guru but let's presume new dynamic IP of your master will last long enough and master will be accessible under this IP from outside using standard internet communication. 我不是网络专家,但是我们假设您的主服务器的新动态IP将持续足够长的时间,并且可以使用标准Internet通信从外部在该IP地址下访问主服务器。 And either replica will be able to find new IP or you can send new IP of master to the replica to some listener or web service. 并且副本将能够找到新的IP,或者您可以将新的主IP发送给副本到某个侦听器或Web服务。 If so then every time IP changes and you get replication error on replica you can simply use following commands on replica: 如果是这样,那么每次IP更改并且您在副本上遇到复制错误时,只需在副本上使用以下命令即可:

STOP SLAVE; CHANGE MASTER TO MASTER_HOST='xxx.xxx.xxx.xxx'; START SLAVE;

This works because replica knows which last position in bin log was successfully applied. 之所以可行,是因为副本知道bin日志中的最后一个位置已成功应用。 So when you change only master IP and start replication again, replica will simply continue. 因此,当您仅更改主IP并再次开始复制时,复制将继续。

Of course if master will not be accessible under some dynamic IP from outside then replica will not able to contact it... 当然,如果无法从外部使用某些动态IP访问master,则副本将无法与其联系...

Scenario 3 - batch shipment of datafiles 方案3-批量装运数据文件

If you will not be able to open VPN or access MySQL master on the boat from outside or ensure internet connection lasting long enough or use disks big enough for all archived bin logs you can always do hot backups on running master using Percona XtraBackup. 如果您将无法从外部打开VPN或从船上访问MySQL主机,或者无法确保互联网连接持续足够长的时间,或者无法使用足够大的磁盘存储所有已归档的bin日志,则始终可以使用Percona XtraBackup在运行的主机上进行热备份。

This tool makes consistent backup of all datafiles with applying of all changes made during the backup. 该工具通过应用备份过程中所做的所有更改来对所有数据文件进行一致的备份。 You can tar and gzip it and send to some cloud storage. 您可以对其进行tar和gzip压缩,然后发送到一些云存储中。 This way you will not lose any data and will have really consistent backup. 这样,您将不会丢失任何数据,并且将拥有真正一致的备份。

Advantage of this solution is - on target machine you simply stop mysql, delete existing old data files, untar/unzip new datafiles and start mysql and here we go. 此解决方案的优点是-在目标计算机上,您只需停止mysql,删除现有的旧数据文件,解压缩/解压缩新数据文件并启动mysql,然后开始操作。 No need to make usually very time consuming restore of the dump file. 通常无需进行非常耗时的转储文件还原。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM