mongodb (master/slave) 主从复制

在mongodb1.6之后就不在推荐使用mongodb的主从复制而是推荐使用Replica Set (副本集),但是在一定条件主从复制还是比较好用,在前期数据量很低的情况是很好的选择。


1.首先配置master服务器:

#r0.conf
dbpath=/sdb1/liujijun/data/data/r0/
logpath=/sdb1/liujijun/data/log/r0.log
#ikeyFile=/sdb1/liujijun/data/key/r0
#upgrade=true
port=28010
oplogSize=500
directoryperdb=true
#replSet=rs1
master=true
fork=true
auth=true
logappend=true
maxConns=800


2:配置slave服务器:

#r1.conf
dbpath=/home/mongodb/data/
logpath=/home/mongodb/log/log.log
port=28015
directoryperdb=true
source=192.168.0.8:28010
oplogSize=100
auth=true
slave=true
fork=true
logappend=true
maxConns=800


然后分别启动主从服务器就可以了。


关于安全:

这是mongodb的官网上的介绍:

Security

When security is enabled, one must configure a user account for the local database that exists on both servers.

The slave-side of a replication connection first looks for a user repl in local.system.users. If present, that user is used to authenticate against the local database on the source side of the connection. If repl user does not exist, the first user object in local.system.users is tried.

The local database works like the admin database: an account for local has access to the entire server.

Example security configuration when security is enabled:

$ mongo <slavehostname>/admin -u <existingadminusername> -p<adminpassword>
> use local
> db.addUser('repl', <replpassword>);
^c
$ mongo <masterhostname>/admin -u <existingadminusername> -p<adminpassword>
> use local
> db.addUser('repl', <replpassword>);
需要在主从的local数据库下建立一致的用户名和密码。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值