简体   繁体   English

如何使用spring boot配置rancher mongodb集群?

[英]How can I configure rancher mongodb cluster with spring boot?

I have mongodb replicasets added as a stack in rancher. 我在牧场主中添加了mongodb replicasets作为堆栈。

I have configured link to the service as mongodb. 我已将服务的链接配置为mongodb。 But whenever I connected to database in spring boot application I got this exception: 但每当我在spring boot应用程序中连接到数据库时,我都会遇到以下异常:

    7/5/2016 6:57:24 AMcom.mongodb.MongoException: not talking to master and retries used up
    7/5/2016 6:57:24 AM at com.mongodb.DBTCPConnector.innerCall(DBTCPConnector.java:323) ~[mongo-java-driver-2.14.2.jar!/:na]
    7/5/2016 6:57:24 AM at com.mongodb.DBTCPConnector.innerCall(DBTCPConnector.java:325) ~[mongo-java-driver-2.14.2.jar!/:na]
    7/5/2016 6:57:24 AM at com.mongodb.DBTCPConnector.innerCall(DBTCPConnector.java:325) ~[mongo-java-driver-2.14.2.jar!/:na]
    7/5/2016 6:57:24 AM at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:273) ~[mongo-java-driver-2.14.2.jar!/:na]
    7/5/2016 6:57:24 AM at com.mongodb.DBCollectionImpl.find(DBCollectionImpl.java:86) ~[mongo-java-driver-2.14.2.jar!/:na]
    7/5/2016 6:57:24 AM at com.mongodb.DBCollectionImpl.find(DBCollectionImpl.java:68) ~[mongo-java-driver-2.14.2.jar!/:na]
    7/5/2016 6:57:24 AM at com.mongodb.DBCursor._check(DBCursor.java:498) ~[mongo-java-driver-2.14.2.jar!/:na]
    7/5/2016 6:57:24 AM at com.mongodb.DBCursor._hasNext(DBCursor.java:621) ~[mongo-java-driver-2.14.2.jar!/:na]
    7/5/2016 6:57:24 AM at com.mongodb.DBCursor.hasNext(DBCursor.java:657) ~[mongo-java-driver-2.14.2.jar!/:na]
    7/5/2016 6:57:24 AM at org.springframework.data.mongodb.core.MongoTemplate.executeFindMultiInternal(MongoTemplate.java:1943) ~[spring-data-mongodb-1.9.1.RELEASE.jar!/:na]

Do I need to add any other configuration in my spring boot application to make it work. 我是否需要在Spring启动应用程序中添加任何其他配置才能使其正常工作。 Thank you very much. 非常感谢你。

Do these changes, then it will work. 做这些改变,然后它会工作。

  1. Pass the complete replica set string while connecting to the mongodb, do not pass an individual server IP 连接到mongodb时传递完整的副本集字符串,不要传递单个服务器IP
  2. Change the readPreferance to PrimaryPrefferred, instead of Primary only. 将readPreferance更改为PrimaryPrefferred,而不是仅限Primary。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM