warnings:
2017-04-24T23:30:47.285+0800 I CONTROL [main]
2017-04-24T23:30:47.285+0800 I CONTROL [main] ** WARNING: Access control is not enabled for the database.
2017-04-24T23:30:47.285+0800 I CONTROL [main] ** Read and write access to data and configuration is unrestricted.
2017-04-24T23:30:47.285+0800 I CONTROL [main] ** WARNING: You are running this process as the root user, which is not recommended.
2017-04-24T23:30:47.285+0800 I CONTROL [main]
mongos> show dbs
admin 0.000GB
config 0.000GB
mongos> use config
switched to db config
mongos> show collections
chunks
lockpings
locks
migrations
mongos
shards
tags
version
mongos> db.shards.find()
# 这里没有返回文档,也说明分片集群中并没有添加可用分片集群。
配置分片集群:shard
mongos> sh.addShard("shard-a/test1.lan,test2.lan,test3.lan")
{ "shardAdded" : "shard-a", "ok" : 1 }
mongos> db.shards.find()
{ "_id" : "shard-a", "host" : "shard-a/test1.lan:27017,test2.lan:27017,test3.lan:27017", "state" : 1 }
mongos> sh.addShard("shard-b/test1.lan:37017,test2.lan:37017,test3.lan:37017")
{ "shardAdded" : "shard-b", "ok" : 1 }
mongos> db.shards.find()
{ "_id" : "shard-a", "host" : "shard-a/test1.lan:27017,test2.lan:27017,test3.lan:27017", "state" : 1 }
{ "_id" : "shard-b", "host" : "shard-b/test1.lan:37017,test2.lan:37017,test3.lan:37017", "state" : 1 }
# 检查分片集群的分片副本集数量,方法一
mongos> db.getSiblingDB('config').shards.find()
{ "_id" : "shard-a", "host" : "shard-a/test1.lan:27017,test2.lan:27017,test3.lan:27017", "state" : 1 }
{ "_id" : "shard-b", "host" : "shard-b/test1.lan:37017,test2.lan:37017,test3.lan:37017", "state" : 1 }
# 检查分片集群的分片副本集数量,方法二
mongos> use admin
switched to db admin
mongos> db.runCommand({listshards: 1})
{
"shards" : [
{
"_id" : "shard-a",
"host" : "shard-a/test1.lan:27017,test2.lan:27017,test3.lan:27017",
"state" : 1
},
{
"_id" : "shard-b",
"host" : "shard-b/test1.lan:37017,test2.lan:37017,test3.lan:37017",
"state" : 1
}
],
"ok" : 1
}
# 检查分片集群的分片副本集数量,方法三
配置分片集合:接下来的步骤就是在数据库上启动分片。分片不会自动完成,而是需要在数据库里提前为集合做好设置才行。
mongos> sh.enableSharding("test2_db") # 该库可以是已存在的,也可以是暂不存在的
{ "ok" : 1 }
mongos> db.getSiblingDB("config").databases.find()
{ "_id" : "test2_db", "primary" : "shard-a", "partitioned" : true }
# sharding 分片库的配置库 dat