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
[email protected] etc]# cat mongo_2701
Mongo_27017.conf mongo_27018.conf
[email protected] 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 ()
Adding nodes
Rs.add (' 192.168.0.111:27018 ')
[Email protected] 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"}
This article is from the "12104515" blog, please be sure to keep this source http://12114515.blog.51cto.com/12104515/1856809
MongoDB Replica set creation