设为首页 加入收藏

TOP

MongoDB 3 分片集群安装配置(七)
2017-04-26 10:22:18 】 浏览:755
Tags:MongoDB 3分片 集群 安装 配置
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

首页 上一页 4 5 6 7 8 9 10 下一页 尾页 7/10/10
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇MySQL 5.7.x开启SSL连接 下一篇MySQL分库分表备份脚本

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目