线上的实际情况是总共有4台服务器。现在主要用的是memcache
,并且目前只用了61M左右的内存空间。公司的需求是逐步把整个网站的缓存迁移到redis。
目前的想法是拿3台服务器拿来做集群,每台服务器配置一个Master实例。为了实现高可用,还需要给每台服务器配置一个Slave实例。我想问的是,可不可以将Master实例和Slave实例配置到一个主机当中,以及这样配置所带来的影响?
还有一种想法是,只用2台服务器,1台服务器运行3个Master实例,另一台服务器运行3个Slave实例。大家还有更好的解决方案吗?
还听他们说,集群的话至少要有3个主节点。用2个主节点不行吗?
If you put master and slave on the same machine, there will be problems:
Both master and slave need to occupy memory when running, and the machine's memory may not be enough
If the machine goes down, is powered off, or the network is disconnected, then there is no high availability for the master and slave.
It is best to put master and slave on different machines.
As for why it is 3 instead of 2. This is the best strategy during cluster elections. Redis3.0 starts to support clusters.
Generally, for a cluster to reach a consensus on a certain public state, more than half of the redis instances in the cluster need to agree.
Why do we need a majority? Because we need to consider the situation of split-brain in the cluster, that is, network-partition.
A majority can guarantee that no matter how the network is isolated, no matter how the brain is split, no matter how large the The cluster is isolated into several small clusters. In the small cluster that can provide services (meaning that there are more than half of the instances), at least one instance is synchronized to the latest status information.
Understand the above mentioned majority, and then have the background to talk about why it is an odd number
Even numbers can also have a majority. For example, in a cluster of 4 instances, 3 is a majority.
But why is odd number still the best?
If the cluster has 5 instances, it can only tolerate the crash of 2 instances.
If there are 6 instances in the cluster, it can only tolerate the crash of 2 instances.
With the same tolerance, what is the difference between 6 and 5:
Since clusters need to communicate with each other, the more instances, the greater the network overhead
The more instances there are, when there are 5 instances, the probability of crash of 3 instances is less than when there are 6 instances.
So of course the odd number is the most cost-effective.
It’s possible, just set different ports. As for the impact, I don’t think it has any special impact.
If there are 3 machines, each will run a master, and then put their respective slaves on different machines to form a ring backup, instead of putting eggs in one basket.
If you have enough IP resources, find a ha middleware to implement high availability.
It is not recommended to put the production environment on the same physical machine. The cluster with 3 masters is talking about a 3.0 cluster. An odd number of nodes ensures that the voting can produce a certain result
Well, then put the Slave somewhere else.
What do you think of this design?