MongoDB Master-slave copy/replica set/Shard cluster Introduction
The previous article describes the installation of MongoDB, in MongoDB, there are two ways of data redundancy, one is Master-slave mode (master-slave replication), one is Replica sets mode (replica set).
MongoDB has a total of three ways to build the cluster:
Replica set (replica set),
sharding (slice)
master-slaver (Master-slave) "is not recommended to use ... "
among them, the sharding cluster is also the most complex of three clusters.
replica sets can achieve failover compared to master-slave. Very use.
MongoDB does not currently recommend the use of master-slave mode, instead of the replica set mode. A replica set is a relationship that is primarily from one to the other and can be understood as the master.
replica sets refer to copying data, saving multiple copies, and saving the same data on different servers, and automatically switching when a failure occurs. corresponding to the data redundancy, backup, mirroring, read and write separation, high availability and other keywords,
and sharding refers to the processing of large amounts of data, the data is stored separately, different servers hold different data, their data sum is the entire data set. The pursuit is high performance.
in a production environment, typically these two technologies are used in conjunction with a Shard + replica set.
First, talk about MongoDB master-slave replication configuration
Master-slave replication is the most common way to copy MongoDB, but also a simple database synchronous backup of the cluster technology, this method is very flexible. Can be used for backup, fault recovery, read extension, etc. The most basic way to set up is to establish a master node and one or more slave nodes, each from the node to know the address of the master node. The use of dual-machine backup of the main node after hanging off the node can take over the host to continue service. So this mode is much better than the high availability of a single node.
Configuring the attention point for master-slave replication
1) in the database cluster to clearly know who is the primary server, the primary server only one.
2) from the server to know its own data source is the corresponding master service is who.
3)--master is used to determine the primary server,--slave and--source to control the slave server
You can specify the master-slave relationship in the mongodb.conf configuration file, so that when you start MongoDB, as long as you follow the configuration file, you do not need to--master and--slave to indicate the master-slave.
Below is a simple record of the deployment process for MongoDB master-slave replication
1) Machine Environment 182.48.115.238 Master-node 182.48.115.236 slave-node two machines all shut down firewall and SELinux MongoDB installation reference: http://www.cnblogs.com/
Kevingrace/p/5752382.html 2) Master-slave configuration .... master-node node configuration ..... ......... [Root@master-node ~]# vim/usr/local/mongodb/mongodb.conf port=27017 bind_ip = 182.48.115.238 dbpath=/usr/local/ Mongodb/data logpath=/usr/local/mongodb/log/mongo.log logappend=true Journal = True fork = True master = TRUE//determined from is the primary server [Root@master-node ~]# nohup/usr/local/mongodb/bin/mongod--config/usr/local/mongodb/mongodb.conf & [ Root@master-node ~]# ps-ef|grep MongoDB root 15707 15514 16:45 pts/2 00:00:00/usr/local/mongodb/bin/mongod--c onfig/usr/local/mongodb/mongodb.conf root 15736 15514 0 16:45 pts/2 00:00:00 grep mongodb [Root@master-node ~]# L sof-i:27017 COMMAND PID USER FD TYPE DEVICE size/off NODE NAME mongod 15707 root 7u IPv4 153114 0t0 TCP 182.48.115.238:27017 (LISTEN) because mongodb.conf bound the IP address of the machine 182.48.115.238, so when you connect MongoDB mustWith this IP address, you cannot use the default 127.0.0.1, which means: [Root@master-node ~]# MONGO 182.48.115.238:27017//In order to connect MongoDB [Root@master-node ~]#
MONGO or MongoDB 127.0.0.1:27017//This can not be connected to MongoDB .... slave-node node configuration ... and so on ...... [Root@slave-node ~]# vim/usr/local/mongodb/mongodb.conf port=27017 dbpath=/usr/local/mongodb/data logpath=/usr/ Local/mongodb/log/mongo.log logappend=true Journal = True Fork = True bind_ip = 182.48.115.236//Determine primary database port SOURC E = 182.48.115.238:27017//Determine the primary database port slave = TRUE//Determine that you are from the server [Root@slave-node ~]# Nohup/usr/local/mon Godb/bin/mongod--config/usr/local/mongodb/mongodb.conf & [Root@slave-node ~]# ps-ef|grep MONGO root 26290 2612 6 8 16:47 pts/