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注册代码,十分简单。

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集群管理——基于Zookeeper的节点发现的更多相关文章

  1. Ignite集群管理——基于静态IP的节点发现

    Ignite作为分布式内存,集群管理必不可少,Ignite支持基于组播,静态IP,Zookeeper,JDBC等方式发现节点,本文主要介绍基于静态IP的节点发现. 两个最重要的TCP通信设置类: 1. ...

  2. Elasticsearch集群问题,导致主master节点发现不了node节点

    个人博客:https://blog.sharedata.info/ 最新需要配置es集群采用5个分片和1个副片,正好是11台机器,而只保留一份备份所以只需要5*2=10台机器方案:1.1台作为mast ...

  3. SolrCloud集群搭建(基于zookeeper)

    1. 环境准备 1.1 三台Linux机器,x64系统 1.2 jdk1.8 1.3 Solr5.5 2. 安装zookeeper集群 2.1 分别在三台机器上创建目录 mkdir /usr/hdp/ ...

  4. 2 weekend110的zookeeper的原理、特性、数据模型、节点、角色、顺序号、读写机制、保证、API接口、ACL、选举、 + 应用场景:统一命名服务、配置管理、集群管理、共享锁、队列管理

    在hadoop生态圈里,很多地方都需zookeeper. 启动的时候,都是普通的server,但在启动过程中,通过一个特定的选举机制,选出一个leader. 只运行在一台服务器上,适合测试环境:Zoo ...

  5. 基于zookeeper+mesos+marathon的docker集群管理平台

    参考文档: mesos:http://mesos.apache.org/ mesosphere社区版:https://github.com/mesosphere/open-docs mesospher ...

  6. zookeeper安装和应用场合(名字,配置,锁,队列,集群管理)

    安装和配置详解 本文介绍的 Zookeeper 是以 3.2.2 这个稳定版本为基础,最新的版本可以通过官网http://hadoop.apache.org/zookeeper/ 来获取,Zookee ...

  7. 一步到位分布式开发Zookeeper实现集群管理

    说到分布式开发Zookeeper是必须了解和掌握的,分布式消息服务kafka .hbase 到hadoop等分布式大数据处理都会用到Zookeeper,所以在此将Zookeeper作为基础来讲解. Z ...

  8. 搞懂分布式技术5:Zookeeper的配置与集群管理实战

    搞懂分布式技术5:Zookeeper的配置与集群管理实战 4.1 配置文件 ZooKeeper安装好之后,在安装目录的conf文件夹下可以找到一个名为“zoo_sample.cfg”的文件,是ZooK ...

  9. 基于CentOS与VmwareStation10搭建Oracle11G RAC 64集群环境:3.安装Oracle RAC-3.6.集群管理命令

    3.6. 集群管理命令 3.6.1. RAC的启动与关闭 oracle rac默认会开机自启动,如需维护时可使用以下命令: 关闭: crsctl stop cluster 停止本节点集群服务 crsc ...

随机推荐

  1. C#取得Web程序和非Web程序的根目录的N种取法

    取得控制台应用程序的根目录方法方法1.Environment.CurrentDirectory 取得或设置当前工作目录的完整限定路径方法2.AppDomain.CurrentDomain.BaseDi ...

  2. 自定义tarBar

    使用tarBar大多数情况在我们都是默认的tarBarButton尺寸和位置但是如果我们想,希望像新浪微博那样的tarBar,就需要自定义了. 1.本质上其实就是通过我们的主控制器中以KVC的方式重新 ...

  3. 在CentOS6.8下安装Docker

    在CentOS6.8下安装Docker 一.查看系统版本 [root@localhost opt]# uname -a Linux localhost.localdomain -.el6.x86_64 ...

  4. spring面试大全

    一.spring如何实现资源管理? 使用 applicationContext.getResource(“classpath:文件名”):在src根目录下,在类路径下 applicationConte ...

  5. 希尔排序之python

    希尔排序( Shell sort) 插入排序的改进版本,其核心思想是将原数据集合分割成若干个子序列,然后再对子序列分别进行直接插入排序,使子序列基本有序,最后再对全体记录进行一次直接插入排序. 我的面 ...

  6. cross browse compatible

    不过我之前用过一个Chrome的插件叫浏览器兼容性检测工具,可以在内网测试,会自动监测网页的设计是否满足对应浏览器及版本的规范,不满足的话就会详细提示出来,不过有些过于专业性了,更适合开发人员查看,测 ...

  7. Cocoa 集合类型:NSPointerArray,NSMapTable,NSHashTable

    iOS 中有很多种集合类型,最为常见的可能就 NSArray.NSDictionary.NSSet,但其实还有 NSPointerArray.NSMapTable.NSHashTable 等类型,虽然 ...

  8. centos7 安装composer

    命令: 1.下载composer wget https://dl.laravel-china.org/composer.phar -O /usr/local/bin/composer 2.赋予权限 c ...

  9. webpack学习三——output

    output的两个参数filename,path 一.path输出路径,输出路径要绝对路径,否则报错.做法如下: path:__dirname + 'path' 二.filename 输出文件命,相对 ...

  10. Java——文件操作字符流和字节流的区别

    转:http://blog.csdn.net/joephoenix/articles/2283165.aspx java的IO流分两种流 字节流 InputStream OutputStream 字符 ...