Mkdir/usr/local/mongodb/etc
Mkdir/usr/local/mongodb/data
Mkdir/usr/local/mongodb/logs
Mkdir/usr/local/mongodb/pid
1. Install the Software
Tar zxvf mongodb-linux-x86_64-rhel62-3.0.2.tgz && mv mongodb-linux-x86_64-rhel62-3.0.2/*/usr/local/mongodb/
2. Create a MongoDB data instance profile with port-sensitive configuration files
dbpath=/usr/local/mongodb/data/21000
Logpath=/usr/local/mongodb/logs/21000.log
Pidfilepath=/usr/local/mongodb/pid/21000.pid
Directoryperdb=true
Logappend=true
Replset=peiwo
port=21000
oplogsize=100
Fork=true
Noprealloc=true
Start:
/usr/local/mongodb/bin/mongod-f/usr/local/mongodb/etc/data21000.conf
3, create MongoDB configuration server, store all database meta information (routing, shard) configuration, port-sensitive configuration file
dbpath=/usr/local/mongodb/data/22000
Logpath=/usr/local/mongodb/logs/22000.log
Pidfilepath=/usr/local/mongodb/pid/22000.pid
Directoryperdb=true
Logappend=true
port=22000
oplogsize=100
Fork=true
Noprealloc=true
Configsvr=true
Start:
/usr/local/mongodb/bin/mongod-f/usr/local/mongodb/etc/configsvr22000.conf
/usr/local/mongodb/bin/mongod--configsvr--dbpath/usr/local/mongodb/data/22002--port 22002--fork--logpath/usr/ Local/mongodb/logs/22002.log
4. Start the Routing node
/usr/local/mongodb/bin/mongos--configdb 10.144.8.86:22000,10.144.8.86:22001,10.144.8.86:22002--port 20000--fork- -logpath/usr/local/mongodb/logs/configdb.log
5. Configuring replica set replica set
/usr/local/mongodb/bin/mongo 10.163.111.142:7000 #ip和port是某个节点的地址
Use admin
replcfg={_id: "Peiwo", members:[{_id:0,host: ' 10.163.111.142:21000 ', priority:2}, {_id:1,host: ' 10.163.111.142:21001 ', priority:1}, {_id:2,host: ' 10.163.111.142:21002 ', Arbiteronly:true}]};
Rs.initiate (replcfg) #使配置生效
Rs.status () #查看副本集状态
Db.getmongo (). Setslaveok (); #mongodb默认是从主节点读写数据的, read is not allowed on the replica node and you need to set the replica node to be readable.
6, Configuration sharding
/usr/local/mongodb/bin/mongo 10.144.8.86:20000 #这里必须连接路由节点
Use admin
>sh.addshard ("peiwo/10.163.111.142:21000") #test表示replica set name when the master node is added to Shard, the master, standby, and decision nodes in the set are automatically found
>db.runcommand ({enablesharding: "Peiwotestdb"}) #diameter_test is database name
>db.runcommand ({shardcollection: "peiwotestdb.peiwotable", key:{"_id": 1}})
The first command is easy to understand, the second command is to configure the database that needs to be sharding, and the third command is to configure the collection that needs to be sharding, where Dcca_dccr_test is the name of collection. There is also a key, this is a more critical thing, for the query efficiency will have a great impact, you can see Shard key overview
Here Sharding has been built, the above is just the simplest way to build, some of the configuration is still using the default configuration. If set incorrectly, will lead to inefficient, so we recommend that you look at the official documents and then make the default configuration changes.
This article is from the "My Ops Time" blog, so be sure to keep this source http://aaronsa.blog.51cto.com/5157083/1741513
MongoDB Shard Cluster configuration