MongoDB 마스터 던 전 집합 블록 버스터 설치
############################### ##########################################
http://www.codefrom.com/paper/MongoDB
mongod --master --dbpath /opt/mongo1/ --port 10000
mongod --slave --dbpath /opt/mongo2/ --port 10001 --source 127.0.0.1:10000
--slavedelay 600 600s,
mongo 127.0.0.1:10000
mongo --host 127.0.0.1 --port 10000
show dbs
1
rs.slaveOk() db.getMongo().setSlaveOk();
2
vi ~/.mongorc.js
rs.slaveOk();
3 : mongodb XML slave-ok="true" secondary
http://www.cnblogs.com/htynkn/archive/2011/10/30/2229467.html
############################### #################################################
############################### Replica-Set ##################################
http://webinglin.github.io/2015/06/09/MongoDB - -Replica-Set- /
MongoDB Replica Set
http://www.linuxidc.com/Linux/2015-02/113296.htm
========================================================================================
Replica Set :Primary,Secondary Arbiter。
Primary , Replica Set Primary。Primary ,Replica Set Secondary Primary。
Primary data sets oplog 。
Secondary Secondary Primary oplog, oplog data sets。Secondary Primary , Secondary
。 ,Secondary , Secondary 。
Arbiter Arbiter data sets, Primary Secondary Primary。 Replica Set ,
Arbiter Primary。Arbiter 。 Primary Secondary Arbiter。
Hidden: IP , , , 。
Delayed: primary 。 , , , 。
Non-Voting: secondary , 。
Replica Set 12 , 7 Primary, 12, Master-Slave 。
Replica Set , Arbiter, Secondary Primary Primary, Secondary。
======================================================================================
mongos, , mongos , ,mongos ,
shard 。 mongos , mongodb 。
config server, , ( 、 ) 。mongos , ,
。mongos config server , mongos
, mongos 。 config server , , ! ,
, mongodb 。
shard, 。
owl8 10.45.13.133 mongos config replica set
owl5 10.45.12.205 mongos config replica set
owl6 10.45.12.196 mongos config replica set
mongod --configsvr --dbpath /opt/config --port 21000 --logpath /bak/logs/mongo/config.log --fork
mongos
mongos --configdb 10.45.13.133:21000,10.45.12.205:21000,10.45.12.196:21000 --port 20000 --logpath /bak/logs/mongo/mongos.log --fork
Replica Set
--replSet
mongod --dbpath /opt/mongo --replSet rs0 # ,
mongod --fork --dbpath /opt/mongo --replSet rs0 --oplogSize 5000 --logpath /opt/mongo/mongod.log #
mongod -f /etc/mongod.conf
#############################################################################################
# mongod.conf
# http://docs.mongodb.org/manual/reference/configuration-options/
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: /bak/logs/mongo/mongod.log
# Where and how to store data.
storage:
dbPath: /opt/mongo
journal:
enabled: true
directoryPerDB: true
# syncPeriodSecs: 60
# engine:
# mmapv1:
# wiredTiger:
engine: wiredTiger
wiredTiger:
engineConfig:
cacheSizeGB: 6
# how the process runs
processManagement:
fork: true # fork and run in background
pidFilePath: /opt/mongo/mongod.pid # location of pidfile
# network interfaces
net:
port: 27017
bindIp: 127.0.0.1,10.45.13.133 # Listen to local interface only, comment to listen on all interfaces.
#security:
#operationProfiling:
#replication:
replication:
oplogSizeMB: 5000
replSetName: rs0
#sharding:
## Enterprise-Only Options
#auditLog:
#snmp:
#########################################################################
,
ps -ef|grep -v "grep\|tail"|grep mongo|awk '{print $2}'|xargs kill -15
rm -f /tmp/mongodb-27017.sock
rm -rf /opt/mongo/*
rm -f /opt/mongo/WiredTiger.turtle
sync
echo "1" >/proc/sys/vm/drop_caches
echo "0" >/proc/sys/vm/drop_caches
mongod -f /etc/mongod.conf
tail -f /bak/logs/mongo/mongod.log
owl8 10.45.13.133
owl5 10.45.12.205
owl6 10.45.12.196
# admin
use admin
config = {_id:"rs0",members:[
{_id:0,host:"10.45.13.133:27017"},
{_id:1,host:"10.45.12.205:27017"},
{_id:2,host:"10.45.12.196:27017"}]}
#monogo mongod
#
rs.initiate(config);
rs.conf() #
rs.status()
state: 1 ,2
health: 1 ,0
, Primary
rs.remove("10.172.229.12:27017")
rs.add("10.172.229.12:27017")
replSetStepDown 。
db.adminCommand({replSetStepDown : 1})
Mongodb 215
, 60 . ,
rs.stepDown()
rs.stepDown(600) , 600
db.adminCommand({replSetStepDown : 1, force : true})
rs.freeze , , freeze,
rs.freeze(600)
rs.freeze(0) , , rs.freeze(0)
mongodb oplog size
,oplog 64 5% 。
oplog
rs0:PRIMARY>db.printReplicationInfo()
,
rs0:SECONDARY> db.printSlaveReplicationInfo()
Mongos Config ##################################
#
mongos
mongo --port 20000
use admin
db.runCommand( { addshard : "rs0/10.45.13.133:27017,10.45.12.205:27017,10.45.12.196:27017"});
sh.addShard("rs0/10.45.13.133:27017,10.45.12.205:27017,10.45.12.196:27017")
Arbiter
{_id:2,host:"10.45.12.196:27017",arbiterOnly:true}]}
#
use admin
db.runCommand( { listshards : 1 } );
sh.status()
############################### Replica-Set ##################################
############################### ##################################
http://webinglin.github.io/2015/06/10/MongoDB - - /
https://docs.mongodb.org/manual/tutorial/choose-a-shard-key/
config Server
10.172.229.12:27000
mongos
10.172.229.12:28000
shards
10.172.229.12:29001
10.172.229.12:29002
10.172.229.12:29003
:
mkdir -p /opt/shard/s1
mkdir -p /opt/shard/s2
mkdir -p /opt/shard/s3
mkdir -p /opt/shard/log
mkdir -p /opt/shard/config
: configServer
mongod --configsvr --dbpath /opt/shard/config/ --fork --logpath /opt/shard/log/configsvr.log --logappend --port 27000
: mongos
mongos --configdb 10.172.229.12:27000 --port 28000 --fork --logpath /opt/shard/log/mongs.log
: shard
mongod --dbpath /opt/shard/s1/ --port 29001 --fork --logpath /opt/shard/log/s1.log --shardsvr --logappend
mongod --dbpath /opt/shard/s2/ --port 29002 --fork --logpath /opt/shard/log/s2.log --shardsvr --logappend
mongod --dbpath /opt/shard/s3/ --port 29003 --fork --logpath /opt/shard/log/s3.log --shardsvr --logappend
: shard mongos
mongo --port 28000
# admin
use admin
sh.addShard("10.172.229.12:29001")
sh.addShard("10.172.229.12:29002")
sh.addShard("10.172.229.12:29003")
sh.enableSharding("test")
sh.shardCollection("test.users",{"username":1,"_id":1})
mongos 100 , db.users.stats() , , ,
( sharding key , shard key , , 。)
for(var i=0; i<100; i++) {
db.users.insert({"username":"" + i,age:i*2 , addr:"ardr"+i})
}
db.users.stats()
mongo 29001 , 29002, 29003 ,
############################### ##################################
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.