Overview
The MONGODB environment mainly includes standalone,replication and sharding. StandAlone: Stand-alone environment, the general development of the test when used. Replication: Master-slave structure, a primary, multiple secondary, there may be arbitry.
After the primary is hung up, a secondary will be elected as primary, similar to zookeeper. Arbitry does not save data, just for dine. The election algorithm requires that the number of nodes must be odd number, if primary+secondary is not an odd number, it is necessary to use Arbitry dine. Write data can only be primary, read the data by default also in primary, can be configured to read from secondary, you can select the nearest node. After the data is written successfully on the primary, the action is recorded in the Oplog, the secondary copies the Oplog, and then the data is done. Primary and secondary the data above guarantee final consistency, you can configure write concern for writes, there are several levels: write on primary to think that writing is successful, write to the oplog after writing success; write to one/more/one/ After a few secondary think write success, and so on. Sharding:share the structure of nothing, with only a fraction of the data per machine. Mongod Server storage data, MONGOs server is responsible for routing read and write requests, the metadata exists in the config database.
Because of the amount of data and the number of machines, the project ended up with a primary, a secondary, a arbitry. My own development environment is Ubuntu, and the test environment is CentOS. The 64-bit MongoDB is installed. Download, decompression Download mongodb-linux-x86_64-rhel62-3.4.10.tgz.gz decompression:
#解压命令
TAR-XZVF mongodb-linux-x86_64-rhel62-3.4.10.tgz.gz
Create and edit a configuration fileThe configuration files that are MongoDB to create mongod.conf based on the directory are as follows:
#mongod. conf path is: MongoDB extract directory/mongod.conf
Net:
#bindIp: 127.0.0.1
port:27017
systemlog:
Destination:file
Path:/app/mongodata/log/mongo.log
logappend:true
storage: DBPath
:/app/ Mongodata/data
processmanagement:
fork:true
#security:
# authorization:enabled
Replication:
oplogsizemb:1024
replsetname:rs-test
the other three are also configured, and then start each
#启动命令
mongod-f mongod.conf
Initializing clusters
# 1, select a MongoDB service, through the Bin/mongo command for console
Bin/mongo
# 2, switch to admin library use
admin
# 3, define initialization configuration
config={"_id": "Rs-test", "members": [{"_id": 0, "host": "mongodb-node1:27017"}, {"_id": 1, "host": "Mongodb-nod e2:27017 "}, {" _id ": 2," host ":" MONGODB-NODE3:27017 "}]}
# 4, initialize
rs.initiate (config);