Common practice would be to set up something like ldirectord in front of your mysql cluster to provide a virtual ip as a load balanced address for the cluster, this could then distribute your queries to the various mysql servers.
This would require ipvs routing which may/may not be overkill for your specific situation, it may be that php control of the load balancing would be appropriate for what you are trying to achieve.
Should this query go to a slave, or the master db?
This logic should probably be in PHP. There are often cases where you must have the absolute freshest data, which can't be had from a slave. For example, if a user alters a page, you need to build the updated page from the master db -- the user's changes may have not made it to the slave dbs yet. This is very application-specific, so 3rd party tools may not be able to do this for you.
Which slave should this query go to?
This, you probably don't need to write yourself -- it's not really important to your application which specific slave handles a request. Existing tools should handle this well.
发布评论
评论(2)
常见的做法是在 mysql 集群前面设置类似 ldirectord 的东西,以提供虚拟 ip 作为集群的负载平衡地址,然后这可以将您的查询分发到各个 mysql 服务器。
这将需要 ipvs 路由,这对于您的具体情况可能/可能不会太过分,负载平衡的 php 控制可能适合您想要实现的目标。
Common practice would be to set up something like ldirectord in front of your mysql cluster to provide a virtual ip as a load balanced address for the cluster, this could then distribute your queries to the various mysql servers.
This would require ipvs routing which may/may not be overkill for your specific situation, it may be that php control of the load balancing would be appropriate for what you are trying to achieve.
是和不是。
实际上有两个问题需要回答:
Yes and no.
There are really two questions to be answered: