Hazelcast本地安装

2022-05-23 00:00:00 集群 节点 管理 可以看到 控制台

Update 2021.12.25

一、Hazelcast独立部署
本机:Mac M1

1. 配置Terminal(如果是Intel芯片不要这一步)
2. 安装Hazelcast

brew tap hazelcast/hz
brew install hazelcast
1
2
如果你的brew很久没更新,可能要执行一下brew update
确认Hazelcast的版本号

hz -V
1
3. 启动个节点

hz start
1
启动第二个节点

hz start
1
检查日志,可以看到两个节点组建了集群

2021-12-15 16:38:21,223 [ INFO] [main] [c.h.i.i.JetExtension]: [127.0.0.1]:5701 [dev] [5.0] Jet is enabled
2021-12-15 16:38:21,225 [ INFO] [main] [c.h.i.c.ClusterService]: [127.0.0.1]:5701 [dev] [5.0]

Members {size:1, ver:1} [
Member [127.0.0.1]:5701 - f702879e-2836-4b6a-b878-d6f5abc3dd71 this
]

2021-12-15 16:38:21,241 [ INFO] [main] [c.h.c.LifecycleService]: [127.0.0.1]:5701 [dev] [5.0] [127.0.0.1]:5701 is STARTED




2021-12-15 16:40:22,634 [ INFO] [hz.suspicious_cohen.IO.thread-in-1] [c.h.i.s.t.TcpServerConnection]: [127.0.0.1]:5701 [dev] [5.0] Initialized new cluster connection between /127.0.0.1:5701 and /127.0.0.1:50156
2021-12-15 16:40:28,644 [ INFO] [hz.suspicious_cohen.priority-generic-operation.thread-0] [c.h.i.c.ClusterService]: [127.0.0.1]:5701 [dev] [5.0]

Members {size:2, ver:2} [
Member [127.0.0.1]:5701 - f702879e-2836-4b6a-b878-d6f5abc3dd71 this
Member [127.0.0.1]:5702 - 9fbe0477-1434-4ea0-970a-c921cbeb224b
]

4. 启动管理控制台

hz mc start
1
Dev Mode那里点击Enable
点击View Cluster

注:管理控制台的配置方法。

5. 启动一个client

hz-cli console
1
执行命令插入一些数据。其中ns表示对象的名字(可以是IMap,IList等等),敲help可以看到更多命令。

ns test
put "1" "张三"
put "2" "李四"
1
2
3
6. 在管理控制台下面可以看到插入的数据:


二、Hazelcast嵌入springboot部署
1.创建一个springboot web项目并使用@Configuration注解初始化Hazelcast的三个实例和客户端。
@Configuration
public class HazelcastConfiguration {

private HazelcastInstance client;

@Bean("hzclient")
public HazelcastInstance getClient() {
if( client == null ) {
return setup();
}else{
return client;
}
}

private HazelcastInstance setup() {
// 自定义集群名字,避免连接到局域网其他人的集群,因为它默认是广播模式
String clusterName = "hz_aggregate";
// 集群chu
int port = 54321;
// embedding mode
Config config = new Config();
config.setClusterName(clusterName);
config.getNetworkConfig().setPublicAddress("127.0.0.1");
config.getNetworkConfig().setPort(port);
config.getJetConfig().setEnabled(true);
config.getManagementCenterConfig().addTrustedInterface("127.0.0.1");
Hazelcast.newHazelcastInstance(config);
Hazelcast.newHazelcastInstance(config);
Hazelcast.newHazelcastInstance(config);
// Hazelcast.newHazelcastInstance(config);

// Hazelcast客户端
ClientConfig clientConfig = new ClientConfig();
clientConfig.setClusterName(clusterName);
clientConfig.getNetworkConfig().addAddress("127.0.0.1" + ":" + port);
// clientConfig.setClusterName("dev");
// clientConfig.getNetworkConfig().addAddress("127.0.0.1:5701", "127.0.0.1:5702");
client = HazelcastClient.newHazelcastClient(clientConfig);
return client;
}

}


创建好之后的日志如下:

2021-12-25 10:30:33.909 INFO 86485 --- [ient_1.event-17] c.h.c.impl.spi.ClientClusterService : hz.client_1 [hz_aggregate] [5.0.1-SNAPSHOT]

Members [3] {
Member [127.0.0.1]:54321 - 2ab1c0f5-66a7-4a48-a741-77567f972d84
Member [127.0.0.1]:54322 - 40b0cdf4-b64e-451e-8b3f-5e4ed51cb82a
Member [127.0.0.1]:54323 - a17b35c0-3500-4438-9bdc-fb05324e4fc4
}

2.管理端连接embedding的Hazelcast集群
1. 编辑连接字符串:
2. 连接后点击查看集群

3. 默认的Dashboard


4. 使用Map Browser功能透视内存IMap:
点击Storage–>Maps,可以看到管理后台的透视功能把Employee类反序列化显示出来了。

为了让管理端能够反序列化定制类需要按下面的命令引入第三方jar(employee_demo-0.0.1-SNAPSHOT.jar)

#!/bin/sh
ps -ef | grep "hazelcast@5.2021.09" | grep -v grep | awk '{print $2}' | xargs kill -9
sleep 1
# if can not recover, execute command below
#rm -rf /Users/ouyang/hazelcast-mc
sleep 1
echo "starting Hazelcast Management Control WebSite..."
java -cp /usr/local/Cellar/hazelcast@5.2021.09/5.0/libexec/management-center
————————————————
版权声明:本文为CSDN博主「ouyangshixiong」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/ouyangshixiong/article/details/122140111

相关文章