【问题标题】:Jelastic connection to MongoDB Not working On Remote tomcat but ok when Local tomcat connect to remote Mongo与 MongoDB 的 Jelastic 连接在远程 tomcat 上不起作用,但在本地 tomcat 连接到远程 Mongo 时正常
【发布时间】:2015-01-08 22:51:02
【问题描述】:

我在 Jelastic 上有一个环境,他们的支持无法提供帮助:P

我使用 java 8 和 MongoDB 2.6.4 设置 Tomcat 7.0.55 对于 mongo,我还设置了一个外部 ip,以便我可以从本地 tomcat 访问。

这里发生了什么, 我能够运行我的本地 Tomcat 和 Jelastic 远程 Mongo DB 但是部署后,我从远程 mongo 获取此日志

2015-01-07T22:57:29.637+0000 [conn22208]  authenticate db: easylend {authenticate: 1, user: "cre8tech", nonce: "xxx", key: "xxx" }
2015-01-07T22:57:29.638+0000 [conn22208] Failed to authenticate cre8tech@easylend with mechanism MONGODB-CR: AuthenticationFailed keymismatch

我 1000% 确定凭证是正确的,因此该方法用于记录,因为我可以在本地使用它到他们的远程 mongo + 我可以通过使用来访问它

mongo XXXX.whelastic.net/{myDbName} --username {username} --password {password}

@Bean
@Override
public Mongo mongo() throws Exception {
    ServerAddress serverAdress = new ServerAddress(host, Integer.parseInt(port));  
    Mongo mongo = null;
    if (usr != null && !usr.isEmpty()) {
        MongoCredential credential = MongoCredential.createMongoCRCredential(usr, database, pwd.toCharArray());
        mongo = new MongoClient(serverAdress, Arrays.asList(credential));

    } else {
        mongo = new MongoClient(serverAdress);
    }

    mongo.setWriteConcern(WriteConcern.SAFE);

    return mongo;
}

tomcat的登录只是说不能认证

com.mongodb.CommandFailureException: { "serverUsed" : "********" , "code" : 18 , "ok" : 0.0 , "errmsg" : "auth fails"}

我的理论是远程 Jelastic tomcat 可能包含一些干扰我使用的 mongo 驱动程序的 jar/libs

感谢您的帮助

【问题讨论】:

    标签: java mongodb tomcat authentication jelastic


    【解决方案1】:

    无需再搜索 我发现了问题

    Jelastic 上的 tomcat 继承自一些 linux 命令,例如 pwd,用于显示当前目录 我在我的财产中使用 pwd 来检索密码。 它不应该发生冲突,但它确实发生了,我将 /opt/tomcat 作为密码而不是我的密码

    这可能是您最终需要修复的问题,因此这些变量不会与文件属性混合

    解决方法是使用不同的属性名称

    同样适用于 Amazon beanstalk

    谢谢

    【讨论】:

      猜你喜欢
      • 2018-07-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-17
      • 1970-01-01
      相关资源
      最近更新 更多