第2关:MongoDB 复制集搭建
mkdir -p /data/test/db1 /data/test/db2 /data/test/db3
mkdir -p /logs/test
touch { /logs/test/mongod1.log /logs/test/mongod2.log /logs/test/mongod3.log }
mkdir -p /etc/test
touch { /etc/test/mongod1.conf /etc/test/mongod2.conf /etc/test/mongod3.conf }
vim /etc/test/mongod1.conf
port=20001
dbpath=/data/test/db1
logpath=/logs/test/mongod1.log
logappend=true
fork=true
replSet=YOURMONGO
vim /etc/test/mongod2.conf
port=20002
dbpath=/data/test/db2
logpath=/logs/test/mongod2.log
logappend=true
fork=true
replSet=YOURMONGO
vim /etc/test/mongod3.conf
port=20003
dbpath=/data/test/db3
logpath=/logs/test/mongod3.log
logappend=true
fork=true
replSet=YOURMONGO
mongod -f /etc/test/mongod1.conf
mongod -f /etc/test/mongod2.conf
mongod -f /etc/test/mongod3.conf
mongo --port 20001
config = {
_id:"YOURMONGO",
members:[
{_id:0,host:'127.0.0.1:20001'},
{_id:1,host:'127.0.0.1:20002',arbiterOnly:true},
{_id:2,host:'127.0.0.1:20003'},
]
}
rs.initiate(config)
第3关:MongoDB 分片集搭建
mkdir -p /data/test2/shard1/db
mkdir -p /logs/test2/shard1/log
mkdir -p /data/test2/shard2/db
mkdir -p /logs/test2/shard2/log
mkdir -p /data/test2/shard3/db
mkdir -p /logs/test2/shard3/log
mkdir -p /data/test2/config/db
mkdir -p /logs/test2/config/log
mkdir -p /logs/test2/mongs/log
mkdir -p /etc/test2
vim /etc/test2/mongod1.conf
dbpath=/data/test2/shard1/db
logpath=/logs/test2/shard1/log/mongodb.log
port=21001
shardsvr=true
fork=true
vim /etc/test2/mongod2.conf
dbpath=/data/test2/shard2/db
logpath=/logs/test2/shard2/log/mongodb.log
port=21002
shardsvr=true
fork=true
vim /etc/test2/mongod3.conf
dbpath=/data/test2/shard3/db
logpath=/logs/test2/shard3/log/mongodb.log
port=21003
shardsvr=true
fork=true
mongod -f /etc/test2/mongod1.conf
mongod -f /etc/test2/mongod2.conf
mongod -f /etc/test2/mongod3.conf
mongod --dbpath /data/test2/config/db --logpath /logs/test2/config/log/mongodb.log --port 21004 --configsvr --replSet cs --fork
mongo localhost:21004
use admin;
cfg = {
_id:'cs',
configsvr:true,
members:[
{_id:0,host:'localhost:21004'}
]
};
rs.initiate(cfg);
exit
mongos --configdb cs/localhost:21004 --logpath /logs/test2/mongs/log/mongodb.log --port 21005 --fork
mongo localhost:21005
sh.addShard('localhost:21001');
sh.addShard('localhost:21002');
sh.addShard('localhost:21003');
sh.status();
db.collection.dropIndexes()