日期:2014-05-16  浏览次数:20414 次

mongo安装命令笔记

/usr/sbin/setsebool -P httpd_can_network_connect 1

?

mkdir -p /home/mongodb/data/shard11

mkdir -p /home/mongodb/data/shard21

?

mkdir -p /home/mongodb/data/shard12

mkdir -p /home/mongodb/data/shard22

?

mkdir -p /home/mongodb/data/shard13

mkdir -p /home/mongodb/data/shard23

?

./mongod -shardsvr -replSet shard1 -port 27017 -dbpath /home/mongodb/data/shard11 -oplogSize 100 -logpath /home/mongodb/data/shard11.log -logappend -fork

./mongod -shardsvr -replSet shard1 -port 27017 -dbpath /home/mongodb/data/shard12 -oplogSize 100 -logpath /home/mongodb/data/shard12.log -logappend -fork

./mongod -shardsvr -replSet shard1 -port 27017 -dbpath /home/mongodb/data/shard13 -oplogSize 100 -logpath /home/mongodb/data/shard13.log -logappend -fork

?

?

./mongo -port 27017

?

config = {_id: 'shard1', members: [

{_id: 0, host: '192.168.12.249:27017'},

{_id: 1, host: '192.168.12.247:27017'},

{_id: 2, host: '192.168.12.245:27017'}]

}

rs.initiate(config)

rs.status()

?

./mongod -shardsvr -replSet shard2 -port 27018 -dbpath /home/mongodb/data/shard21 -oplogSize 100 -logpath /home/mongodb/data/shard21.log -logappend -fork

./mongod -shardsvr -replSet shard2 -port 27018 -dbpath /home/mongodb/data/shard22 -oplogSize 100 -logpath /home/mongodb/data/shard22.log -logappend -fork

./mongod -shardsvr -replSet shard2 -port 27018 -dbpath /home/mongodb/data/shard23 -oplogSize 100 -logpath /home/mongodb/data/shard23.log -logappend -fork

?

./mongo -port 27018

?

config = {_id: 'shard2', members: [

{_id: 0, host: '192.168.12.249:27018'},

{_id: 1, host: '192.168.12.247:27018'},

{_id: 2, host: '192.168.12.245:27018'}]

}

rs.initiate(config)

rs.status()

?

?

mkdir -p /home/mongodb/data/config

./mongod -configsvr -dbpath /home/mongodb/data/config -port 20000 -logpath /home/mongodb/data/config.log -logappend -fork

./mongos -configdb 192.168.12.249:20000,192.168.12.247:20000,192.168.12.245:20000 -port 30000 -chunkSize 1 -logpath /home/mongodb/data/mongos.log -logappend -fork

hunkSize参数用来设置chunk块的大小,这里为了测试,设置成1M

?

./mongo 192.168.12.249:30000/admin

?

db.runCommand({addshard:"shard1/192.168.12.249:27017,192.168.12.247:27017,192.168.12.245:27017",name:"s1",maxsize:20480});

db.runCommand({addshard:"shard2/192.168.12.249:27018,192.168.12.247:27018,192.168.12.245:27018",name:"s2",maxsize:20480});

?

db.runCommand({listshards:1})

?

db.runCommand({enablesharding:'test'})

db.runCommand({shardcollection:"test.c1",key : {_id: 1} , unique : true} )

for (var i = 1; i <= 30000; i++) db.c1.save({_id:i,value1:"1234567890",value2:"1234567890",value3:"1234567890",value4:"1234567890"})

?

./mongoimport -d "testimport6" -c "foo" -f "file1,file2,file3,file4,file5,file6,file7,file8,file9,file10,file11,file12,file13,file14,file15,file16,file17" -type=csv -file=/home/*.log