Mongodb3.2.12 副本集 + 分片 完整安装
1.安装准备
MongoDB安装包:mongodb-Linux-x86_64-rhel70-3.2.8.tgz
下载地址:https://www.mongodb.com/download-center#previous
下载MongoDB安装,选择Community Server选项,选中RHEL 6 Linux 64-bit版本下载。
2.解压MongoDB安装包
[hadoop@new-cdh9 Tools]$ tar -zxvf mongodb-linux-x86_64-amazon-3.2.12.tgz
mongodb-linux-x86_64-amazon-3.2.12/README
mongodb-linux-x86_64-amazon-3.2.12/THIRD-PARTY-NOTICES
mongodb-linux-x86_64-amazon-3.2.12/MPL-2
mongodb-linux-x86_64-amazon-3.2.12/GNU-AGPL-3.0
mongodb-linux-x86_64-amazon-3.2.12/bin/mongodump
mongodb-linux-x86_64-amazon-3.2.12/bin/mongorestore
mongodb-linux-x86_64-amazon-3.2.12/bin/mongoexport
mongodb-linux-x86_64-amazon-3.2.12/bin/mongoimport
mongodb-linux-x86_64-amazon-3.2.12/bin/mongostat
mongodb-linux-x86_64-amazon-3.2.12/bin/mongotop
mongodb-linux-x86_64-amazon-3.2.12/bin/bsondump
mongodb-linux-x86_64-amazon-3.2.12/bin/mongofiles
mongodb-linux-x86_64-amazon-3.2.12/bin/mongooplog
mongodb-linux-x86_64-amazon-3.2.12/bin/mongoperf
mongodb-linux-x86_64-amazon-3.2.12/bin/mongosniff
mongodb-linux-x86_64-amazon-3.2.12/bin/mongod
mongodb-linux-x86_64-amazon-3.2.12/bin/mongos
mongodb-linux-x86_64-amazon-3.2.12/bin/mongo
[hadoop@new-cdh12 Tools]$ mv mongodb-linux-x86_64-amazon-3.2.12 mongodb
[hadoop@new-cdh9 Tools]$
3.创建MongoDB存放数据库文件和日志的目录
[hadoop@new-cdh12 Tools]$ cd mongodb
[hadoop@new-cdh12 mongodb]$ ll
total 100
drwxrwxr-x 2 hadoop hadoop 4096 Mar 6 18:54 bin
-rw-rw-r-- 1 hadoop hadoop 34520 Feb 2 00:41 GNU-AGPL-3.0
-rw-rw-r-- 1 hadoop hadoop 16726 Feb 2 00:41 MPL-2
-rw-rw-r-- 1 hadoop hadoop 1359 Feb 2 00:41 README
-rw-rw-r-- 1 hadoop hadoop 35910 Feb 2 00:41 THIRD-PARTY-NOTICES
[hadoop@new-cdh12 mongodb]$ mkdir data log conf
[hadoop@new-cdh12 mongodb]$ ll
total 108
drwxrwxr-x 2 hadoop hadoop 4096 Mar 6 18:54 bin
drwxrwxr-x 2 hadoop hadoop 4096 Mar 6 19:03 conf
drwxrwxr-x 2 hadoop hadoop 4096 Mar 6 18:58 data
-rw-rw-r-- 1 hadoop hadoop 34520 Feb 2 00:41 GNU-AGPL-3.0
drwxrwxr-x 2 hadoop hadoop 4096 Mar 6 18:58 log
-rw-rw-r-- 1 hadoop hadoop 16726 Feb 2 00:41 MPL-2
-rw-rw-r-- 1 hadoop hadoop 1359 Feb 2 00:41 README
-rw-rw-r-- 1 hadoop hadoop 35910 Feb 2 00:41 THIRD-PARTY-NOTICES
[hadoop@new-cdh12 mongodb]$
4.YAML格式mongod.conf(Core Options)
配置请参考官方配置:https://docs.mongodb.com/manual/reference/configuration-options/#core-options 我们采用YMAL格式配置mognod.conf文件。首先进入到mongodb的conf目录下,输入命令vim mongod.conf创建配置文件。输入配置信息后,进行保存. 输入:号之后,需要空格隔开
systemLog:
destination:file #以文件形式输出日志文件,输入file之前,需要空格
path: /hadoop/Tools/mongodb/log/shard1/mongodb.log #表示存储日志文件
logAppend: true #日志是追加模式,false是覆盖模式
storage:
dbPath:/hadoop/Tools/mongodb/data/shard1 #表示存储mongodb数据库文件目录
processManagement:
fork: true #作为后台服务运行
#net:
# bindIP: 127.0.0.1
# port: 27017
#security:
# authorization:enabled
5.搭建数据库副本集
需要准备3台mongod服务器 new-cdh9:27017 new-cdh9:27017 new-cdh9:27017
1.Mongod.conf文件配置
在conf/shard1目录下vi mongod.conf文件输入以下内容:
systemLog:
destination: file
path: /hadoop/Tools/mongodb/log/shard1/mongodb.log
logAppend: true
storage:
dbPath: /hadoop/Tools/mongodb/data/shard1
processManagement:
fork: true
replication:
oplogSizeMB: 5
replSetName: re01
2.分别在3台机器上启动副本集
[hadoop@new-cdh12 Tools]$ mongodb/bin/mongod -f mongodb/conf/shard1/mongod.conf
about to fork child process, waiting until server is ready for connections.
forked process: 19535
child process started successfully, parent exiting
[hadoop@new-cdh10 Tools]$ mongodb/bin/mongod -f mongodb/conf/shard1/mongod.conf
about to fork child process, waiting until server is ready for connections.
forked process: 18495
child process started successfully, parent exiting
[hadoop@new-cdh9 Tools]$ mongodb/bin/mongod -f mongodb/conf/shard1/mongod.conf
about to fork child process, waiting until server is ready for connections.
forked process: 11523
child process started successfully, parent exiting
启动之前记得创建所需要的文件夹。
3.初始化副本集
[hadoop@new-cdh9 Tools]$ mongodb/bin/mongo
MongoDB shell version: 3.2.12
connecting to: test
Server has startup warnings:
2017-03-06T19:57:07.733+0800 I CONTROL [initandlisten]
2017-03-06T19:57:07.733+0800 I CONTROL [initandlisten] ** WARNING: soft rlimits too low. rlimits set to 31335 processes, 65535 files. Number of processes should be at least 32767.5 : 0.5 times number of files.
> config={_id:“re01”,members:[{_id:0,host:“new-cdh9:27017”},{_id:1,host:“new-cdh10:27017”},{_id:2,host:“new-cdh12:27017”}]}
{
“_id” : “re01”,
“members” : [
{
“_id” : 0,
“host” : “new-cdh9:27017”
},
{
“_id” : 1,
“host” : “new-cdh10:27017”
},
{
“_id” : 2,
“host” : “new-cdh12:27017”
}
]
}
> rs.initiate(config)
{ “ok” : 1 }
re01:OTHER>
re01:PRIMARY>
re01:PRIMARY>
4.检查副本集状态
输入rs.status()查看副本集状态。 health:1 //1表明状态是正常,0表明异常 state:1 // 1表明是primary,2表明是slave,即做备份的机器
re01:PRIMARY> rs.status()
{
“set” : “re01”,
“date” : ISODate(“2017-03-06T12:08:20.110Z”),
“myState” : 1,
“term” : NumberLong(1),
“heartbeatIntervalMillis” : NumberLong(2000),
“members” : [
{
“_id” : 0,
“name” : “new-cdh9:27017”,
“health” : 1,
“state” : 1,
“stateStr” : “PRIMARY”,
“uptime” : 673,
“optime” : {
“ts” : Timestamp(1488801896, 1),
“t” : NumberLong(1)
},
“optimeDate” : ISODate(“2017-03-06T12:04:56Z”),
“electionTime” : Timestamp(1488801895, 1),
“electionDate” : ISODate(“2017-03-06T12:04:55Z”),
“configVersion” : 1,
“self” : true
},
{
“_id” : 1,
“name” : “new-cdh10:27017”,
“health” : 1,
“state” : 2,
“stateStr” : “SECONDARY”,
“uptime” : 215,
“optime” : {
“ts” : Timestamp(1488801896, 1),
“t” : NumberLong(1)
},
“optimeDate” : ISODate(“2017-03-06T12:04:56Z”),
“lastHeartbeat” : ISODate(“2017-03-06T12:08:20.001Z”),
“lastHeartbeatRecv” : ISODate(“2017-03-06T12:08:18.174Z”),
“pingMs” : NumberLong(0),
“syncingTo” : “new-cdh12:27017”,
“configVersion” : 1
},
{
“_id” : 2,
“name” : “new-cdh12:27017”,
“health” : 1,
“state” : 2,
“stateStr” : “SECONDARY”,
“uptime” : 215,
“optime” : {
“ts” : Timestamp(1488801896, 1),
“t” : NumberLong(1)
},
“optimeDate” : ISODate(“2017-03-06T12:04:56Z”),
“lastHeartbeat” : ISODate(“2017-03-06T12:08:20.001Z”),
“lastHeartbeatRecv” : ISODate(“2017-03-06T12:08:18.123Z”),
“pingMs” : NumberLong(0),
“syncingTo” : “new-cdh9:27017”,
“configVersion” : 1
}
],
“ok” : 1
}
re01:PRIMARY>
6.数据库分片
Mongodb分配技术需要最少4台服务区,其中2台为mongod服务器,一台为mongos服务区,另外一太为mongosconfig server服务器。 但是资源不够 所有 通过改变端口的方式,在同一台机器上运行
1.配置另一个副本集
端口改成27018,更改副本集名称 详细配置如下,(创建所需文件件)
systemLog:
destination: file
path: /hadoop/Tools/mongodb/log/shard2/mongodb.log
logAppend: true
storage:
dbPath: /hadoop/Tools/mongodb/data/shard2
net:
bindIp: 0.0.0.0
port: 27018
processManagement:
fork: true
replication:
oplogSizeMB: 5
replSetName: re02
配置好启动,初始化副本集 参考 上面介绍
[hadoop@new-cdh10 Tools]$ mongodb/bin/mongo --port 27018
MongoDB shell version: 3.2.12
connecting to: 127.0.0.1:27018/test
Server has startup warnings:
2017-03-06T20:42:25.201+0800 I CONTROL [initandlisten]
2017-03-06T20:42:25.201+0800 I CONTROL [initandlisten] ** WARNING: soft rlimits too low. rlimits set to 31335 processes, 65535 files. Number of processes should be at least 32767.5 : 0.5 times number of files.
> config={_id:“re02”,members:[{_id:0,host:“new-cdh9:27018”},{_id:1,host:“new-cdh10:27018”},{_id:2,host:“new-cdh12:27018”}]}
{
“_id” : “re02”,
“members” : [
{
“_id” : 0,
“host” : “new-cdh9:27018”
},
{
“_id” : 1,
“host” : “new-cdh10:27018”
},
{
“_id” : 2,
“host” : “new-cdh12:27018”
}
]
}
> rs.initiate(config)
{ “ok” : 1 }
re02:OTHER>
re02:SECONDARY>
re02:PRIMARY> rs.status()
{
“set” : “re02”,
“date” : ISODate(“2017-03-06T12:50:54.839Z”),
“myState” : 1,
“term” : NumberLong(1),
“heartbeatIntervalMillis” : NumberLong(2000),
“members” : [
{
“_id” : 0,
“name” : “new-cdh9:27018”,
“health” : 1,
“state” : 2,
“stateStr” : “SECONDARY”,
“uptime” : 107,
“optime” : {
“ts” : Timestamp(1488804559, 2),
“t” : NumberLong(1)
},
“optimeDate” : ISODate(“2017-03-06T12:49:19Z”),
“lastHeartbeat” : ISODate(“2017-03-06T12:50:53.350Z”),
“lastHeartbeatRecv” : ISODate(“2017-03-06T12:50:53.019Z”),
“pingMs” : NumberLong(0),
“syncingTo” : “new-cdh10:27018”,
“configVersion” : 1
},
{
“_id” : 1,
“name” : “new-cdh10:27018”,
“health” : 1,
“state” : 1,
“stateStr” : “PRIMARY”,
“uptime” : 510,
“optime” : {
“ts” : Timestamp(1488804559, 2),
“t” : NumberLong(1)
},
“optimeDate” : ISODate(“2017-03-06T12:49:19Z”),
“infoMessage” : “could not find member to sync from”,
“electionTime” : Timestamp(1488804559, 1),
“electionDate” : ISODate(“2017-03-06T12:49:19Z”),
“configVersion” : 1,
“self” : true
},
{
“_id” : 2,
“name” : “new-cdh12:27018”,
“health” : 1,
“state” : 2,
“stateStr” : “SECONDARY”,
“uptime” : 107,
“optime” : {
“ts” : Timestamp(1488804559, 2),
“t” : NumberLong(1)
},
“optimeDate” : ISODate(“2017-03-06T12:49:19Z”),
“lastHeartbeat” : ISODate(“2017-03-06T12:50:53.350Z”),
“lastHeartbeatRecv” : ISODate(“2017-03-06T12:50:53.072Z”),
“pingMs” : NumberLong(0),
“syncingTo” : “new-cdh10:27018”,
“configVersion” : 1
}
],
“ok” : 1
}
re02:PRIMARY>
2.设置最高优先级强制转换成员为主节点
输入cfg=rs.conf()命令 输入命令: #cfg.members[0].priority=1 #cfg.members[2].priority=0.5
re02:PRIMARY> cfg=rs.conf()
{
“_id” : “re02”,
“version” : 1,
“protocolVersion” : NumberLong(1),
“members” : [
{
“_id” : 0,
“host” : “new-cdh9:27018”,
“arbiterOnly” : false,
“buildIndexes” : true,
“hidden” : false,
“priority” : 1,
“tags” : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
},
{
"_id" : 1,
"host" : "new-cdh10:27018",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
},
{
"_id" : 2,
"host" : "new-cdh12:27018",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
}
\],
"settings" : {
"chainingAllowed" : true,
"heartbeatIntervalMillis" : 2000,
"heartbeatTimeoutSecs" : 10,
"electionTimeoutMillis" : 10000,
"getLastErrorModes" : {
},
"getLastErrorDefaults" : {
"w" : 1,
"wtimeout" : 0
},
"replicaSetId" : ObjectId("58bd5ac24d2b001bf76cbc6a")
}
}
re02:PRIMARY> cfg.members[2].priority=0.5
0.5
re02:PRIMARY> cfg.members[0].priority=0.5
0.5
re02:PRIMARY> cfg.members[1].priority=1
1
re02:PRIMARY> rs.reconfig(cfg)
{ “ok” : 1 }
re02:PRIMARY> cfg=rs.conf()
{
“_id” : “re02”,
“version” : 2,
“protocolVersion” : NumberLong(1),
“members” : [
{
“_id” : 0,
“host” : “new-cdh9:27018”,
“arbiterOnly” : false,
“buildIndexes” : true,
“hidden” : false,
“priority” : 0.5,
“tags” : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
},
{
"_id" : 1,
"host" : "new-cdh10:27018",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
},
{
"_id" : 2,
"host" : "new-cdh12:27018",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 0.5,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
}
\],
"settings" : {
"chainingAllowed" : true,
"heartbeatIntervalMillis" : 2000,
"heartbeatTimeoutSecs" : 10,
"electionTimeoutMillis" : 10000,
"getLastErrorModes" : {
},
"getLastErrorDefaults" : {
"w" : 1,
"wtimeout" : 0
},
"replicaSetId" : ObjectId("58bd5ac24d2b001bf76cbc6a")
}
}
re02:PRIMARY>
使分片副本集1 的主节点落在new-cdh9上(操作参考上面) 使分片副本集2 的主节点落在new-cdh10上(操作如上)
3.配置config副本集服务器
创建所需文件夹 需要添加上replication节点,需要加上副本集名称。 详细配置如下
[hadoop@new-cdh9 Tools]$ vi mongodb/conf/config/mongod.conf
systemLog:
destination: file
path: /hadoop/Tools/mongodb/log/config/mongodb.log
logAppend: true
storage:
dbPath: /hadoop/Tools/mongodb/data/config
processManagement:
fork: true
sharding:
clusterRole: configsvr
replication:
oplogSizeMB: 5
replSetName: config01
~
“mongodb/conf/config/mongod.conf” 13L, 326C written
[hadoop@new-cdh9 Tools]$ mongodb/bin/mongod -f mongodb/conf/config/mongod.conf
about to fork child process, waiting until server is ready for connections.
forked process: 11909
child process started successfully, parent exiting
[hadoop@new-cdh9 Tools]$
分别在两台机器上启动mongo
4.初始化配置config副本集服务器
只能初始化一次
[hadoop@new-cdh9 Tools]$ mongodb/bin/mongo --port 27019
MongoDB shell version: 3.2.12
connecting to: 127.0.0.1:27019/test
Server has startup warnings:
2017-03-06T21:16:45.868+0800 I CONTROL [initandlisten]
2017-03-06T21:16:45.868+0800 I CONTROL [initandlisten] ** WARNING: soft rlimits too low. rlimits set to 31335 processes, 65535 files. Number of processes should be at least 32767.5 : 0.5 times number of files.
> config={_id:“config01”,members:[{_id:0,host:“new-cdh9:27019”},{_id:1,host:“new-cdh10:27019”}]}
{
“_id” : “config01”,
“members” : [
{
“_id” : 0,
“host” : “new-cdh9:27019”
},
{
“_id” : 1,
“host” : “new-cdh10:27019”
}
]
}
> rs.initiate(config)
{ “ok” : 1 }
config01:OTHER> rs.status()
{
“set” : “config01”,
“date” : ISODate(“2017-03-06T13:23:38.057Z”),
“myState” : 1,
“term” : NumberLong(1),
“configsvr” : true,
“heartbeatIntervalMillis” : NumberLong(2000),
“members” : [
{
“_id” : 0,
“name” : “new-cdh9:27019”,
“health” : 1,
“state” : 1,
“stateStr” : “PRIMARY”,
“uptime” : 413,
“optime” : {
“ts” : Timestamp(1488806612, 1),
“t” : NumberLong(1)
},
“optimeDate” : ISODate(“2017-03-06T13:23:32Z”),
“infoMessage” : “could not find member to sync from”,
“electionTime” : Timestamp(1488806611, 1),
“electionDate” : ISODate(“2017-03-06T13:23:31Z”),
“configVersion” : 1,
“self” : true
},
{
“_id” : 1,
“name” : “new-cdh10:27019”,
“health” : 1,
“state” : 2,
“stateStr” : “SECONDARY”,
“uptime” : 17,
“optime” : {
“ts” : Timestamp(1488806612, 1),
“t” : NumberLong(1)
},
“optimeDate” : ISODate(“2017-03-06T13:23:32Z”),
“lastHeartbeat” : ISODate(“2017-03-06T13:23:37.996Z”),
“lastHeartbeatRecv” : ISODate(“2017-03-06T13:23:34.193Z”),
“pingMs” : NumberLong(0),
“syncingTo” : “new-cdh9:27019”,
“configVersion” : 1
}
],
“ok” : 1
}
config01:PRIMARY>
5.配置启动mongos服务器
由于config服务器是副本集结构,所以在配置mognos.conf文件也有所变化。 跟以前不同,这里需要在服务器地址前添加副本集名称,每个服务器之间都要用逗号隔开就可以。这是启动第一个mongos服务器。 以下是mongos.conf文件配置内容:
systemLog:
destination: file
path: /hadoop/Tools/mongodb/log/mongos/mongos.log
logAppend: true
processManagement:
fork: true
net:
port: 28885
sharding:
configDB: config01/new-cdh9:27019, new-cdh9:27019
在mongos 集群上分别启动,配置文件相同
6.添加分片副本集
[hadoop@new-cdh9 Tools]$ mongodb/bin/mongo new-cdh9:28885
MongoDB shell version: 3.2.12
connecting to: new-cdh9:28885/test
mongos> use admin
switched to db admin
mongos> db.runCommand({addshard:“re01/new-cdh9:27017”})
{ “shardAdded” : “re01”, “ok” : 1 }
mongos> db.runCommand({addshard:“re02/new-cdh10:27018”})
{ “shardAdded” : “re02”, “ok” : 1 }
mongos>
7.在mongos中添加分片数据库并设置片键
[hadoop@new-cdh9 ~]$ Tools/mongodb/bin/mongo new-cdh9:28885
MongoDB shell version: 3.2.12
connecting to: new-cdh9:28885/test
mongos> use admin
switched to db admin
mongos> db.runCommand({enablesharding:“mydbtest”})
{ “ok” : 1 }
mongos> db.runCommand({shardcollection:“mydbtest.user”,key:{“userName”:“hashed”}})
{ “collectionsharded” : “mydbtest.user”, “ok” : 1 }
8.在mongos中测试分片和副本集
mongos> use mydbtest
switched to db mydbtest
mongos> for(var i=0;i<10000;i++){db.user.insert({“userName”:“user”+i,“depart”:“towngas”,“userNo”:“no.”+i})}
WriteResult({ “nInserted” : 1 })
mongos> db.printShardingStatus()
— Sharding Status —
sharding version: {
“_id” : 1,
“minCompatibleVersion” : 5,
“currentVersion” : 6,
“clusterId” : ObjectId(“58bd66d71f6b1608450ac068”)
}
shards:
{ “_id” : “re01”, “host” : “re01/new-cdh10:27017,new-cdh12:27017,new-cdh9:27017” }
{ “_id” : “re02”, “host” : “re02/new-cdh10:27018,new-cdh12:27018,new-cdh9:27018” }
active mongoses:
“3.2.12” : 2
balancer:
Currently enabled: yes
Currently running: no
Failed balancer rounds in last 5 attempts: 0
Migration Results for the last 24 hours:
4 : Success
2 : Failed with error ‘aborted’, from re02 to re01
159 : Failed with error ‘ns not found, should be impossible’, from re02 to re01
1 : Failed with error ‘data transfer error’, from re02 to re01
databases:
{ “_id” : “family”, “primary” : “re01”, “partitioned” : false }
{ “_id” : “mydb”, “primary” : “re02”, “partitioned” : true }
mydb.user
shard key: { “userName” : 1 }
unique: false
balancing: true
chunks:
re01 3
re02 5
{ “userName” : { “minKey" : 1 } } -->> { "userName" : "user1" } on : re01 Timestamp(2, 0)
{ "userName" : "user1" } -->> { "userName" : "user185791" } on : re01 Timestamp(3, 0)
{ "userName" : "user185791" } -->> { "userName" : "user36485" } on : re01 Timestamp(4, 0)
{ "userName" : "user36485" } -->> { "userName" : "user450641" } on : re02 Timestamp(4, 1)
{ "userName" : "user450641" } -->> { "userName" : "user536435" } on : re02 Timestamp(3, 3)
{ "userName" : "user536435" } -->> { "userName" : "user622228" } on : re02 Timestamp(3, 4)
{ "userName" : "user622228" } -->> { "userName" : "user7" } on : re02 Timestamp(3, 5)
{ "userName" : "user7" } -->> { "userName" : { "maxKey” : 1 } } on : re02 Timestamp(1, 3)
{ “_id” : “mydbtest”, “primary” : “re02”, “partitioned” : true }
mydbtest.user
shard key: { “userName” : “hashed” }
unique: false
balancing: true
chunks:
re01 2
re02 2
{ “userName” : { “minKey" : 1 } } -->> { "userName" : NumberLong("-4611686018427387902") } on : re01 Timestamp(2, 2)
{ "userName" : NumberLong("-4611686018427387902") } -->> { "userName" : NumberLong(0) } on : re01 Timestamp(2, 3)
{ "userName" : NumberLong(0) } -->> { "userName" : NumberLong("4611686018427387902") } on : re02 Timestamp(2, 4)
{ "userName" : NumberLong("4611686018427387902") } -->> { "userName" : { "maxKey” : 1 } } on : re02 Timestamp(2, 5)
mongos> ^C
bye
看结果我们已经把数据分在 re1 和re2 上 分别登录各分片的主节点 查看
[hadoop@new-cdh9 ~]$ Tools/mongodb/bin/mongo new-cdh9:27017
MongoDB shell version: 3.2.12
connecting to: new-cdh9:27017/test
Server has startup warnings:
2017-03-06T19:57:07.733+0800 I CONTROL [initandlisten]
2017-03-06T19:57:07.733+0800 I CONTROL [initandlisten] ** WARNING: soft rlimits too low. rlimits set to 31335 processes, 65535 files. Number of processes should be at least 32767.5 : 0.5 times number of files.
re01:PRIMARY> use mydbtest
switched to db mydbtest
re01:PRIMARY> db.user.count()
4969
re01:PRIMARY> ^C
bye
[hadoop@new-cdh9 ~]$ Tools/mongodb/bin/mongo new-cdh10:27018
MongoDB shell version: 3.2.12
connecting to: new-cdh10:27018/test
Server has startup warnings:
2017-03-06T20:42:25.201+0800 I CONTROL [initandlisten]
2017-03-06T20:42:25.201+0800 I CONTROL [initandlisten] ** WARNING: soft rlimits too low. rlimits set to 31335 processes, 65535 files. Number of processes should be at least 32767.5 : 0.5 times number of files.
re02:PRIMARY> use mydbtest
switched to db mydbtest
re02:PRIMARY> db.user.count()
5031
re02:PRIMARY>
行数分别是 5031 + 4969 = 10000 证明我们分片测试成功