一。mongodb安装
下载mongodb,
安装:
声明:本文主从配在一台机子上
-
#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
配置主从配置文件:(配置文件中各个参数不明白的,建议
/usr/local/mongodb/bin/mongod -h查询
-
#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
如果出现一下情况:建议删除从下面数据文件,就是删除
db_slave下的所有文件
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" } ###显示这行,表示同步成功
阅读(3420) | 评论(0) | 转发(1) |