MongoDB 双机集群配置与管理
来源:互联网 发布:视频裁切软件 编辑:程序博客网 时间:2024/05/01 21:05
--////////////////////////////////////////////////////////////////////////////////
1. 216 shardsvr
2. 217 shardsvr
3. 217 configsvr
4. 216 mongos
--////////////////////////////////////////////////////////////////////////////////
192.168.16.216/192.168.16.217
--27018
mongod --shardsvr run
mongod --shardsvr --dbpath /data/db --fork --logpath /data/log/shard216.log --logappend
mongod --shardsvr --dbpath /data/db --fork --logpath /data/log/shard217.log --logappend
192.168.16.216/192.168.16.216
--27019
mongod --configsvr
--mongod --configsvr --dbpath /data/config --fork --logpath /data/log/config216.log --logappend
mongod --configsvr --dbpath /data/config --fork --logpath /data/log/config217.log --logappend
http://192.168.16.216:28019/
--mongos --configdb 192.168.16.216:27019,192.168.16.217:27019
--mongos --configdb 192.168.16.216
--mongos --configdb 192.168.16.216,192.168.16.217 --fork --logpath /data/log/configdb216.log --logappend
mongos --configdb 192.168.16.217 --fork --logpath /data/log/configdb217.log --logappend
--这里起仲裁的作用,只能是单数. 我这里面设置了两个,需要减少或增加一个.
--[mongodb@rac1 data]$ mongos --configdb 192.168.16.216:27019,192.168.16.217:27019
--Wed Aug 22 23:17:58 need either 1 or 3 configdbs
--////////////////////////////////////////////////////////////////////////////////
mongo
use admin
--移除
--db.runCommand({ removeshard : "shard2" })
--检查
--db.runCommand( { listshards : 1 } );
db.runCommand({addshard:"192.168.16.216:27018",name:"shard1"})
db.runCommand({addshard:"192.168.16.217:27018",name:"shard2"})
mongos> use admin
mongos> db.runCommand( { enablesharding : "test" } )
mongos> db.runCommand( { shardcollection : "test.people", key : {name : 1} } )
--////////////////////////////////////////////////////////////////////////////////
mongos> db.runCommand({"serverStatus" : 1 })
mongos> config = db.getSisterDB("config")
mongos> config.databases.find()
mongos> printShardingStatus();
--////////////////////////////////////////////////////////////////////////////////
mongos> use admin
db.addUser("root","abcd");
--////////////////////////////////////////////////////////////////////////////////
mongos> db.createCollection("mycol1")
{ "ok" : 1 }
mongos> db.users.find();
mongos> db.users.find({},{a:1,b:1})
mongos> show collections
如:mongos> db.mycol1.stats();
db.<collection_name>.stats(); --查看具体的Shard存储信息
db.runCommand({isdbgrid:1});
db.runCommand({ismaster:1});
mongos> db.records.stats();
mongos> db.records.find();
db.records.remove();
db.coll.find().sort({"username":1,"age":-1})
db.records.find().sort({"num":1})
cd /soft
./nmon_linux_x86_64 -fT -s 10 -c 120
./nmon_linux_x86_64 -fT -s 5 -c 5
ps -ef|grep nmon
--////////////////////////////////////////////////////////////////////////////////
ps -ef | grep mongodb
--////////////////////////////////////////////////////////////////////////////////
mongos> Var cursor = db.records.find()
Thu Aug 23 22:30:56 SyntaxError: missing ; before statement (shell):1
mongos> while(cursor.hasNext()){
Var obj = cursor.next();
Print(obj.num);
}
mongos> use admin
db.addUser("root","abcd");
http://192.168.16.216:28019/
mongos> db.runCommand( { listshards : 1 } );
{
"shards" : [
{
"_id" : "shard1",
"host" : "192.168.16.216:27019"
},
{
"_id" : "shard2",
"host" : "192.168.16.217:27019"
}
],
"ok" : 1
}
mongos> db.runCommand( { enablesharding : "test" } )
{ "ok" : 1 }
mongos> db.runCommand( { shardcollection : "test.people", key : {name : 1} } )
{ "collectionsharded" : "test.people", "ok" : 1 }
mongos> db.printShardingStatus();
--- Sharding Status ---
sharding version: { "_id" : 1, "version" : 3 }
shards:
{ "_id" : "shard1", "host" : "192.168.16.216:27019" }
{ "_id" : "shard2", "host" : "192.168.16.217:27019" }
databases:
{ "_id" : "admin", "partitioned" : false, "primary" : "config" }
{ "_id" : "test", "partitioned" : true, "primary" : "shard2" }
test.people chunks:
shard2 1
{ "name" : { $minKey : 1 } } -->> { "name" : { $maxKey : 1 } } on : shard2 { "t" : 1000, "i" : 0 }
mongos> config = db.getSisterDB("config")
config
mongos> config.databases.find()
{ "_id" : "admin", "partitioned" : false, "primary" : "config" }
{ "_id" : "test", "partitioned" : true, "primary" : "shard2" }
mongos>
--mongo
--use admin
--db.runCommand({addshard:"127.0.0.1:10000",name:"shard1",maxSize:40000})
--db.runCommand({addshard:"127.0.0.1:10001",name:"shard2"})
--mongod --shardsvr --dbpath /data/db --port 10000 run > /data/log/shard216.log &
--cat /data/log2/sharda.log
--mongod --shardsvr --dbpath /data/db --port 10001 run > /data/log/shard217.log &
--cat /data/log2/shardb.log
mongos> db.runCommand({"serverStatus" : 1 })
{
"host" : "rac1",
"version" : "2.0.7",
"process" : "mongos",
"uptime" : 10198,
"localTime" : ISODate("2012-08-22T14:50:55.661Z"),
"mem" : {
"resident" : 4,
"virtual" : 110,
"supported" : true
},
"connections" : {
"current" : 1,
"available" : 818
},
"extra_info" : {
"note" : "fields vary by platform",
"heap_usage_bytes" : 258416,
"page_faults" : 0
},
"opcounters" : {
"insert" : 0,
"query" : 19,
"update" : 0,
"delete" : 0,
"getmore" : 0,
"command" : 60
},
"ops" : {
"sharded" : {
"insert" : 0,
"query" : 0,
"update" : 0,
"delete" : 0,
"getmore" : 0,
"command" : 0
},
"notSharded" : {
"insert" : 0,
"query" : 19,
"update" : 0,
"delete" : 0,
"getmore" : 0,
"command" : 60
}
},
"shardCursorType" : {
},
"asserts" : {
"regular" : 0,
"warning" : 0,
"msg" : 0,
"user" : 4,
"rollovers" : 0
},
"network" : {
"bytesIn" : 6636,
"bytesOut" : 10361,
"numRequests" : 79
},
"ok" : 1
}
mongos>
--=================================================
--停止MongoDB
--向服务器发送一个SIGINT或SIGTERM信号
-- kill -2 PID(SIGINT) 或 kill PID (SIGTERM)
-- 当收到时会稳妥退出. 也就是说会等到当前运行的操作或文件预分配完成.
-- 关闭所有打开的连接,将缓存的数据刷新到磁盘,最后停止
--SIGKILL(kill 9),会导致数据库直接关闭. 上面的步骤会忽略,这会使数据文件损坏.
-- 如真损坏了,一定要在启动备份之前修复数据库
--另一种方法是使用shutdown命令
-- use admin
-- >db.shutdownServer();
--=================================================
--语法收集:
>db.createCollection("users1")
>db.createCollection("users", {size: 20000})
test.cloud1
use test
db.createCollection("testtab2",{size: 100000})
[mongodb@rac1 db]$ mongo
MongoDB shell version: 2.0.7
connecting to: test
mongos> db.rmongos> db. c
test.c
mongos> db.createCollection("testtab2",{size:100000})
{ "ok" : 1 }
mongos>
Capped Collection 集合
概念
1. Capped集合是定长文档,记录集的长度是定长,定数量的
2. Capped集合的数据库尺寸是预先定制的,如1024K
3. 我们可以预算得到capped记录集的document数,
4. Capped 的按先后顺序进行插入,如果文档数溢出,则丢弃最早的记录,先进先出的定长队列,并且有系统自动实现
5. 不存在索引,插入和提取速度都相当快
>db.createCollection("mycoll", {capped:true, size:100000})
>db.user.actions.count();
>db.user.actions.find();
>db.user.actions.find().sort({"$natural": -1})
mongos> use test;
switched to db test
mongos> db.cursors.find({a:3})
{ "a" : 3 }
mongos> db.runCommand( { shardcollection : "test.cursors", key : {"_id" : 1} } )
{ "ok" : 0, "errmsg" : "access denied - use admin db" }
mongos> use admin
switched to db admin
mongos> db.runCommand( { shardcollection : "test.cursors", key : {"_id" : 1} } )
{ "ok" : 0, "errmsg" : "can't shard capped collection" }
--=================================================
db.createCollection("mycoll")
MAIL:xcl_168@aliyun.com
我的CSDN BLOG: http://blog.csdn.net/xcl168
- MongoDB 双机集群配置与管理
- mongodb集群搭建(双机)
- MongoDB双机集群操作记录
- mongodb集群与分片的配置说明
- mongodb集群AB复制 安装与配置
- mongodb集群与分片的配置说明
- MongoDB集群状态查看与重新配置
- mongodb集群管理
- MongoDB集群管理要点
- Linux下mysql双机集群配置教程
- mongodb用户管理与权限配置
- 配置MongoDB集群
- MongoDB集群配置
- 配置MongoDB集群分片
- 配置MongoDB集群分片
- MongoDB集群安装配置
- mongodb的集群配置
- 配置MongoDB集群分片
- (2)啊哈!算法
- 设计模式笔记
- 线段树_懒标记
- vim 缩进、禁用鼠标、高亮、从上次编辑位置打开
- IOS 图片上传处理 图片压缩 图片处理
- MongoDB 双机集群配置与管理
- chapter3习题
- 从零开始构建Ubuntu LiveCD
- fseek函数、ftell函数和rewind函数
- JavaScript-3
- HD1052
- Linux Shell笔记之结构循环
- java中的堆与栈
- shor sValue=5; sValue=sValue-2;与short sValue=5;sValue-=2;是否等价?