apache Ignite 安装和helloworld
2023-04-18 14:50:19 时间
代码位置
https://github.com/lilihongjava/ignite_examples/tree/main/ignite-01
安装
下载ignite安装包,apache-ignite-2.11.0-bin.zip
选2台服务器,解压文件,在bin目录下(如/root/ignite/apache-ignite-2.11.0-bin/bin)执行
./ignite.sh ../examples/config/example-ignite.xml
日志如下:
[15:56:53] Ignite node started OK (id=235e6170)
[15:56:53] Topology snapshot [ver=1, locNode=235e6170, servers=1, clients=0, state=ACTIVE, CPUs=8, offheap=3.9GB, heap=4.3GB]
[15:56:53] ^-- Baseline [id=0, size=1, online=1, offline=0]
[15:56:58] Joining node doesn't have stored group keys [node=acd7e430-d4b3-443c-816f-d3a3f6c8fa1f]
[15:56:58] Topology snapshot [ver=2, locNode=235e6170, servers=2, clients=0, state=ACTIVE, CPUs=16, offheap=7.8GB, heap=8.6GB]
[15:56:58] ^-- Baseline [id=0, size=2, online=2, offline=0]
Ignite node started OK,则表示节点启动成功,此例中在2台服务器启动,所以 online=2。
helloworld程序
创建maven项目,添加包依赖
<properties>
<ignite.version>2.11.0</ignite.version>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.ignite</groupId>
<artifactId>ignite-core</artifactId>
<version>${ignite.version}</version>
</dependency>
<dependency>
<groupId>org.apache.ignite</groupId>
<artifactId>ignite-spring</artifactId>
<version>${ignite.version}</version>
</dependency>
</dependencies>
创建HelloWorld.java 文件
cfg.setClientMode(true),作为客户端节点启动。
采用tcp发现方式(TcpDiscoveryMulticastIpFinder)查找服务节点
Ignition.start(cfg), 启动客户端节点
IgniteConfiguration cfg = new IgniteConfiguration();
// The node will be started as a client node.
cfg.setClientMode(true);
// Classes of custom Java logic will be transferred over the wire from this app.
cfg.setPeerClassLoadingEnabled(true);
// Setting up an IP Finder to ensure the client can locate the servers.
TcpDiscoveryMulticastIpFinder ipFinder = new TcpDiscoveryMulticastIpFinder();
ipFinder.setAddresses(Collections.singletonList("10.1.12.215:47500..47509"));
cfg.setDiscoverySpi(new TcpDiscoverySpi().setIpFinder(ipFinder));
// Starting the node
Ignite ignite = Ignition.start(cfg);
客户端创建cache(myCache)
// Create an IgniteCache and put some values in it.
IgniteCache<Integer, String> cache = ignite.getOrCreateCache("myCache");
cache.put(1, "Hello");
cache.put(2, "World!");
System.out.println(">> Created the cache and add the values.");
向服务器发起计算任务
ignite.compute(ignite.cluster().forServers()).broadcast(new RemoteTask());
System.out.println(">> Compute task is executed, check for output on the server nodes.");
RemoteTask 任务如下 打印myCache内容
private static class RemoteTask implements IgniteRunnable {
@IgniteInstanceResource
Ignite ignite;
@Override public void run() {
System.out.println(">> Executing the compute task");
System.out.println(
" Node ID: " + ignite.cluster().localNode().id() + "
" +
" OS: " + System.getProperty("os.name") +
" JRE: " + System.getProperty("java.runtime.name"));
IgniteCache<Integer, String> cache = ignite.cache("myCache");
System.out.println(">> " + cache.get(1) + " " + cache.get(2));
}
}
结果
客户端日志 Topology snapshot […clients=1… 表示成功加入集群
[16:09:05] Ignite node started OK (id=72ba4f53)
[16:09:05] Topology snapshot [ver=3, locNode=72ba4f53, servers=2, clients=1, state=ACTIVE, CPUs=24, offheap=7.8GB, heap=12.0GB]
[16:09:05] ^-- Baseline [id=0, size=2, online=2, offline=0]
>> Created the cache and add the values.
>> Compute task is executed, check for output on the server nodes.
[16:09:08] Ignite node stopped OK [uptime=00:00:02.482]
服务端日志 打印>> Hello World!, 即myCache的内容
[16:08:23] Topology snapshot [ver=3, locNode=235e6170, servers=2, clients=1, state=ACTIVE, CPUs=24, offheap=7.8GB, heap=12.0GB]
[16:08:23] ^-- Baseline [id=0, size=2, online=2, offline=0]
>> Executing the compute task
Node ID: 235e6170-d2f7-4ea6-a7b3-a67cfa50238c
OS: Linux JRE: OpenJDK Runtime Environment
>> Hello World!
[16:08:55] Topology snapshot [ver=4, locNode=235e6170, servers=2, clients=0, state=ACTIVE, CPUs=16, offheap=7.8GB, heap=8.6GB]
[16:08:55] ^-- Baseline [id=0, size=2, online=2, offline=0]
相关文章
- 【技术种草】cdn+轻量服务器+hugo=让博客“云原生”一下
- CLB运维&运营最佳实践 ---访问日志大洞察
- vnc方式登陆服务器
- 轻松学排序算法:眼睛直观感受几种常用排序算法
- 十二个经典的大数据项目
- 为什么使用 CDN 内容分发网络?
- 大数据——大数据默认端口号列表
- Weld 1.1.5.Final,JSR-299 的框架
- JavaFX 2012:彻底开源
- 提升as3程序性能的十大要点
- 通过凸面几何学进行独立于边际的在线多类学习
- 利用行动影响的规律性和部分已知的模型进行离线强化学习
- ModelLight:基于模型的交通信号控制的元强化学习
- 浅谈Visual Source Safe项目分支
- 基于先验知识的递归卡尔曼滤波的代理人联合状态和输入估计
- 结合网络结构和非线性恢复来提高声誉评估的性能
- 最佳实践丨云开发CloudBase多环境管理实践
- TimeVAE:用于生成多变量时间序列的变异自动编码器
- 具有线性阈值激活的神经网络:结构和算法
- 内网渗透之横向移动 -- 从域外向域内进行密码喷洒攻击