-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmongo笔记.txt
84 lines (65 loc) · 1.69 KB
/
mongo笔记.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
./mongod --config ../mongodb.cfg
./mongos --config ../mongodb.cfg
查看服务器统计信息
db.runCommand({"serverStatus":1})
创建复制集
登陆到复制集的一台机器中
./mongo --port 27017
rs.initiate({_id:'shard1', members : [
{_id : 0, host : '172.16.1.107:27017'},
{_id : 1, host : '172.16.1.108:27017'},
{_id : 2, host : '172.16.1.109:27017'}]
})
或者
db.runCommand({
"replSetInitiate" : {
"_id" : "replcopy",
"members" : [
{_id : 0, host : '192.168.10.147:27017'},
{_id : 1, host : '192.168.10.222:27017'},
{_id : 2, host : '192.168.10.244:27017'}
]}})
查看复制集信息
rs.status()
查看活跃节点
db.isMaster()
主从配置信息查看
use local
show collections
db.system.replset.find()
查询从库,分担主库的压力
db.getMongo().setSlaveOk()
通过oplog增加节点
rs.add("192.168.10.223:27017")
删除节点
rs.remove("192.168.10.147:27017")
rs.remove("192.168.10.222:27017")
rs.remove("192.168.10.244:27017")
通过mongod的参数--plogSize来改变oplog的日志大小
######ip改变后的重新启动#######
rs.reconfig({
"_id" : "replcopy",
"members" : [
{
"_id" : 0,
"host" : "192.168.1.147:27017"
},
{
"_id" : 1,
"host" : "192.168.1.222:27017"
},
{
"_id" : 2,
"host" : "192.168.1.244:27017"
}
]
}, {force: true})
#############################################
./mongo --port 30000
创建分片
use admin
db.runCommand({addshard:"shard1/172.16.1.107:27017,172.16.1.108:27017,172.16.1.109:27017"});
激活分片功能
设置分片存储的数据库
db.runCommand({enablesharding : "ims"});
db.runCommand({shardcollection : "ims.form_data", key : {_id : 1}});