Configure MongoDB3.04 cluster shards
Most of the network is sharded by the ipv2.x cluster, so I wrote a 3.04 error. Because the company uses redundant storage of disk arrays, data backup is not considered as a simple partition storage data for testing. Configuration Structure
Server Configuration: dual-core cpu, 8 GB memory, And/shard directory are mounted with a GB hard disk.
Server LIST:
IP |
Functions |
192.168.6.117 |
Config, mongos |
192.168.6.118 |
Client |
192.168.6.119 |
Client |
192.168.6.147 |
Client |
192.168.6.160 |
Client |
First, open these five machines and execute the same command:
wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.0.4.tgztar zxvf mongodb-linux-x86_64-3.0.4.tgzcp -rf mongodb-linux-x86_64-3.0.4 /usr/local/
Open machines 118, 119, 147, and 160 in sequence and execute the following command (Note: Replace the specified 118 with 119 ):
mkdir /shard/shard11 9chmod -R 777 /shard/shard119/usr/local/mongodb-3.0.4/bin/mongod -shardsvr -port 27017 -dbpath=/shard/shard119/ --storageEngine wiredTiger -logpath=/shard/shard119.log --fork
Then start. Run the following command on the terminal to check whether the Mongod process is successfully started:
ps aux | grep mongo
If none of them are successfully started, repeat the above until you find the cause.
OK. Now we have successfully started one mongod instance on four computers, and mongod is the process of actually storing data. A configuration server is also required in the cluster to store the configuration information shared by each node and the METADATA of the data [METADATA], as shown in the preceding config.
Open Server 117 and execute the following command:
mkdir /data/config/usr/local/mongodb-3.0.4/bin/mongod -configsvr -dbpath=/data/config -port 20000 -logpath=/data/config.log --fork
When all of the above are successfully started, we can enable the mongos service. Mongo is also executed on 117.
/usr/local/mongodb-3.0.4/bin/mongos -configdb 192.168.6.117:20000 -port 30000 -chunkSize 100 -logpath=/data/mongos.log --fork
Note: the ip address and port corresponding to configdb should be the ip address and port set in config. -ChunkSize: the default Host size is 200. We can set it to 100 or 100 MB.
If the process runs smoothly, you can see the processes running on the two mongo in 117, and run the command: ps-ef | grep mong. Indicates that the mongo multipart installation is complete.
Configure mongo shards as follows:
Connect to the database:
/usr/local/mongodb-3.0.4/bin/mongo 192.168.6.117:30000/admin
Note: The following operations are completed under the mongo command line:
Add a partition server: db. runCommand ({"addshard": "192.168.6.118: 27017"}) db. runCommand ({"addshard": "192.168.6.119: 27017"}) db. runCommand ({"addshard": "192.168.6.147: 27017"}) db. runCommand ({"addshard": "192.168.6.160: 27017"}) sets the sharded Database: db. runCommand ({"enablesharding": "qiaodazhao"}) use Database: use qiaodazhao to set table sharding Based on Field hash: sh. shardCollection ("qiaodazhao. resume_meta_data ", {_ id:" hashed "}) set table sharding Based on fields (note that this form works the same as above): db. runCommand ({"shardcollection": "qiaodazhao. things "," key ": {" _ id ": 1}) print the database partition information: db. printShardingStatus () prints the server information: db. serverStatus () create a table index: db. resume_meta_data.ensureIndex ({"org_name": 1 },{ "background": true}) view the table index: db. resume_meta_data.getIndexes ()
Due to space limitations, printing information is not available here.
Sort out common mongodb operation commands