下载mongodb,http://www.mongodb.org/downloads
安装:
声明:本文主从配在一台机子上
- #tar -zxvf mongodb-2.2.tar.gz
- #mv mongodb-linux-x86_64-static-legacy-2.0.6/ /usr/local/mongodb
- #cd /usr/local/mongodb
- #mkdir -p data/db_master
- #mkdir data/db_slave
- #mkdir log
- #cd bin
- #vim mongod_master.conf
- dbpath = /usr/local/mongodb/data/db_master
- logpath = /usr/local/mongodb/log/mongodb_master.log
- port = 13600
- bind_ip = 192.168.1.102,127.0.0.1
- logappend = true
- fork = true
- directoryperdb = true
- nohttpinterface = true
- oplogSize = 1024
- master = true
- noauth = true
- only = stock
- #vim mongod_slave.conf
- dbpath = /usr/local/mongodb/data/db_slave
- logpath = /usr/local/mongodb/log/mongodb_slave.log
- port = 13700
- bind_ip = 192.168.1.102,127.0.0.1
- logappend = true
- fork = true
- directoryperdb = true
- nohttpinterface = true
- oplogSize = 1024
- slave = true
- noauth = true
- source = 192.168.1.102:13600
- # /usr/local/mongodb/bin/mongod -f /usr/local/mongodb/bin/mongod_master.conf
- # /usr/local/mongodb/bin/mongod -f /usr/local/mongodb/bin/mongod_slave.conf
Wed Mar 27 15:37:07 ERROR: Client::~Client _context should be null but is not; client:replslave
查看主从是否启动:会看到四个mongo
- #netstat -tlupn | grep mongo
自此安装完毕。
二。检查主从工作
登录主,插入数据:
- #/usr/local/mongodb/bin/mongo --port 13600
- > use test
- > db.blog.save({title:"new test"})
- > exit
- #/usr/local/mongodb/bin/mongo --port 13700
- > use test
- > db.blog.find()
- { "_id" : ObjectId("5152bc3f25dc5817713accce"), "title" : "new test" } ###显示这行,表示同步成功