mongodb副本集加上权限校验后java客户端连接不上

彭小位 发布于 2017/02/22 14:09
阅读 392
收藏 0

mongodb副本集,不加权限校验的时候客户端连接是没有问题的,加上权限校验后,就报如下异常:

Caused by: com.mongodb.MongoException$Network: IOException authenticating the connection
    at com.mongodb.DBPort$NativeAuthenticator.authenticate(DBPort.java:661)
    at com.mongodb.DBPort.authenticate(DBPort.java:370)
    at com.mongodb.DBPort.checkAuth(DBPort.java:381)
    at com.mongodb.DBTCPConnector.innerCall(DBTCPConnector.java:299)
    at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:279)
    at com.mongodb.DBCollectionImpl.find(DBCollectionImpl.java:84)
    at com.mongodb.DB.command(DB.java:317)
    at com.mongodb.DB.command(DB.java:296)
    at com.mongodb.DBCollection.getCount(DBCollection.java:1189)
    at com.mongodb.DBCollection.getCount(DBCollection.java:1154)
    at com.mongodb.DBCollection.getCount(DBCollection.java:1138)
    at com.mongodb.DBCollection.getCount(DBCollection.java:1107)
    at com.mongodb.DBCollection.getCount(DBCollection.java:1066)
    at cn.sunline.ltts.base.ftp.TestDemo.test(TestDemo.java:90)
    ... 25 more
Caused by: java.net.SocketException: Connection reset
    at java.net.SocketInputStream.read(SocketInputStream.java:196)
    at java.net.SocketInputStream.read(SocketInputStream.java:122)
    at java.io.BufferedInputStream.fill(BufferedInputStream.java:235)
    at java.io.BufferedInputStream.read1(BufferedInputStream.java:275)
    at java.io.BufferedInputStream.read(BufferedInputStream.java:334)
    at org.bson.io.Bits.readFully(Bits.java:48)
    at org.bson.io.Bits.readFully(Bits.java:35)
    at org.bson.io.Bits.readFully(Bits.java:30)
    at com.mongodb.Response.<init>(Response.java:42)
    at com.mongodb.DBPort$1.execute(DBPort.java:141)
    at com.mongodb.DBPort$1.execute(DBPort.java:135)
    at com.mongodb.DBPort.doOperation(DBPort.java:164)
    at com.mongodb.DBPort.call(DBPort.java:135)
    at com.mongodb.DBPort.findOne(DBPort.java:189)
    at com.mongodb.DBPort.runCommand(DBPort.java:197)
    at com.mongodb.DBPort$NativeAuthenticator.authenticate(DBPort.java:653)
    ... 38 more

 

mongodb服务端版本为:mongodb-linux-x86_64-rhel62-3.2.7

java客户端使用的版本为:mongo-java-driver-2.12.1.jar

 

我要上传文件导名为mongodb的库,在这个库中用户都建了,但是就是报错

这是客户端测试代码:

ServerAddress sa = new ServerAddress("172.18.50.113:27017");
            ServerAddress sa1 = new ServerAddress("172.18.50.114:27017");
            
            List<ServerAddress> sends = new ArrayList<ServerAddress>();
            sends.add(sa);
            sends.add(sa1);
            List<MongoCredential> mongoCredentialList = new ArrayList<MongoCredential>();
            mongoCredentialList.add(MongoCredential.createMongoCRCredential("common", "mongodb", "common".toCharArray()));
            DB db = new MongoClient(sends, mongoCredentialList).getDB("mongodb");
            DBCollection collection = db.getCollection("phfund_ds.datas");
            System.out.println(collection.getCount());

 

请问有哪位大虾知道为什么吗?求赐教!

加载中
0
Kit_lee
Kit_lee

Credential的帐密是否对?

返回顶部
顶部