As the company's business development MSSQL has been in the bottleneck. Because there is no money to buy a big server can only rely on software to achieve maximum optimization. The original system architecture is as follows:
Now you're ready to switch between read and write databases and read-only data into NoSQL databases. MongoDB was eventually selected. The following is the beginning of MongoDB learning.
1. MongoDB Download: https://www.mongodb.org/downloads?_ga=1.159678843.794950141.1434346788
2. The specific installation is not much to say. There are too many introductions on the web. There's no need to waste the keyboard.
3. Build a copy Set
A simple replication set consists of a minimum of three nodes. 1.primary 2. Secondary,3.arbiter node
Primary: Stores data.
Secondary: Synchronizing master node data
Arbiter: When the primary node fails, arbiter votes to select a secondary to act as the Priary node.
Roughly as follows:
Note: Three nodes are actually three Mongod instances.
(1). Create a master node configuration file content as follows: File name: rs0.conf
DBPath = D:\RuntimeServices\MongoDB_Ad\shard00\db//Specify Data store directory
LogPath = D:\RuntimeServices\MongoDB_Ad\shard00\log\shard00.log//Specify database log directory
Journal = TRUE//Whether to start the logging function
Port = 32000//Port number
Nohttpinterface = TRUE//Do not open the Web monitoring interface
Replset = RS0//replica set name (same copy set name)
(2). Create a Slave node configuration file (rs1.conf) with the following contents:
DBPath = D:\RuntimeServices\MongoDB_Ad\shard01\db
LogPath = D:\RuntimeServices\MongoDB_Ad\shard01\log\shard01.log
Journal = True
Port = 32001
Nohttpinterface = True
Replset = Rs0
(3). Create the Arbiter node configuration file (rs2.conf) as follows:
DBPath = D:\RuntimeServices\MongoDB_Ad\shard02\db
LogPath = D:\RuntimeServices\MongoDB_Ad\shard02\log\shard02.log
Journal = True
Port = 32002
Nohttpinterface = True
Replset = Rs0
Generate three services separately
Sc.exe create OpenXLive.MongoDB_Ad.Shard00 binpath= "\" D:\RuntimeServices\MongoDB_Ad\mongodb-3.0.4\bin\mongod.exe\ "--service--config=\" D:\RuntimeServices\MongoDB_Ad\mongodb-3.0.4\rs0_0.conf\ "displayname=" Rs0_service "start=" Auto
(4). Link to master node execution command
Rs.initiate ();
At this point, the replica set has only one member. Rs.conf () to view.
Follow the default settings for MongoDB. The command that you just initialized initializes the Mongod instance to the primary node. The following joins the nodes and arbiter.
Rs0:primary>rs.add ("localhost:32001");
Rs0:primary>rs.addarb ("localhost:32002");
Rs0:primary>rs.status () To view the status of the replica set.
This completes the creation of a replica set. In the age of big data, a copy set is far from enough. Although disaster recovery was resolved. However, the data shards are not completed. The space on a physical machine is limited. In order to achieve data equalization distributed on multiple machines. The following starts the MongoDB cluster build.
Building a clustered environment in MongoDB is very simple. In a few minutes, you can complete a clustered environment with failover, data synchronization, read-write separation, and distributed storage of data.
Second, the Shard cluster architecture
A shard cluster consists of a mongos routing process, a configuration server, and a replica set consisting of a collection of shards. Such as:
A shard (shard) on a shard cluster is a copy set. Of course, it can also be a single mongod instance. Replication sets are generally used in clusters. Ensure that a shard does not fail. If a shard fails. The entire cluster is hung up. Because a portion of the data is preserved on each shard.
The synthesis of all shards is all data. So we should ensure that the integrity and stability of the data on each shard is critical.
MONGOs and configuration servers are lightweight processes. The data is not saved. The configuration server only holds some state information for the Shard. Therefore, the whole process of reading the cluster is: access to the mongos-query configuration server, according to the configuration server requirements to write or read those shard server to read data.
To build the cluster steps:
1. Configure the replica set Rs0 and start. Refer to the above introduction
2. Configure the replica set rs1 and start.
3. Configure the Cofingure server.
The configuration server is also an Mongod instance.
(1). Configure server 1 configuration file cfgserver_0.conf content is as follows:
Dbpath= "E:\Mongodb\config\data\db_config0"
LogPath = "E:\Mongodb\config\logs\db_config0.log"
Journal = True
Port = 30002
Configsvr=true
Start the service.
(2). Configure server 2 configuration file reference above. Start the service
(3). Configure server 3 configuration file reference above. Start the service
4. Configuring the MONGOs Routing server
The configuration file cfg_mongos.conf content is as follows:
Logpath= ""
Port = 30000
ConfigDB = localhost:30001,localhost:30002,localhost:30003
Start the server.
5. Add individual shards to the cluster:
Open the client connection to the MONGOs server.
Add the master and slave nodes of the first Shard: Mongos>sh.addshard ("localhost:30004,localhost:30005")
Add a master node for the second shard: Mongos>sh.addshard ("localhost:30007,localhost:30008")
6. Finally pass Sh.status () check if correct (I actually added three shards)
Support the Shard cluster to complete the construction.
More content:
1. How do I access the cluster?
2. How do I add user rights?
3. If the monitoring cluster environment is working properly.
4. If you do data distributed storage
5. Tab key If selected?
6. Index Establishment
7.curd basic operation.
8. How to control the read and write separation.
9.c# php Java JS and so how to use the Mongod cluster?
For the above question. The next step is to update slowly.
MongoDB Windows Foundation Configuration