今天刚配了一个mongodb主从,配置如下:
master:
/usr/local/mongodb/bin/mongod –fork –port 40000 –dbpath /u01/mongodata/db/geomaster/ –logpath /u01/mongodata/log/geomaster.log –logappend –master –auth
slave:
/usr/local/mongodb/bin/mongod –fork –port 40000 –slave –source 1.1.1.1:40000 –dbpath /u01/mongodata/db/geoslave/ –logpath /u01/mongodata/log/geosalve.log –logappend –auth
然后我在master上更新了一下admin的密码,但是slave没有同步过去。操作如下:
/usr/local/mongodb/bin/mongo –port 40000 admin -u admin -pMongoDB shell version: 2.2.0
Enter password:
connecting to: 127.0.0.1:40000/admin
> use admin
switched to db admin
> show users
{
“_id” : ObjectId(“50f60fe6179b01ee8f3e6c60”),
“user” : “admin”,
“readOnly” : false,
“pwd” : “859ab375317685a04d8d8ecf80222350”
}
> db.system.users.remove({user:’admin’})
> show users
> db.addUser(‘admin’,’new-password’)
{
“user” : “admin”,
“readOnly” : false,
“pwd” : “2f8ecfc89f3153c9203c189eadb7fa45”,
“_id” : ObjectId(“50f61888c26232c510edae56”)
}
> db.auth(‘admin’,’jiayuan.com2013!@#’)
1
在slave上查看mongodb日志,发现有如下报错信息:
repl:Wed Jan 16 11:24:51 [replslave] repl: sleep 3 sec before next pass
Wed Jan 16 11:24:54 [replslave] repl: syncing from host:10.1.2.87:40000
Wed Jan 16 11:24:54 [replslave] replauthenticate: no user in local.system.users to use for authentication
repl:
Wed Jan 16 11:24:54 [replslave] repl: sleep 3 sec before next pass
Wed Jan 16 11:24:57 [replslave] repl: syncing from host:10.1.2.87:40000
Wed Jan 16 11:24:57 [replslave] replauthenticate: no user in local.system.users to use for authentication
repl:
Wed Jan 16 11:24:57 [replslave] repl: sleep 3 sec before next pass
Wed Jan 16 11:25:00 [replslave] repl: syncing from host:10.1.2.87:40000
Wed Jan 16 11:25:00 [replslave] replauthenticate: no user in local.system.users to use for authentication
repl:
Wed Jan 16 11:25:00 [replslave] repl: sleep 3 sec before next pass
Wed Jan 16 11:25:03 [replslave] repl: syncing from host:10.1.2.87:40000
Wed Jan 16 11:25:03 [replslave] replauthenticate: no user in local.system.users to use for authentication
这是因为:如果我们要启用Master/Slave模式,而且开启了Auth功能,则需要同时在Master和Slave上的local数据库上增加一个repl的用户。
配置如下:
use local
db.addUser(‘repl’,’replication’)
添加完用户之后,主从同步就正常了。