当我尝试通过客户端连接Hazelcast服务器时,它会给我以下操作。
com.hazelcast.client.AuthenticationException: Invalid credentials!
at com.hazelcast.client.spi.impl.ClusterListenerSupport$ManagerAuthenticator.authenticate(ClusterListenerSupport.java:153)
at com.hazelcast.client.connection.nio.ClientConnectionManagerImpl.authenticate(ClientConnectionManagerImpl.java:249)
at com.hazelcast.client.connection.nio.ClientConnectionManagerImpl.initializeConnection(ClientConnectionManagerImpl.java:220)
at com.hazelcast.client.connection.nio.ClientConnectionManagerImpl.getOrConnect(ClientConnectionManagerImpl.java:211)
at com.hazelcast.client.connection.nio.ClientConnectionManagerImpl.getOrConnect(ClientConnectionManagerImpl.java:67)
at com.hazelcast.client.spi.impl.ClusterListenerSupport.connect(ClusterListenerSupport.java:241)
at com.hazelcast.client.spi.impl.ClusterListenerSupport.connectToOne(ClusterListenerSupport.java:209)
at com.hazelcast.client.spi.impl.ClusterListenerSupport.connectToCluster(ClusterListenerSupport.java:161)
at com.hazelcast.client.spi.impl.ClientClusterServiceImpl.start(ClientClusterServiceImpl.java:203)
at com.hazelcast.client.impl.HazelcastClientInstanceImpl.start(HazelcastClientInstanceImpl.java:303)
at com.hazelcast.client.HazelcastClient.newHazelcastClient(HazelcastClient.java:86)
尝试使用组名作为dev1。我的服务器在Linux系统上。这是Windows系统的客户端配置。
<?xml version="1.0" encoding="UTF-8"?>
<hazelcast-client xsi:schemaLocation="http://www.hazelcast.com/schema/client-config hazelcast-client-config-3.6.xsd"
xmlns="http://www.hazelcast.com/schema/client-config"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<group>
<name>dev1</name>
<password>dev-pass</password>
</group>
<license-key>HAZELCAST_ENTERPRISE_LICENSE_KEY</license-key>
<properties>
<property name="hazelcast.client.shuffle.member.list">true</property>
<property name="hazelcast.client.heartbeat.timeout">60000</property>
<property name="hazelcast.client.heartbeat.interval">5000</property>
<property name="hazelcast.client.event.thread.count">5</property>
<property name="hazelcast.client.event.queue.capacity">1000000</property>
<property name="hazelcast.client.invocation.timeout.seconds">120</property>
</properties>
<network>
<cluster-members>
<address>192.168.2.49</address>
<address>192.168.5.67</address>
</cluster-members>
<smart-routing>true</smart-routing>
<redo-operation>true</redo-operation>
<connection-timeout>60000</connection-timeout>
<connection-attempt-period>3000</connection-attempt-period>
<connection-attempt-limit>2</connection-attempt-limit>
<socket-options>
<tcp-no-delay>false</tcp-no-delay>
<keep-alive>true</keep-alive>
<reuse-address>true</reuse-address>
<linger-seconds>3</linger-seconds>
<timeout>-1</timeout>
<buffer-size>32</buffer-size>
</socket-options>
<ssl enabled="false">
<factory-class-name>com.hazelcast.examples.MySslFactory</factory-class-name>
</ssl>
</network>
<executor-pool-size>40</executor-pool-size>
<native-memory enabled="false" allocator-type="POOLED">
<size unit="MEGABYTES" value="128" />
<min-block-size>1</min-block-size>
<page-size>1</page-size>
<metadata-space-percentage>40.5</metadata-space-percentage>
</native-memory>
<load-balancer type="random"/>
<near-cache name="default">
<max-size>2000</max-size>
<time-to-live-seconds>90</time-to-live-seconds>
<max-idle-seconds>100</max-idle-seconds>
<eviction-policy>LFU</eviction-policy>
<invalidate-on-change>true</invalidate-on-change>
<in-memory-format>OBJECT</in-memory-format>
<local-update-policy>INVALIDATE</local-update-policy>
</near-cache>
<query-caches>
<query-cache name="query-cache-name" mapName="map-name">
<predicate type="class-name">com.hazelcast.examples.ExamplePredicate</predicate>
<entry-listeners>
<entry-listener include-value="true" local="false">com.hazelcast.examples.EntryListener</entry-listener>
</entry-listeners>
<include-value>true</include-value>
<batch-size>1</batch-size>
<buffer-size>16</buffer-size>
<delay-seconds>0</delay-seconds>
<in-memory-format>BINARY</in-memory-format>
<coalesce>false</coalesce>
<populate>true</populate>
<eviction eviction-policy="LRU" max-size-policy="ENTRY_COUNT" size="10000"/>
<indexes>
<index ordered="false">name</index>
</indexes>
</query-cache>
</query-caches>
</hazelcast-client>
我的配置有错吗?
这是客户端代码
HazelcastInstance client = com.hazelcast.client.HazelcastClient.newHazelcastClient();
Map<Integer, String> customerMap = client.getMap("customers");
答案 0 :(得分:2)
您的群集需要密码。你能尝试一下:
ClientConfig config = new ClientConfig();
config.getGroupConfig().setPassword("dev-pass"); //that's the pw in your xml config.
com.hazelcast.client.HazelcastClient.newHazelcastClient(config);
答案 1 :(得分:0)
我有同样的错误,但是没有密码。设置clientConfig.setClusterName("DEV");
会有所帮助。
<dependency>
<groupId>com.hazelcast</groupId>
<artifactId>hazelcast</artifactId>
<version>4.0.1</version>
</dependency>
ClientConfig clientConfig =new ClientConfig();
clientConfig.getNetworkConfig().addAddress("10.0.0.180:5701");
clientConfig.setClusterName("DEV");
hz = HazelcastClient.newHazelcastClient(clientConfig);