简体   繁体   English

动态ip上的mysql数据库多主复制

[英]mysql database Multi-master replication on dynamic ip

Situation: 情况:

Php application with mysql database running on 2 sites 在2个站点上运行MySQL数据库的PHP应用程序

  1. online -static ip XXXX 在线-静态ip XXXX
  2. localhost (not online most of time and dynamic ip) 本地主机(大多数时间和动态ip都不在线)

application traffic is usually low <10 users. 应用程序流量通常低于10个用户。

what i need is that whenever a change is done to the online database, this change is pushed to localhost -if its online or when ever its available- and vise versa (any changes done locally is uploaded online to database when ever there is online connection). 我需要的是,每当对联机数据库进行更改时,都会将该更改推送到localhost-如果它是联机的,或者它可用时,并且反之亦然(当存在联机连接时,本地所做的任何更改都会在线上传到数据库) )。

is it possible to setup such replication by mysql ? 有可能通过mysql设置这种复制吗? or do i need to write a custom PHP that ping master server and once its available 还是我需要编写自定义的ping主服务器的PHP,一旦可用

thanks very much :). 非常感谢 :)。

Yes you can do this with replication. 是的,您可以通过复制进行此操作。 Just pick which server you want to be the master and have the second one send all of its changes to the main one then the main one could send its changes back. 只需选择您要成为主服务器的服务器,然后让第二台服务器将其所有更改发送到主服务器,然后主服务器就可以将其更改发送回去。

Replication can be a bit daunting to set up but once its up and running its grate. 复制设置起来可能有些艰巨,但是一旦启动并运行它的炉排。 http://dev.mysql.com/doc/refman/5.0/en/replication-howto.html http://dev.mysql.com/doc/refman/5.0/en/replication-howto.html

Let's first analyze your question: 让我们首先分析您的问题:

  1. The problem of accessing MySQL with a dynamic ip . 使用动态ip访问MySQL的问题。 This is very easy. 这很容易。 Once you installed MySQL on a server with an ever-changing IP, what you can do is go to NO-IP, DynDNS or any other Dynamic DNS service and register for free with them. 在IP不断变化的服务器上安装MySQL之后,您可以执行NO-IP,DynDNS或任何其他动态DNS服务,并免费向其注册。 Once you've registered with them, you would get a client for your operating system. 向他们注册后,您将获得操作系统的客户端。 Install that and then you can access your MySQL server using a domain name. 安装它,然后您可以使用域名访问MySQL服务器。

    Example: Instead of having to access your server at 127.0.0.1, you can access it as mysql-server.easynet.net etc. 示例:您不必以127.0.0.1访问服务器,而可以以mysql-server.easynet.net等访问它。

  2. Now the second and albeit complex part of your question, how to do available and lazy replication. 现在是问题的第二个也是最复杂的部分,即如何进行可用和延迟复制。 This is relatively a bit more complex than the previous step. 这比上一步要复杂一些。 But, what actually happens is that you have to choose a scheme of replication . 但是,实际上发生的是您必须选择复制方案 Basically what you are looking for here is MASTER-MASTER replication since you have a possibility of changes happening at both the MySQL servers. 基本上,您在这里寻找的是MASTER-MASTER复制,因为您有可能两个 MySQL服务器上进行更改。 Thus the updates need to be bi-directional , that's what this scheme of replication does. 因此,更新必须是双向的 ,这就是此复制方案所做的。 How to do it? 怎么做? Well, I am providing the links which I've found easier to follow: 好吧,我提供的链接更容易理解:

Master-Master Replication 主-主复制

Step-by-step MySQL Master Replication 分步MySQL主复制

I hope that would ease your plight and answer your question! 我希望这可以缓解您的困境并回答您的问题! Cheers! 干杯!

Sure, you can 你当然可以
You need to setup both MySQL servers as Master and Slave at the same time. 您需要同时将两个MySQL服务器设置为主服务器和从服务器。
Configure the online server as Master, and the localhost server as slave, and once replication is OK. 将在线服务器配置为主服务器,将本地服务器配置为从服务器,一旦复制确定即可。
Configure the localhost as Master and the online server as slave. 将localhost配置为主服务器,将在线服务器配置为从服务器。
I already did that on two servers. 我已经在两台服务器上做到了。

About the dynamic IP on the local host, simply you can use any dynamic IP service like: no-ip, and use the dns name instead of the IP. 关于本地主机上的动态IP,只需使用任何动态IP服务即可,例如:no-ip,并使用dns名称代替IP。

这是我写的一篇文章 (法文,但您可以从中获得配置摘要),用于使用负载平衡器(mysql代理)设置MASTER-MASTER复制,以平衡两个节点之间的SQL查询。

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

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