PHP/PDO MariaDB Galera群集 [英] PHP/PDO MariaDB Galera Cluster

查看:66
本文介绍了PHP/PDO MariaDB Galera群集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正处于配置可从四个全局位置访问的服务的最后阶段(计划以后再添加).我将在带有MariaDB的Ubuntu 12.04机器上运行服务器.我最初的想法是创建具有4个不同数据库且彼此独立运行的服务器,并以用户只能登录到最初注册服务器的约束为条件.

I am in the final stages of configuring a service that is accessible from four global locations (with plans to add more later). I will be running the servers on an Ubuntu 12.04 box with MariaDB. My initial thought was to create servers that run independently of each other with 4 distinct databases and live with the constraint that users would only be able to login to the server where they were initially registered.

但是,我刚遇到

However, I have just run into this article that has got me thinking... .

如果我按照文章中的建议设置了具有主-主复制功能的Galera集群,那么我的阅读可以使我拥有一个大型数据库的奢侈感,该数据库在所有四台服务器上始终可用.我已经收集(并希望)集群设置正确且运行良好,我不需要在PHP代码中做任何事情(四个MariaDB实例将具有相同的用户访问数据库)-甚至不更改PDO连接字符串

From my reading of things if I set up a Galera cluster with master-master replication as suggested in the article I can move have the luxury of one large database that is consistently available across all four servers. I have gathered (and am hoping) that with the cluster setup correctly and functioning well I need do pretty much nothing in my PHP code (the four MariaDB instances will have the same user to access the database) - not even alter the PDO connection string.

但是,这听起来太好了,难以置信.我的问题是:

However, this sounds almost too good to be true. My questions are:

  • are there other issues involved here that make for complications?
  • Do the PHP PDO connection strings need to be altered in anway?
  • Does the fact that my application is already structured to ensure that there is absolutely zero chance of two servers attempting to simultaneously write the same row help?
  • And finally, reading from the MariaDB docs, that this will not work with the TokuDB storage engine?
  • Is there a way to specifically stop the replication of a selected table? Could I in fact exploit the "only InnoDB/XtraDB" constraint and use another storage engine on the table I do not want to have replicated?

推荐答案

这里还涉及其他导致复杂化的问题吗?

are there other issues involved here that make for complications?

您应该有一些已知限制意识到.通常,对于群集,理想情况下,应该有奇数个节点以防止脑部分裂,但是偶数个节点通常也一样.

There are some Known Limitations that you should be aware of. Generally, with clusters, you should ideally have an odd number of nodes to prevent split brain conditions, but an even number will usually work just as well.

是否需要随意更改PHP PDO连接字符串?

Do the PHP PDO connection strings need to be altered in anway?

不.您现有的连接字符串应该可以使用.

No. Your existing connection strings should work.

我的应用程序已经结构化以确保两台服务器尝试同时编写同一行帮助的可能性绝对为零吗?

Does the fact that my application is already structured to ensure that there is absolutely zero chance of two servers attempting to simultaneously write the same row help?

查看已知限制,并确保您的应用程序仍会执行该操作.如果您使用的是命名锁,则需要更改您的应用程序.

Look at the known limitations and make sure your application will still do that. If you're using named locks, you'll need to change your application.

最后,从MariaDB文档中读取到的信息,这是否不适用于TokuDB存储引擎?

And finally, reading from the MariaDB docs, that this will not work with the TokuDB storage engine?

在最近的galera群集发行版中添加了对TokuDB的支持.我已经使用了一些,并且它确实像InnoDB一样进行复制,但是由于它是galera集群构建中的新功能,因此我不会依赖它.

TokuDB support was added in the recent galera cluster distribution. I have used some and it does replicate just like InnoDB but I wouldn't rely on it since it's new in the galera cluster build.

有没有一种方法可以专门停止所选表的复制?实际上,我可以利用仅InnoDB/XtraDB"约束并在我不想复制的表上使用另一个存储引擎吗?

Is there a way to specifically stop the replication of a selected table? Could I in fact exploit the "only InnoDB/XtraDB" constraint and use another storage engine on the table I do not want to have replicated?

我听说很多人问他们是否可以从复制中省略表或数据库,但是我仍然没有听到一个很好的理由. Galera复制提供HA,并且便宜又容易,因此即使某些表并不重要,我也找不到任何不复制数据的现实原因.话虽如此,使用MyISAM/Aria可能无法复制数据.

I've heard a lot of people ask if they can omit tables or databases from replication but I still haven't heard a good reason why. Galera replication provides HA and is cheap and easy so even if some tables aren't important I can't find any realistic reason to not replicate the data. That being said, you could have data not replicated by using MyISAM/Aria.

我已经在多个中等规模的项目中将galera与MariaDB结合使用,这是我发现的针对HA的最佳解决方案,并且还提供了性能优势.其他解决方案通常价格昂贵或不成熟.您应该考虑的一件事是设置代理以连接到数据库服务器,例如HA Proxy,mysql-proxy或glbd(我使用它们),以提供更好的冗余和连接平衡以提高性能.

I've been using MariaDB with galera in multiple moderately sized projects and it is the best solution I've found for HA and it also provides performance benefits. Other solutions are generally expensive or not mature. One thing you should consider is setting up a proxy for connecting to the database servers like HA Proxy, mysql-proxy, or glbd (which I use) to provide better redundancy and connection balancing for performance.

回应下面的DroidOS评论:

In response to DroidOS's comment below:

  1. 集群中的每个写入都需要每个节点都同意,因此节点之间的任何延迟都将添加到每个写入中.因此,基本上,每次写入将在写入服务器和添加到其中的其他节点之间具有最大的往返时间.

  1. Every write in the cluster needs to be agreed upon by every node so any latency between nodes is added to every write. So, basically, every write will have the greatest round trip time between the writing server and the other nodes added to it.

否. Galera复制是整个群集中的全部或全部.如果任何节点在写入数据时遇到问题(如果表没有主键,则可能会发生这种情况),因为该节点不能保证其数据与群集的其余部分一致,因此会自动终止自身.如果发生这种情况,群集的其余部分将继续正常运行.如果存在网络问题,如果其中一个网段达到了法定人数,它将继续正常运行.任何没有仲裁的段将等待更多的节点获得仲裁,但不接受查询.通过这种行为,您可以确保能够查询的任何节点都与集群的其余部分保持一致.

No. Galera replication is all or nothing across the entire cluster. If any node has a problem writing the data, which can happen if a table doesn't have a primary key, the node will gracefully kill itself since it can't guarantee its data is consistent with the rest of the cluster. If that happens, the rest of the cluster will continue to operate normally. If there is a network issue, if one of the segments has quorum, it will continue to operate normally. Any segments without quorum will wait for more nodes to get quorum but will not accept queries. With this behavior, you can be sure that any node that you are able to query is consistent with the rest of the cluster.

这篇关于PHP/PDO MariaDB Galera群集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆