Related database master-slave and cluster methods

Relevant database master-slave and cluster methods
memcached can use magent for master-slave synchronization and fragmented storage (cluster function)
http://blog.sina.com.cn/s/blog_80413dd90102vbxa.html
1. If it is a set operation, it will also At the same time, write a copy to the backup memcached, such as 127.0.0.1:11411 in the third step. If there are multiple backup databases, the load will be balanced.
2. If it is a read operation, first determine whether the memcached specified by the hash algorithm is not It works normally. If it is normal, read the data of this library. If it is not normal, read the data of the backup library.
3. If a main library is down, the read key is on this machine, and then it will be downloaded from The backup database reads, if the machine recovers from the crash, even if the data of this key exists in the backup database, it will not be read, but will only read null from the main database.

When running the magent command, specify which are slaves and which are the master.


Redis
Redis periodically writes updated data to disk or writes modification operations to additional record files, and implements master-slave (master-slave) synchronization on this basis.
Redis can be configured as master and slave. From time to time, specify the master's IP and password in the configuration file.
Redis' master-slave replication function is very powerful. A master can have multiple slaves, and a slave can have multiple slaves. In this way, a powerful multi-level server is formed cluster architecture.

The process of master-slave replication
When the slave server is set up, the slave will establish a connection with the master, and then send the sync command. Whether it is the connection established by the first synchronization or the reconnection after the connection is disconnected, the master will start a background process to save the database snapshot to the file, and the master process will start to collect new write commands and cache them. After the background process finishes writing the file, the master sends the file to the slave, and the slave saves the file to disk, and then loads it into the memory to restore the database snapshot to the slave. The master will then forward the cached command to the slave. And subsequent write commands received by the master will be sent to the slave through the connection established. Commands to synchronize data from master to slave use the same protocol format as commands sent from client. When the connection between the master and the slave is disconnected, the slave can automatically re-establish the connection. If the master receives synchronous connection commands from multiple slaves at the same time, it will only start a process to write database mirroring, and then send it to all slaves.

Sharding is done through cluster (which hash slot this key should be distributed to is calculated according to crc16(key) mod 16384).

After the master node goes down, the slave node will temporarily serve as the master node to take over the work of the master node, but not always can replace. When the following two situations occur, it can be considered that Redis-Cluster has been down:
1. If the current master node does not have a slave node after the master node in the cluster is down, the cluster enters the down state, that is, the slot mapping of the cluster unsuccessful. (If there is a master node that cannot work, it will not work.)
2. If more than half of the master nodes in the cluster are down, regardless of whether there are slave nodes, the cluster will be in a down state.


sentinel is used to make the slave become the master after Redis is down for the master

http://blog.csdn.net/sk199048/article/details/50725369
http://www.cnblogs.com/liuling/p/2014-4-19-02.html
http://blog.csdn.net/xu470438000/article/details/42971091
(Redis cluster_3.redis master-slave automatic Switch Sentinel) http://www.2cto.com/database/201502/377061.html
(cluster deployment of redis 3.0) http://blog.csdn.net/myrainblues/article/details/25881535/ Replication of

MySQL
Mysql is An asynchronous replication process that replicates from one MySQL node (called the Master) to another MySQL node (called the Slave).
To implement MySQL Replication, you must first open the Binary Log on the Master side, because the entire replication process is actually the Slave getting the log from the Master side and then executing the various operations recorded in the log in complete order on itself.

The replication principle of MySQL is very simple. To sum up:
only one master can be set for each slave.
After executing sql, the master records the binary log file (bin-log).
Connect to the master from the master, and obtain the binlog from the master, store it in the local relay-log, and execute the sql from the last remembered position, and stop the synchronization once an error is encountered.

MysqlCluster can be clustered. The master-slave synchronization in the Mysqlcluster data node group adopts synchronous replication to ensure the consistency of node data in the group.


() http://blog.csdn.net/yangzhenzhen/article/details/8512292
(MySQL cluster) http://blog.csdn.net/chenxingzhen001/article/details/7708663

(two-phase commit protocol) final commit phase It will be extremely time-consuming, and the extremely short time-consuming means that the possibility of failure of the operation is reduced.



The mongoDb
master node records all operations oplogs on it, and the slave node periodically polls the master node to obtain these operations, and then performs these operations on its own data copy to ensure that the slave node's data is consistent with the master node. (Asynchronous replication process)
mongoDb can be configured as master and slave, and the IP

replication cluster ReplicateSet mode of the host needs to be configured from time to time (introduce an arbitration node, the arbitration node does not store data. In this way, the ability of the slave to become the master after the master is down is achieved. )

Replica Set ensures high availability, data shards (Shards) expand capacity

(conquer Mongodb's master-slave replication & cluster replication) http://snowolf.iteye.com/blog/1974747
(Three ways to build a Mongodb cluster) http: //blog.csdn.net/luonanqin/article/details/8497860
(solution for high availability cluster) http://www.open-open.com/lib/view/open1476329503902.html


If you want to achieve high availability, you can use keepalived software. (to prevent single point of failure)

If the security needs to be counted, the data must be successfully written to multiple database nodes before the data is considered valid, but this affects performance and user experience.

The master-slave synchronization in the data node group adopts synchronous replication to ensure data security.

Data security can be backed up and the log is placed on another server to ensure data security, because the data is written to the database first. The log is written.


Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326686026&siteId=291194637