mongodb root用户创建数据库提示not master
问题如题
问题也比较简单, 就是master挂了
mongodb的集群似乎和mysql,redis的不太一样,这个我也不太清楚
总之单机不会出现这种情况,集群会出现
解决方法
就是将master重启就可以了
mongodb "errmsg" : "not master and slaveok=false"的解决
是正常的,因为secondary是不允许读写的,如果非要解决执行 rs.slaveok() 这句命令就可以了
[yukw@mongodb4 data]$ ./mongo -port 20000
mongodb shell version v3.4.4
connecting to: mongodb://127.0.0.1:20000/
mongodb server version: 3.4.4
server has startup warnings:
2019-07-31t17:06:43.397+0800 i control [initandlisten]
2019-07-31t17:06:43.397+0800 i control [initandlisten] ** warning: access control is not enabled for the database.
2019-07-31t17:06:43.398+0800 i control [initandlisten] ** read and write access to data and configuration is unrestricted.
2019-07-31t17:06:43.398+0800 i control [initandlisten]
2019-07-31t17:06:43.398+0800 i control [initandlisten]
2019-07-31t17:06:43.398+0800 i control [initandlisten] ** warning: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2019-07-31t17:06:43.398+0800 i control [initandlisten] ** we suggest setting it to 'never'
2019-07-31t17:06:43.398+0800 i control [initandlisten]
2019-07-31t17:06:43.398+0800 i control [initandlisten] ** warning: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2019-07-31t17:06:43.398+0800 i control [initandlisten] ** we suggest setting it to 'never'
2019-07-31t17:06:43.398+0800 i control [initandlisten]> show users
2019-07-31t17:07:33.469+0800 e query [thread1] error: not master and slaveok=false :
_geterrorwithcode@src/mongo/shell/utils.js:25:13
db.prototype.getusers@src/mongo/shell/db.js:1537:1
shellhelper.show@src/mongo/shell/utils.js:752:9
shellhelper@src/mongo/shell/utils.js:659:15
@(shellhelp2):1:1
> show dbs
2019-07-31t17:07:39.126+0800 e query [thread1] error: listdatabases failed:{
"ok" : 0,
"errmsg" : "not master and slaveok=false", ##报错提示
"code" : 13435,
"codename" : "notmasternoslaveok"
} :
_geterrorwithcode@src/mongo/shell/utils.js:25:13
mongo.prototype.getdbs@src/mongo/shell/mongo.js:62:1
shellhelper.show@src/mongo/shell/utils.js:769:19
shellhelper@src/mongo/shell/utils.js:659:15
@(shellhelp2):1:1
> rs.slaveok(); ##执行命令
> show dbs
local 0.000gb
> show users
>
好了,这就是解决not master and slaveok=false的方法了
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持代码网。
发表评论