标签:l数据库 dmi bow 资料 master Owner 建立 mod ODB
master配置本机 :192.168.100.23:27017
/etc/mongodb/mongo.conf
port = 27017
dbpath = /data/mongodb_t
logpath = /var/log/mongodb_t.log
logappend = true
journal = true
fork = true
据资料, 必须建立全局用户root,个人感觉是超级管理员; 必须对local数据库建立repl用户。
mongo –port 27017
> use admin > db.createUser({user:"root", pwd:"123456", roles:[{role:"root", db:"admin"}]}) > db.createUser({user:"repl", pwd:"123456", roles:[{role:"dbOwner", db:"local"}]}) > show users { "_id" : "admin.root", "user" : "root", "db" : "admin", "roles" : [ { "role" : "root", "db" : "admin" } ] } { "_id" : "admin.repl", "user" : "repl", "db" : "admin", "roles" : [ { "role" : "dbOwner", "db" : "local" } ] } >exit12345678910111213141516171819202122232425262728
添加以下三项:
port = 27017
dbpath = /data/mongodb_t
logpath = /var/log/mongodb_t.log
keyFile=/srv/mongodb/keyfile
logappend = true
journal = true
fork = true
keyFile=/srv/mongodb/keyfile #添加keyfile
auth = true #打开认证
master = true #打开主库配置
主要目的是对主从之间的验证
cd /srv/mongodb/
openssl rand -base64 741 >>keyfile
chmod 700 keyfile
本机:与主库不再同一台设备上面,同一局域网
/etc/mongodb/mongo.conf
port = 27017
dbpath = /data/mongodb_t
logpath = /logs/mongo/mongodb_t.log
logappend = true
journal = true
fork = true
port = 27017
dbpath = /data/mongodb_t
logpath = /logs/mongo/mongodb_t.log
logappend = true
journal = true
fork = true
auth = true
slave = true
keyFile=/srv/mongodb/keyfile
source = 192.168.100.23:27017
cd /srv/mongodb/
将主库设备上面的keyfile拷贝到这个目录下
chmod 700 keyfile
重启之后,登陆数据库,就能看到与主库的同步了
如果shell登陆, 需要
rs.slaveOk()
mongodb 在认证(auth)的情况下,配置主从(master & slave)
标签:l数据库 dmi bow 资料 master Owner 建立 mod ODB
原文地址:http://blog.51cto.com/13833333/2133232