yapi连接mongodb集群

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/qq_36742720/article/details/99682114

首先是官方文档:

https://hellosean1025.github.io/yapi/devops/index.html

我的数据库集群信息如下:

副本集名称:yapi01
IP列表:
    10.142.***.**:28005,
    10.142.***.**:28005,
    10.142.***.**:28005
authDB:***
用户名:yapi_rw
密码:********
库:yapi

然后在yapi中的config.json中的配置信息如下:

{
   "port": "9090",
   "closeRegister": false,
   "adminAccount": "zhangsan@163.com",
   "db": {
      "connectString": "mongodb://10.142.***.**:28005,10.142.***.**:28005,10.142.***.**:28005/yapi?authSource=[authDB]&replicaSet=yapi01&slaveOk=true",
      "user": "yapi_rw",
      "pass": "********"
   },
}

这样,就能够成功连接上了。

要注意的是:authSource参数值对应的是authDB中的值,replicaSet的值对应的是副本集名称,slaveOk默认为true就行。

展开阅读全文

mongodb连接集群的疑问................

09-14

情况描述如下:rn1、用集群连接方式创建mongodb连接rnList seeds = new ArrayList<>();rn for(String h : host_list)rn ServerAddress sa = new ServerAddress(h,port);rn seeds.add(sa);rn rn MongoOptions opt = new MongoOptions();rn opt.connectionsPerHost = poolSize;rn opt.threadsAllowedToBlockForConnectionMultiplier = blockSize;rn mg = new Mongo(seeds, opt); rnrn2、其中一个ip是虚假的,为了测试集群连接方式能够正常工作。rn3、验证登录rndb_con.authenticate(user, password.toCharArray());rnrn问题所在:rn如果用debug模式,手动跟踪代码,在有ip无效的情况下,验证能正常通过,能进行下面的mongodb操作。rn但是如果正常执行,验证不通过,会提示mongodb所操作的集合需要认证。如下rncom.mongodb.MongoException: Rare case where master=null, probably all servers are downrn at com.mongodb.DBTCPConnector$MyPort.get(DBTCPConnector.java:438)rn at com.mongodb.DBTCPConnector.innerCall(DBTCPConnector.java:280)rn at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:257)rn at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:310)rn at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:295)rn at com.mongodb.DBCursor._check(DBCursor.java:368)rn at com.mongodb.DBCursor._hasNext(DBCursor.java:459)rn at com.mongodb.DBCursor.hasNext(DBCursor.java:484)rn at com.hw.jgpt.mongo.SimpleTest.main(SimpleTest.java:98)rnrn如果在 mg = new Mongo(seeds, opt); 这句话之后加上休眠语句,会报错:rncom.mongodb.MongoException: not authorized for query on ************************rn at com.mongodb.MongoException.parse(MongoException.java:82)rn at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:314)rn at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:295)rn at com.mongodb.DBCursor._check(DBCursor.java:368)rn at com.mongodb.DBCursor._hasNext(DBCursor.java:459)rn at com.mongodb.DBCursor.hasNext(DBCursor.java:484)rn at com.hw.jgpt.mongo.SimpleTest.main(SimpleTest.java:98)rnrnrn 论坛

没有更多推荐了,返回首页