问题
I try to connect to a Couchbase server on the intranet. For this purpose, I use the Java SDK and the following configuration:
CouchbaseEnvironment couchbaseEnvironment = DefaultCouchbaseEnvironment.builder()
.queryEnabled(true)
.queryPort(11210)
.build();
Cluster cluster = CouchbaseCluster.create(couchbaseEnvironment, "192.168.1.150");
Bucket bucket = cluster.openBucket("mybucket");
However, this just leaves me with lots of errors on the console:
INFO [2015-03-30 14:03:07,306] org.eclipse.jetty.util.log: Logging initialized @1805ms
INFO [2015-03-30 14:03:07,605] com.couchbase.client.core.CouchbaseCore: CoreEnvironment: {sslEnabled=false, sslKeystoreFile='null', sslKeystorePassword='null', queryEnabled=true, queryPort=11210, bootstrapHttpEnabled=true, bootstrapCarrierEnabled=true, bootstrapHttpDirectPort=8091, bootstrapHttpSslPort=18091, bootstrapCarrierDirectPort=11210, bootstrapCarrierSslPort=11207, ioPoolSize=4, computationPoolSize=4, responseBufferSize=16384, requestBufferSize=16384, kvServiceEndpoints=1, viewServiceEndpoints=1, queryServiceEndpoints=1, ioPool=NioEventLoopGroup, coreScheduler=CoreScheduler, eventBus=DefaultEventBus, packageNameAndVersion=couchbase-java-client/2.1.1 (git: 2.1.1), dcpEnabled=false, retryStrategy=BestEffort, maxRequestLifetime=75000, retryDelay=com.couchbase.client.core.time.ExponentialDelay@11bd803, reconnectDelay=com.couchbase.client.core.time.ExponentialDelay@58f07f02, observeIntervalDelay=com.couchbase.client.core.time.ExponentialDelay@75798d03, keepAliveInterval=30000, autoreleaseAfter=2000}
INFO [2015-03-30 14:03:16,004] com.couchbase.client.core.node.Node: Connected to Node 192.168.1.150
INFO [2015-03-30 14:03:16,367] com.couchbase.client.core.config.ConfigurationProvider: Opened bucket sortimo_shadow
WARN [2015-03-30 14:03:16,386] com.couchbase.client.core.endpoint.Endpoint: [null][KeyValueEndpoint]: Could not connect to endpoint, retrying with delay 32 MILLISECONDS:
! java.net.ConnectException: Connection refused: localhost/127.0.0.1:11210
! at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method) ~[na:1.8.0_31]
! at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:716) ~[na:1.8.0_31]
! at com.couchbase.client.deps.io.netty.channel.socket.nio.NioSocketChannel.doFinishConnect(NioSocketChannel.java:208) ~[core-io-1.1.1.jar:1.1.1]
! at com.couchbase.client.deps.io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:281) ~[core-io-1.1.1.jar:1.1.1]
! at com.couchbase.client.deps.io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:528) [core-io-1.1.1.jar:1.1.1]
! at com.couchbase.client.deps.io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:468) [core-io-1.1.1.jar:1.1.1]
! at com.couchbase.client.deps.io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:382) [core-io-1.1.1.jar:1.1.1]
! at com.couchbase.client.deps.io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:354) [core-io-1.1.1.jar:1.1.1]
! at com.couchbase.client.deps.io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:116) [core-io-1.1.1.jar:1.1.1]
! at com.couchbase.client.deps.io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:137) [core-io-1.1.1.jar:1.1.1]
! at java.lang.Thread.run(Thread.java:745) [na:1.8.0_31]
INFO [2015-03-30 14:03:16,390] com.couchbase.client.core.node.Node: Disconnected from Node 192.168.1.150
WARN [2015-03-30 14:03:16,402] com.couchbase.client.core.endpoint.Endpoint: [null][ViewEndpoint]: Could not connect to endpoint, retrying with delay 32 MILLISECONDS:
...
The same happens if I choose port 8092 instead of 11210. What am I doing wrong?
回答1:
First off, 11210 is a reserved couchbase port for the Key/Value operations protocol, so you shouldn't try to set it as the query port (not the same service)!
Thanks for including logs, it shows that the SDK is trying to connect to localhost instead of connecting to the remote node. I think you're hitting a bug in version 2.1.1 used in conjunction with Couchbase Server 3.0.1 or lesser, am I right?
If so, the bug has been fixed in Java SDK 2.1.2, which should be released beginning of April. You can check that this is the case by using the Developer Preview (but don't forget to switch to official GA version once it is released).
(process to get preview version of 2.1.2 removed since it is now officially available)
The bug is tracked here
edit note: versions 2.1.2 and several additional versions have since been released that include the bugfix
来源:https://stackoverflow.com/questions/29348577/couchbase-connection-refused