Ignite集群管理——基于Zookeeper的节点发现
2017-06-03 23:12
357 查看
Ignite支持基于组播,静态IP,Zookeeper,JDBC等方式发现节点,本文主要介绍基于Zookeeper的节点发现。
环境准备,两台笔记本电脑A,B。A笔记本上使用VMware虚拟机安装了Ubuntu系统C。
1、 C安装Zookeeper
由于主要测试Ignite,这里仅仅简单安装一个zookeeper节点,下载zookeeper解压后,直接执行zookeeper目录下的bin/zkServer.sh start命令则成功启动zookeeper。
查看Ubuntu系统C的IP地址为192.168.1.104,zookeeper默认端口为12181。
注意:这里VMware虚拟机的网络适配器一定要选择桥接模式,否则A机器无法访问虚拟机。
2、 A系统运行Ignite节点1;
代码中加粗的部分便是Ignite注册代码,十分简单。
3、 B系统运行Ignite节点2;
可以看到,Ignite节点2可以成功访问到Ignite节点1存入缓存的数据。
环境准备,两台笔记本电脑A,B。A笔记本上使用VMware虚拟机安装了Ubuntu系统C。
1、 C安装Zookeeper
由于主要测试Ignite,这里仅仅简单安装一个zookeeper节点,下载zookeeper解压后,直接执行zookeeper目录下的bin/zkServer.sh start命令则成功启动zookeeper。
查看Ubuntu系统C的IP地址为192.168.1.104,zookeeper默认端口为12181。
注意:这里VMware虚拟机的网络适配器一定要选择桥接模式,否则A机器无法访问虚拟机。
2、 A系统运行Ignite节点1;
代码中加粗的部分便是Ignite注册代码,十分简单。
package com.coshaho.learn.ignite.cluster; import org.apache.ignite.Ignite; import org.apache.ignite.IgniteCache; import org.apache.ignite.Ignition; import org.apache.ignite.cache.CacheMode; import org.apache.ignite.configuration.CacheConfiguration; import org.apache.ignite.configuration.IgniteConfiguration; import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi; import org.apache.ignite.spi.discovery.tcp.ipfinder.zk.TcpDiscoveryZookeeperIpFinder; /** * * IgniteCluster01.java Create on 2017年6月3日 下午10:52:38 * * 类功能说明: 基于zookeeper集群 * * Copyright: Copyright(c) 2013 * Company: COSHAHO * @Version 1.0 * @Author coshaho */ public class IgniteCluster01 { public static void main(String[] args) { TcpDiscoverySpi spi = new TcpDiscoverySpi(); TcpDiscoveryZookeeperIpFinder ipFinder = new TcpDiscoveryZookeeperIpFinder(); // Specify ZooKeeper connection string. ipFinder.setZkConnectionString("192.168.1.104:12181"); spi.setIpFinder(ipFinder); IgniteConfiguration cfg = new IgniteConfiguration(); // Override default discovery SPI. cfg.setDiscoverySpi(spi); // Start Ignite node. Ignite ignite =Ignition.start(cfg); System.out.println("IgniteCluster1 start OK."); CacheConfiguration<Integer, String> cacheCfg = new CacheConfiguration<Integer, String>(); cacheCfg.setBackups(1); cacheCfg.setCacheMode(CacheMode.PARTITIONED); cacheCfg.setName("myCache"); IgniteCache<Integer, String> cache = ignite.getOrCreateCache(cacheCfg); cache.put(1, "ignite1"); System.out.println(cache.get(1)); System.out.println(cache.get(2)); } }
3、 B系统运行Ignite节点2;
package com.coshaho.learn.ignite.cluster; import org.apache.ignite.Ignite; import org.apache.ignite.IgniteCache; import org.apache.ignite.Ignition; import org.apache.ignite.cache.CacheMode; import org.apache.ignite.configuration.CacheConfiguration; import org.apache.ignite.configuration.IgniteConfiguration; import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi; import org.apache.ignite.spi.discovery.tcp.ipfinder.zk.TcpDiscoveryZookeeperIpFinder; public class IgniteCluster02 { public static void main(String[] args) { TcpDiscoverySpi spi = new TcpDiscoverySpi(); TcpDiscoveryZookeeperIpFinder ipFinder = new TcpDiscoveryZookeeperIpFinder(); // Specify ZooKeeper connection string. ipFinder.setZkConnectionString("192.168.1.104:12181"); spi.setIpFinder(ipFinder); IgniteConfiguration cfg = new IgniteConfiguration(); // Override default discovery SPI. cfg.setDiscoverySpi(spi); // Start Ignite node. Ignite ignite =Ignition.start(cfg); System.out.println("IgniteCluster2 start OK."); CacheConfiguration<Integer, String> cacheCfg = new CacheConfiguration<Integer, String>(); cacheCfg.setBackups(1); cacheCfg.setCacheMode(CacheMode.PARTITIONED); cacheCfg.setName("myCache"); IgniteCache<Integer, String> cache = ignite.getOrCreateCache(cacheCfg); cache.put(2, "ignite2"); System.out.println(cache.get(1)); System.out.println(cache.get(2)); } }
可以看到,Ignite节点2可以成功访问到Ignite节点1存入缓存的数据。
相关文章推荐
- Ignite集群管理——基于静态IP的节点发现
- 基于zookeeper管理redis集群,LCMPS框架(二)
- zookeeper集群之java程序异步方式实现对数据节点的增,删,改,查及其权限管理(三)
- 2 weekend110的zookeeper的原理、特性、数据模型、节点、角色、顺序号、读写机制、保证、API接口、ACL、选举、 + 应用场景:统一命名服务、配置管理、集群管理、共享锁、队列管理
- zookeeper和java实现的统一配置管理和集群节点管理简单案例
- zookeeper集群之java程序同步方式实现对数据节点的增,删,改,查及其权限管理(二)
- 基于Mesos+Marathon+Zookeeper的Docker集群管理环境搭建过程分享
- 关于能否使用2个zookeeper管理3节点storm集群的测试
- 基于zookeeper管理redis集群,实现消息路由(一)
- <四>基于淘宝Fourinone实现集群管理demo
- 利用zookeeper管理集群
- Linux 高可用(HA)集群之heartbeat基于crm进行资源管理详解(二)
- ndb集群添加节点 ndb集群管理节点的重新初始化
- dubbo学习之dubbo管理控制台装配及集成zookeeper集群部署(1)
- 集群节点基于Hadoop集群的HBase集群的配置【2】
- zookeeper+dubbo+dubbo管理集群的简要配置[单机]
- solrcloud集群启动管理过程基于源码的分析
- Linux 高可用(HA)集群之heartbeat基于crm进行资源管理详解
- MYSQL集群管理节点和数据节点的检测脚本
- 在python中使用zookeeper管理你的应用集群