vi install_mongo.sh

tar -zxvf mongodb-linux-x86_64-rhel62-3.2.9.tgz

mv mongodb-linux-x86_64-rhel62-3.2.9 /usr/local/mongo

cat>>/etc/profile<<EOF

export PATH=/usr/local/mongo/bin:$PATH

EOF

source /etc/profile



mongotest1


vi start27017.sh

mkdir /opt/mongo1_1

cat >>/etc/mongo_27017.conf<<EOF

port=27017

fork=true

storageEngine=wiredTiger

dbpath=/opt/mongo1_1

logpath=/opt/mongo1_1/mongo.log

wiredTigerDirectoryForIndexes=true

wiredTigerCacheSizeGB=0.3

logappend=true

replSet=rs1

oplogSize=100

EOF

mongod -f /etc/mongo_27017.conf


[root@mongotest3 etc]# cat mongo_2701

mongo_27017.conf  mongo_27018.conf  

[root@mongotest3 etc]# cat mongo_27018.conf 

port=27018

fork=true

storageEngine=mmapv1

dbpath=/opt/mongo1_2

logpath=/opt/mongo1_2/mongo.log

replSet=rs1

logappend=true

oplogSize=100







cfg = { _id: "rs1", members:[

          { _id : 0, host : "192.168.0.109:27017"},

          { _id : 1, host : "192.168.0.110:27017"},

          { _id : 2, host : "192.168.0.111:27017"} ]

};

rs.initiate(cfg);


use online

db.test1.insert({name:'aaa'})

db.test1.find()



添加节点

rs.add('192.168.0.111:27018')



[root@mongotest3 opt]# mongo --port 27018

rs1:SECONDARY> use admin

switched to db admin

rs1:SECONDARY> use online

switched to db online

rs1:SECONDARY> rs.slaveOk()

rs1:SECONDARY> db.test1.find()

{ "_id" : ObjectId("57e943faff931e363a5a0309"), "name" : "aaa" }