Ignite 集群

来源:互联网 发布:c语言 long int 编辑:程序博客网 时间:2024/06/01 08:20
ignite具有高级的集群功能,包括逻辑集群组和自动发现。ignite的节点可以自动发现其他的节点。这有助于在需要时缩放集群,而不必重新启动整个集群。开发人员还可以利用ignite的混合云支持,允许在私有云和公共云之间建立连接,例如Amazon Web Services,为它们提供两个世界中最好的。

这里写图片描述
集群特性一浏览:
1.Cluster APIs(集群API)
2.Cluster Groups(集群组)
3.Leader Election(主节点选举)
4.Cluster Configuration(集群配置)
5.Zero Deployment(零部署)
6.Deployment Modes(部署模式)
7.Resource Injection(资源注入)
8.Amazon AWS Integration(亚马逊AWS集成)
9.Google Cloud Integration(谷歌云集成)
10.JClouds Integration(JClouds集成)
11.Network Configuration(网络设置)
12.Docker Deployment(docker发布部署)
13.Mesos Deployment(Mesos发布部署)
14.YARN Deployment(YARN发布部署)
15.SSL\TLS

1.Cluster APIs

访问集群和节点的APIs

1.1 IgniteCluster

集群功能是由IgniteCluster 接口提供的。你可以像下面这样,从Ignite中取得IgniteCluster实例。
    Ignite ignite = Ignition.ignite();    IgniteCluster cluster = ignite.cluster();
通过这个IgniteCluster接口,你可以:>启动或者关闭远程的集群节点>获取集群成员的列表>创建逻辑上的集群组

1.2 ClusterNode

ClusterNode接口有一个非常简洁的API,并且仅将节点作为拓扑中的逻辑网络端点处理。他的全局的唯一ID,节点的状态参数,它由用户设置的静态属性和其他一些参数。

1.3 Cluster Node Attributes 集群节点属性

虽有的集群节点在启动时自动的注册所有的环境和系统属性作为节点书店。然而,用户选择去用配置来分配他们自己的节点的属性。
<bean class="org.apache.ignite.IgniteConfiguration">    ...    <property name="userAttributes">        <map>            <entry key="ROLE" value="worker"/>        </map>    </property>    ...</bean>
如下的例子展示了怎么获取到被设置了“worker”属性的节点。
ClusterGroup workers = ignite.cluster().forAttribute("ROLE", "worker");Collection<ClusterNode> nodes = workers.nodes();
所有的节点属性可以通过ClusterNode.attribute("propertyName")来获取到。

1.4 Cluster Node Metrics 集群节点参数

ignite自动的为在集群中的节点收集度量信息。度量参数在背后被收集,并在集群节点交换心跳信息的时候更新度量信息。节点的度量信息可以通过包含超过50个不同的度量参数的ClusterMetrics 接口来获取(注意:同样的度量对于集群组也是可用的。)这里是一个获取一些度量信息的例子,包括本地节点的CPU平均利用率和堆使用情况:
// Local Ignite node.ClusterNode localNode = cluster.localNode();// Node metrics.ClusterMetrics metrics = localNode.metrics();// Get some metric values.double cpuLoad = metrics.getCurrentCpuLoad();long usedHeap = metrics.getHeapMemoryUsed();int numberOfCores = metrics.getTotalCpus();int activeJobs = metrics.getCurrentActiveJobs();

1.5 Local Cluster Node

本地的网格节点是代表了这个ignite节点的ClusterNode 的一个实例。这里是获取本地节点的样例:
ClusterNode localNode = ignite.cluster().localNode();

2. Cluster Groups 集群组

在你的集群中,轻松的创建集群节点的逻辑组

2.1 ClusterGroup

ClusterGroup代表的是一个逻辑上的集群节点的组合。在ignite中所有的节点都被设计的是平等的,所以你不需要去使用特殊的顺序来启动任何节点,或者分配一些特殊的角色给节点他们。然而,ignite允许用户去针对任何特定于应用程序的目的去逻辑的分组集群节点。例如,你可能希望去只在远程节点发布部署一个服务,或者为为某些工作节点分配“worker”角色以执行作业。注意:    IgniteCluster 接口同样是一个包含了所有集群中的几点的集群组,他是ClusterGroup子类。你可以限制作业的执行,服务的发布部署,消息,事件,和其他的任务,让它们只在某些集群组上运行。例如,这里是一个怎么去广播一个作业只到远程节点(不包括本地节点)。
final Ignite ignite = Ignition.ignite();IgniteCluster cluster = ignite.cluster();// Get compute instance which will only execute// over remote nodes, i.e. not this node.IgniteCompute compute = ignite.compute(cluster.forRemotes());// Broadcast to all remote nodes and print the ID of the node // on which this closure is executing.compute.broadcast(() -> System.out.println("Hello Node: " + ignite.cluster().localNode().id());
//1.7版本final Ignite ignite = Ignition.ignite();IgniteCluster cluster = ignite.cluster();// Get compute instance which will only execute// over remote nodes, i.e. not this node.IgniteCompute compute = ignite.compute(cluster.forRemotes());// Broadcast closure only to remote nodes.compute.broadcast(new IgniteRunnable() {    @Override public void run() {        // Print ID of the node on which this runnable is executing.        System.out.println(">>> Hello Node: " + ignite.cluster().localNode().id());    }});

2.2 Predefined Cluster Groups (预定义集群组)

你可以基于任何谓词,来创建集群组。为方便起见,ignite配备了一些预定义的集群组。下面是一些例子,通过ClusterGroup 接口获取到集群组。
//Remote NodesIgniteCluster cluster = ignite.cluster();// Cluster group with remote nodes, i.e. other than this node.ClusterGroup remoteGroup = cluster.forRemotes();
//Cache NodesIgniteCluster cluster = ignite.cluster();// All nodes on which cache with name "myCache" is deployed,//所有的叫“myCache”名字的缓存实例的节点,不管是客户端还是服务端类型ClusterGroup cacheGroup = cluster.forCacheNodes("myCache");//为所有“myCache”缓存实例存储数据的所有的节点ClusterGroup dataGroup = cluster.forDataNodes("myCache");// 所有访问以“myCache”为名字的缓存的所在的客户端节点集合ClusterGroup clientGroup = cluster.forClientNodes("myCache");
//Nodes with AttributesIgniteCluster cluster = ignite.cluster();//所有的 节点的“Role”属性是“worker” 的节点ClusterGroup attrGroup = cluster.forAttribute("ROLE", "worker");
//Random NodeIgniteCluster cluster = ignite.cluster();// Cluster group containing one random node.//包含一个随机节点的集群组ClusterGroup randomGroup = cluster.forRandom();// First (and only) node in the random group.//集群组的第一个节点ClusterNode randomNode = randomGroup.node();
//Host NodesIgniteCluster cluster = ignite.cluster();// 获取一个随机节点ClusterGroup randomNode = cluster.forRandom();// 所有的与上面那个随机节点的主机名相同的节点组成的集群组ClusterGroup cacheNodes = cluster.forHost(randomNode);
//Oldest NodeIgniteCluster cluster = ignite.cluster();// Dynamic cluster group representing the oldest cluster node.// Will automatically shift to the next oldest, if the oldest// node crashes.ClusterGroup oldestNode = cluster.forOldest();
//Local NodeIgniteCluster cluster = ignite.cluster();// 只有本地节点在里面的集群组ClusterGroup localGroup = cluster.forLocal();// Local node.ClusterNode localNode = localGroup.node();
//Clients & serversIgniteCluster cluster = ignite.cluster();// All client nodes.ClusterGroup clientGroup = cluster.forClients();// All server nodes.ClusterGroup serverGroup = cluster.forServers();

2.3 Cluster Groups with Node Attributes

Ignite的独特特性是所有的网格节点是平等的。这里没有主节点或者服务器节点,当然也没有工作节点或者客户端节点。在Ignite中的节点都是平等的---然而 用户可以配置节点来作为主节店和工作节点,或者客户端和数据节点。所有的集群节点,在启动的时候,会自动的注册所有的环境和系统属性文件,来作为节点的属性。但是,用户可以选择使用ignite配置来分配自定义的属性。
<bean class="org.apache.ignite.IgniteConfiguration">    ...    <property name="userAttributes">        <map>            <entry key="ROLE" value="worker"/>        </map>    </property>    ...</bean>
IgniteConfiguration cfg = new IgniteConfiguration();Map<String, String> attrs = Collections.singletonMap("ROLE", "worker");cfg.setUserAttributes(attrs);// Start Ignite node.Ignite ignite = Ignition.start(cfg);
所有的环境变量系统属性会被自动的注册为节点属性节点属性可以使用ClusterNode.attribute("propertyName")方法来获取下面是如何获取节点属性
IgniteCluster cluster = ignite.cluster();ClusterGroup workerGroup = cluster.forAttribute("ROLE", "worker");Collection<GridNode> workerNodes = workerGroup.nodes();

2.4 Custom Cluster Groups

你可以使用一些谓词来定义动态的集群组。这样的集群组会运行在那些满足谓词条件的节点上。这里是一个样例,在这个集群组中的节点会在谓词条件下被改变:
IgniteCluster cluster = ignite.cluster();// Nodes with less than 50% CPU load.ClusterGroup readyNodes = cluster.forPredicate((node) -> node.metrics().getCurrentCpuLoad() < 0.5);
IgniteCluster cluster = ignite.cluster();// Nodes with less than 50% CPU load.ClusterGroup readyNodes = cluster.forPredicate(    new IgnitePredicate<ClusterNode>() {        @Override public boolean apply(ClusterNode node) {            return node.metrics().getCurrentCpuLoad() < 0.5;        }    }));

2.5 Combining Cluster Groups

你可以通过在它们之间嵌套的方式来联合集群组们。例如,下面的代码片段演示如何通过将远程组与随机组相结合获得一个随机远程节点。
// Group containing oldest node out of remote nodes.ClusterGroup oldestGroup = cluster.forRemotes().forOldest();ClusterNode oldestNode = oldestGroup.node();

2.6 Getting Nodes from Cluster Groups

你可以以下面的方式获取集群节点。
ClusterGroup remoteGroup = cluster.forRemotes();// All cluster nodes in the group.Collection<ClusterNode> grpNodes = remoteGroup.nodes();// First node in the group (useful for groups with one node).ClusterNode node = remoteGroup.node();// And if you know a node ID, get node by ID.UUID myID = ...;node = remoteGroup.node(myId);

2.7 Cluster Group Metrics

ignite自动的为所有集群节点收集度量信息,集群组们的最cool的事就是主动的聚合在组内的节点们的度量信息,并在组内提供适当的平均值,最小值,最大值。节点的度量信息可以通过包含超过50个不同的度量参数的ClusterMetrics 接口来获取(注意:同样的度量对于集群组也是可用的。)这里是一个获取一些度量信息的例子,包括本地节点的CPU平均利用率和堆使用情况:
// Cluster group with remote nodes, i.e. other than this node.ClusterGroup remoteGroup = ignite.cluster().forRemotes();// Cluster group metrics.ClusterMetrics metrics = remoteGroup.metrics();// Get some metric values.double cpuLoad = metrics.getCurrentCpuLoad();long usedHeap = metrics.getHeapMemoryUsed();int numberOfCores = metrics.getTotalCpus();int activeJobs = metrics.getCurrentActiveJobs();

3.Leader Election(主节点选举)

自动的选择最老的或者最新的节点

3.1 overview

当在分布式的环境下运行工作时,由于集群拓扑的改变,你通常需要担保总会使用同一个节点。那么这个节点就是我们说的主节点。在一些系统里,选举集群的主节点通常需要去做数据一致性和通过从集群成员收集选票来处理,以最终得到主节点。因为在Ignite中数据的一致性是被数据网格的affinity功能处理完成了 (e.g. Rendezvous Hashing)。对于数据网格以外的数据一致性,传统意义上的领导者是不需要的。然而你还是希望为某些任务,可以有一个协调器节点。为了这个目的,ignite允许你自动的挑选最老的或者最新的集群中的节点。

3.2 Oldest Node

最老的节点有一个属性,每当添加新节点时它都保持不变。当最老的节点在集群中变化了时候,那么就是他被移除出了集群的时候。这里有一个例子,是如何在集群组选择最老的节点。
IgniteCluster cluster = ignite.cluster();// Dynamic cluster group representing the oldest cluster node.// Will automatically shift to the next oldest, if the oldest// node crashes.ClusterGroup oldestNode = cluster.forOldest();  

3.3 Youngest Node

最新的节点,不像最老的节点,在一个节点加入到集群中的时候会时常变化。然而,有时它可能仍然很方便,特别是如果您只需要在新加入的节点上执行某些任务时尤其如此。这里是一个例子,是在集群组中选则最新的节点:
gniteCluster cluster = ignite.cluster();// Dynamic cluster group representing the youngest cluster node.// Will automatically shift to the next youngest, if the youngest// node crashes.ClusterGroup youngestNode = cluster.forYoungest();
一旦获取到了集群组,你可以使用它去执行任务,发布服务,发送消息和更多的其他功能。

4. 集群配置(Cluster Configuration)

发布部署ignite在任何环境,并且可插拔的自动节点发现。

4.1 概述

在ignite中,节点之间可以通过DiscoverySpi,可以彼此发现.ignite提供了TcpDiscoverySpi 作为一个默认的DiscoverySpi实现,该实现使用TCP/IP进行节点间的发现。发现SPI可以配置为多播和基于静态IP的节点发现。

4.2 Multicast Based Discovery 基于组播的发现

TcpDiscoveryMulticastIpFinder 使用组播去发现在网格中的其他节点,他是默认的ip发现器,为TcpDiscoverySpi服务。你不需要再去指定它,除非你打算去重写默认的设置。这里有一个样例,讲的是如何来使用spring XML文件或者java代码来配置发现器。
<bean class="org.apache.ignite.configuration.IgniteConfiguration">  ...  <property name="discoverySpi">    <bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi">      <property name="ipFinder">        <bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.multicast.TcpDiscoveryMulticastIpFinder">          <property name="multicastGroup" value="228.10.10.157"/>        </bean>      </property>    </bean>  </property></bean>
TcpDiscoverySpi spi = new TcpDiscoverySpi();TcpDiscoveryVmIpFinder ipFinder = new TcpDiscoveryMulticastIpFinder();ipFinder.setMulticastGroup("228.10.10.157");spi.setIpFinder(ipFinder);IgniteConfiguration cfg = new IgniteConfiguration();// Override default discovery SPI.cfg.setDiscoverySpi(spi);// Start Ignite node.Ignition.start(cfg);

4.3 Static IP Based Discovery(基于静态ip发现)

一旦当组播不可用的时候,TcpDiscoveryVmIpFinder查找器可以使用预先配置的指定地址列表进行工作。你只需要提供至少一个远程节点的ip地址,但是最好提供2到3个网格中的节点的ip。一旦与所提供的IP地址建立连接,ignite将自动发现所有其他网格节点。默认情况下,TcpDiscoveryVmIpFinder 在non-shared模式下使用。如果你都是那启动一个服务器节点,那么在这种模式下,ip地址的列表最好包含这个本地节点。因为这会让这个节点在其他节点加入进这个集群的时候不需要等待,而是变为第一个集群节点,并且正常的操作。这里有一个样例,讲的是如何使用springXML和java代码配置发现器
<bean class="org.apache.ignite.configuration.IgniteConfiguration">  ...  <property name="discoverySpi">    <bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi">      <property name="ipFinder">        <bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder">          <property name="addresses">            <list>              <!--                                    Explicitly specifying address of a local node to let it start                                  and operate normally even if there is no more nodes in the cluster.                                    You can also optionally specify an individual port or port range.                          -->              <value>1.2.3.4</value>              <!--                   IP Address and optional port range of a remote node.                  You can also optionally specify an individual port and don't set                                    the port range at all.              -->              <value>1.2.3.5:47500..47509</value>            </list>          </property>        </bean>      </property>    </bean>  </property></bean>
TcpDiscoverySpi spi = new TcpDiscoverySpi();TcpDiscoveryVmIpFinder ipFinder = new TcpDiscoveryVmIpFinder();// Set initial IP addresses.// Note that you can optionally specify a port or a port range.ipFinder.setAddresses(Arrays.asList("1.2.3.4", "1.2.3.5:47500..47509"));spi.setIpFinder(ipFinder);IgniteConfiguration cfg = new IgniteConfiguration();// Override default discovery SPI.cfg.setDiscoverySpi(spi);// Start Ignite node.Ignition.start(cfg);

4.4 Multicast and Static IP Based Discovery(基于组播和静态ip的发现)

你可以将组播和静态ip一起使用。在这种情况下,除了通过组播(如果有的话)接收到的地址,tcpdiscoverypfinder还可以使用预配置的静态IP地址列表,就像上面描述的静态IP的发现一样。下面是一个如何配置多播IP查找器和静态IP地址的示例:
<bean class="org.apache.ignite.configuration.IgniteConfiguration">  ...  <property name="discoverySpi">    <bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi">      <property name="ipFinder">        <bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.multicast.TcpDiscoveryMulticastIpFinder">          <property name="multicastGroup" value="228.10.10.157"/>          <!-- list of static IP addresses-->          <property name="addresses">            <list>              <value>1.2.3.4</value>              <!--                   IP Address and optional port range.                  You can also optionally specify an individual port.              -->              <value>1.2.3.5:47500..47509</value>            </list>          </property>        </bean>      </property>    </bean>  </property></bean>
TcpDiscoverySpi spi = new TcpDiscoverySpi();TcpDiscoveryVmIpFinder ipFinder = new TcpDiscoveryMulticastIpFinder();// Set Multicast group.ipFinder.setMulticastGroup("228.10.10.157");// Set initial IP addresses.// Note that you can optionally specify a port or a port range.ipFinder.setAddresses(Arrays.asList("1.2.3.4", "1.2.3.5:47500..47509"));spi.setIpFinder(ipFinder);IgniteConfiguration cfg = new IgniteConfiguration();// Override default discovery SPI.cfg.setDiscoverySpi(spi);// Start Ignite node.Ignition.start(cfg);

4.5 Isolated Ignite Clusters on Same Set of Machines(隔离同一台机器上的Ignite集群)

当您需要在同一台机器上启动两个单独的ignite集群时,可能会有这样的情况,原因是出于测试目的或出于其他原因。如果来自不同集群的节点将使用非交叉的本地端口范围来实现TcpDiscoverySpi和tcp通信spi,那么就可以实现这个任务。假设您需要在一台机器上启动两个单独的集群以进行测试。然后,对于第一个集群中的节点,您应该使用以下TcpDiscoverySpi和tcpationspi配置:
<bean class="org.apache.ignite.configuration.IgniteConfiguration">    ...    <!--                Explicitly configure TCP discovery SPI to provide list of                 initial nodes from the first cluster.      -->    <property name="discoverySpi">        <bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi">            <!-- Initial local port to listen to. -->            <property name="localPort" value="48500"/>            <!-- Changing local port range. This is an optional action. -->            <property name="localPortRange" value="20"/>            <!-- Setting up IP finder for this cluster -->            <property name="ipFinder">                <bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder">                    <property name="addresses">                        <list>                            <!--                                Addresses and port range of the nodes from the first                                                                cluster.                                127.0.0.1 can be replaced with actual IP addresses or                                                                host names. Port range is optional.                            -->                            <value>127.0.0.1:48500..48520</value>                        </list>                    </property>                </bean>            </property>        </bean>    </property>    <!--        Explicitly configure TCP communication SPI changing local                port number for the nodes from the first cluster.    -->    <property name="communicationSpi">        <bean class="org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi">            <property name="localPort" value="48100"/>        </bean>    </property></bean>
IgniteConfiguration cfg=new IgniteConfiguration();// Explicitly configure TCP discovery SPI to provide list of initial nodes// from the first cluster.TcpDiscoverySpi discoverySpi=new TcpDiscoverySpi();// Initial local port to listen to.discoverySpi.setLocalPort(48500);// Changing local port range. This is an optional action.discoverySpi.setLocalPortRange(20);TcpDiscoveryVmIpFinder ipFinder=new TcpDiscoveryVmIpFinder();// Addresses and port range of the nodes from the first cluster.// 127.0.0.1 can be replaced with actual IP addresses or host names.// The port range is optional.ipFinder.setAddresses(Arrays.asList("127.0.0.1:48500..48520"));// Overriding IP finder.discoverySpi.setIpFinder(ipFinder);// Explicitly configure TCP communication SPI by changing local port number for// the nodes from the first cluster.TcpCommunicationSpi commSpi=new TcpCommunicationSpi();commSpi.setLocalPort(48100);// Overriding discovery SPI.cfg.setDiscoverySpi(discoverySpi);// Overriding communication SPI.cfg.setCommunicationSpi(commSpi);// Starting a node.Ignition.start(cfg);
对于来自第二个集群的节点,配置可以是这样的
<bean id="ignite.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">    <!--        Explicitly configure TCP discovery SPI to provide list of initial         nodes from the second cluster.    -->    <property name="discoverySpi">        <bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi">            <!-- Initial local port to listen to. -->            <property name="localPort" value="49500"/>            <!-- Changing local port range. This is an optional action. -->            <property name="localPortRange" value="20"/>            <!-- Setting up IP finder for this cluster -->            <property name="ipFinder">                <bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder">                    <property name="addresses">                        <list>                            <!--                                Addresses and port range of the nodes from the second                                                                cluster.                                127.0.0.1 can be replaced with actual IP addresses or                                                                host names. Port range is optional.                            -->                            <value>127.0.0.1:49500..49520</value>                        </list>                    </property>                </bean>            </property>        </bean>    </property>    <!--        Explicitly configure TCP communication SPI changing local port number         for the nodes from the second cluster.    -->    <property name="communicationSpi">        <bean class="org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi">            <property name="localPort" value="49100"/>        </bean>    </property></bean>
IgniteConfiguration cfg=new IgniteConfiguration();// Explicitly configure TCP discovery SPI to provide list of initial nodes// from the second cluster.TcpDiscoverySpi discoverySpi=new TcpDiscoverySpi();// Initial local port to listen to.discoverySpi.setLocalPort(49500);// Changing local port range. This is an optional action.discoverySpi.setLocalPortRange(20);TcpDiscoveryVmIpFinder ipFinder=new TcpDiscoveryVmIpFinder();// Addresses and port range of the nodes from the second cluster.// 127.0.0.1 can be replaced with actual IP addresses or host names.// The port range is optional.ipFinder.setAddresses(Arrays.asList("127.0.0.1:49500..49520"));// Overriding IP finder.discoverySpi.setIpFinder(ipFinder);// Explicitly configure TCP communication SPI by changing local port number for// the nodes from the second cluster.TcpCommunicationSpi commSpi=new TcpCommunicationSpi();commSpi.setLocalPort(49100);// Overriding discovery SPI.cfg.setDiscoverySpi(discoverySpi);// Overriding communication SPI.cfg.setCommunicationSpi(commSpi);// Starting a node.Ignition.start(cfg);
从配置中可以看出,它们之间的差异是很小的,只有SPIs和IP finder的端口号是不同的。如果您希望来自不同集群的节点能够使用多播协议来寻找彼此,则用tcpdiscoverypfinder替换TcpDiscoveryVmIpFinder,并在上面的每个配置中设置惟一的TcpDiscoveryMulticastIpFinder.multicastGroups。

4.6 Apache jclouds Based Discovery

4.7 Amazon S3 Based Discovery

4.8 Google Cloud Storage Based Discovery

以上自行参考官方文档吧

4.9 JDBC Based Discovery

您可以将数据库作为初始IP地址的公共共享存储。使用这个IP查找器节点将在启动时将其IP地址写入数据库。这是通过TcpDiscoveryJdbcIpFinder完成的。
<bean class="org.apache.ignite.configuration.IgniteConfiguration">  ...  <property name="discoverySpi">    <bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi">      <property name="ipFinder">        <bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.jdbc.TcpDiscoveryJdbcIpFinder">          <property name="dataSource" ref="ds"/>        </bean>      </property>    </bean>  </property></bean><!-- Configured data source instance. --><bean id="ds" class="some.Datasource">  ...</bean>
TcpDiscoverySpi spi = new TcpDiscoverySpi();// Configure your DataSource.DataSource someDs = MySampleDataSource(...);TcpDiscoveryJdbcIpFinder ipFinder = new TcpDiscoveryJdbcIpFinder();ipFinder.setDataSource(someDs);spi.setIpFinder(ipFinder);IgniteConfiguration cfg = new IgniteConfiguration();// Override default discovery SPI.cfg.setDiscoverySpi(spi);// Start Ignite node.Ignition.start(cfg);

4.10 Shared File System Based Discovery(基于共享文件系统的发现)

共享文件系统可以用作节点的IP地址的存储。节点将在启动时将其IP地址写入文件系统。该行为由TcpDiscoverySharedFsIpFinder提供支持。
<bean class="org.apache.ignite.configuration.IgniteConfiguration">  ...  <property name="discoverySpi">    <bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi">      <property name="ipFinder">        <bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.sharedfs.TcpDiscoverySharedFsIpFinder">          <property name="path" ref="/var/ignite/addresses"/>        </bean>      </property>    </bean>  </property></bean>
// Configuring discovery SPI.TcpDiscoverySpi spi = new TcpDiscoverySpi();// Configuring IP finder.TcpDiscoverySharedFsIpFinder ipFinder = new TcpDiscoverySharedFsIpFinder();ipFinder.setPath("/var/ignite/addresses");spi.setIpFinder(ipFinder);IgniteConfiguration cfg = new IgniteConfiguration();// Override default discovery SPI.cfg.setDiscoverySpi(spi);// Start Ignite node.Ignition.start(cfg);

4.11 Kubernetes Service Based Discovery(基于k8s服务的发现)

自行文档

4.12 ZooKeeper Based Discovery(基于zookeeper的发现)

如果您使用ZooKeeper来协调您的分布式环境,您也可以利用它来发现ignite节点。这是通过TcpDiscoveryZookeeperIpFinder完成的(注意,ignite - zookeeper模块必须启用)。
<bean class="org.apache.ignite.configuration.IgniteConfiguration">    ...    <property name="discoverySpi">        <bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi">            <property name="ipFinder">                <bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.zk.TcpDiscoveryZookeeperIpFinder">                    <property name="zkConnectionString" value="127.0.0.1:2181"/>                </bean>            </property>        </bean>    </property></bean>
TcpDiscoverySpi spi = new TcpDiscoverySpi();TcpDiscoveryZookeeperIpFinder ipFinder = new TcpDiscoveryZookeeperIpFinder();// Specify ZooKeeper connection string.ipFinder.setZkConnectionString("127.0.0.1:2181");spi.setIpFinder(ipFinder);IgniteConfiguration cfg = new IgniteConfiguration();// Override default discovery SPI.cfg.setDiscoverySpi(spi);// Start Ignite node.Ignition.start(cfg);

4.13 Failure Detection Timeout(故障检测超时)

故障检测超时用于确定集群节点在考虑与另一个节点的远程连接失败之前应该等待多长时间。ignite集群中的每个节点都与另一个节点相连接,即发现SPI的级别。NodeA向nodeB发送心跳(以及在集群环上传输的其他系统消息)到nodeB,如果后者在故障转移超时中没有应答,则nodeB将被从集群中启动。这个超时是根据环境的网络和硬件条件来优化发现SPI的故障检测特性的最简单的方法。PS:    超时自动控制TcpDiscoverySpi的配置参数,如套接字超时、消息确认超时等。如果显式设置了这些参数,则将忽略故障超时设置。配置失败检测超时,在服务器端用IgniteConfiguration.setFailureDetectionTimeout(long)来配置,在客户端使用IgniteConfiguration.setClientFailureDetectionTimeout(long)来配置。默认值为服务器节点为10秒,客户机节点为30秒。这就可以使发现SPI可以可靠的运行在绝大多数集装箱式的部署下。但是,对于稳定的低延迟网络,可以将参数设置为~ 200毫秒,以便更快地检测和响应故障。

4.14 Configuration

下面可以看到最常用的TcpDiscoverySpi配置参数。请参考TcpDiscoverySpi javadoc查看完整的配置选项列表。
方法 描述 默认值 setIpFinder(TcpDiscoveryIpFinder) IP查找器用于共享关于节点IP地址的信息。 TcpDiscoveryMulticastIpFinder的一些可以用额实现,如:TcpDiscoverySharedFsIpFinder TcpDiscoveryS3IpFinde TcpDiscoveryJdbcIpFinde TcpDiscoveryVmIpFinder setLocalAddress(String) 设置发现SPI需要使用的本地主机IP地址 如果没有提供,默认情况下将使用第一个发现的非循环地址。如果没有可用的非循环地址,那么java.net.InetAddress.getLocalHost()将被使用。 setLocalPort(int) SPI监听的端口 47500 setLocalPortRange(int) 本地端口范围。本地节点想要尝试在本地端口到本地端口 + 本地端口范围从开始的第一个可用端口绑定 100 setReconnectCount(int) 试图(重新)建立到另一个节点的连接的节点的数量 2 setNetworkTimeout(long) 为网络操作设置毫秒级的最大网络超时 5000 setSocketTimeout(long) 设置套接字操作超时。此超时用于限制连接时间和写入到套接字的时间。 2000 setAckTimeout(long) 设置超时以接收发送消息的确认。 如果在此超时期间未收到确认,发送被认为是失败的,SPI试图重复发送消息。 2000 setJoinTimeout(long) 设置连接超时。如果使用非共享IP查找器和节点无法连接IP查找器中的任何地址,节点将继续尝试在这个超时中加入。如果所有地址仍然没有响应,则抛出异常,节点启动失败。 0意味着永远等待。 0 setThreadPriority(int) 由SPI启动的线程优先级。 0 setStatisticsPrintFrequency(int) 统计打印频率以毫秒为单位。 表示不需要打印。如果值大于0,并且日志不安静,那么数据就会被打印出来,信息级别一次。这对于跟踪拓扑问题可能很有帮助 true

5.Zero Deployment(零部署)

5.1 概述

您用于计算的闭包和任务可能是任何自定义类,包括匿名类。在ignite里,远程节点将自动地了解这些类,并且您不需要显式地部署或移动任何类。jar文件到任何远程节点。

5.2 Peer Class Loading

由于对等类加载(P2P类加载),一个在ignite中的特殊的分布式类加载器可以在节点间字节码交换,所以使得零部署行为变为可能。在启用了对等类加载之后,您不必在网格上的每个节点上手动部署Java或Scala代码并在每次更改时重新部署它。下面的代码示例将在所有远程节点上运行,这是由于对等的类加载,没有任何显式的部署步骤。
IgniteCluster cluster = ignite.cluster();// Compute instance over remote nodes.IgniteCompute compute = ignite.compute(cluster.forRemotes());// Print hello message on all remote nodes.compute.broadcast(() -> System.out.println("Hello node: " + cluster.localNode().id()));
下面是如何配置对等类加载:
<bean class="org.apache.ignite.configuration.IgniteConfiguration">    ...       <!-- Explicitly enable peer class loading. -->    <property name="peerClassLoadingEnabled" value="true"/>    ...</bean>
IgniteConfiguration cfg = new IgniteConfiguration();cfg.setPeerClassLoadingEnabled(true);// Start Ignite node.Ignite ignite = Ignition.start(cfg);
对等类装入序列的运行如下:1.ignite将检查类是否在本地类路径上可用(如果它在系统启动时加载),如果是,则将返回。在本例中没有来自对等节点的类加载。2.如果没有本地可用的类,则会将请求发送到原始节点以提供类定义。原始节点将发送类字节码定义,类将被加载到工作节点上。这种情况只发生一次,一旦类定义被加载到一个节点上,它就再也不需要加载了。PS:用于热重新部署的自动清除缓存用热重新部署使用BinaryMarshaller(默认)。如果您不使用BinaryMarshaller,那是默认设置的,那么当您更改存储在缓存中的数据的类定义时,点火将自动清除之前的类定义的缓存,然后再对新数据进行对等部署,以避免类加载冲突。PS:第三方library在使用对等类加载时,应该注意从对等节点加载的库和在类路径中已经在本地可用的库。我们的建议是将所有第三方库包含到每个节点的类路径中。这可以通过将JAR文件复制到ignite的libs文件夹来实现。这样,每当您更改一行代码时,您将不会将第三方的类的兆字节传输到远程节点。

5.3 Explicit Deployment

要将JAR文件显式地展开,您应该将它们复制到每个ignite集群成员的libs文件夹中。ignite将自动加载启动时libs文件夹中的所有JAR文件

6.Deployment Modes(部署模式)

6.1 概述

ignite的对等类加载行为的细节是受不同的发布模式的控制的。特别的是,当原始的节点离开网织的时候,un-deployment行为依赖于发布模式。其他方面,由部署模式管理,是用户资源管理和类版本管理。在下面的小节中,我们将更详细地描述每个部署模式。

6.1.1 PRIVATE and ISOLATED

在主节点上同一个类加载器中部署的类,将仍然在工作节点上远程共享相同的类加载器。但是,从不同的主节点部署的任务不会在工作节点上共享相同的类加载器,这在开发时很有用,因为不同的开发人员可以在同一类的不同版本上工作。自从@UserResource注解被移除了之后,PRIVATE和SIOLATED模式就变得没有什么区别了。这两个常量由于为了保持向后兼容的原因才一直留存着,其中之一可能在未来的主要版本中被删除。在此模式中,当主节点离开集群时,类将被取消部署。

6.1.2 SHARED

这是默认的部署模式。在这个模式中,来自不同主节点的具有相同版本的类将在工作节点上共享相同的类加载器。当所有主节点都离开网格或用户版本更改时,类将被取消部署。这个模式允许来自不同主节点的类可以在远程节点上共享相同的用户资源(看下面)。这种方法在生产中特别有用,与ISOLATED模式相比,它在单个主节点上有单个类加载器的范围,而SHARED模式则将部署范围扩展到所有主节点。在此模式中,当所有主节点离开集群时,类将被取消部署

6.1.3 CONTINUOUS

在CONTINUOUS模式下,当主节点离开网格时,类不会被取消部署(un-deployed)。Un-deployment只发生在类的用户版本被修改的时候。这种方式的优点是它允许来自不同主节点的任务在工作(worker)节点上共享相同的用户资源的实例(参考Resource Injection)。这就允许所有的在工作节点上执行的任务可被重复使用,连接池或缓存的相同实例。在使用此模式时,您可以启动多个独立的工作节点,在主节点上定义用户资源,并在工作节点上对它们进行初始化,不管它们来自哪个主节点。与孤立的部署模式相比,在单个主节点上具有单个类加载器的范围,CONTINUOUS模式将部署范围扩展到所有在生产中特别有用的主节点。在这种模式下,即使所有主节点都离开集群,类也不会被取消部署。

6.2 Un-Deployment and User Versions

通过对等类加载获取的类定义有它们自己的生命周期。在某些事件(当主节点离开或用户版本更改时,取决于部署模式),类信息将从网格中取消部署(un-deployed):他的类定义从网格中的所有节点和用户资源中删除,链接到这个类定义,也会被删除(同样,取决于部署模式)。对于内存中的数据网格,它还意味着从缓存中删除未部署的类的所有缓存条目。然而,如果使用二进制编组(Binary Marshaller),则不是这样,它允许以二进制格式存储缓存数据,避免从主节点加载条目类的必要性。每当您希望重新部署部署在共享或连续模式中的类时,用户版本就会发挥作用。默认情况下,ignite将自动检测类加载器是否已更改或重新启动节点。但是,如果您想更改并重新部署节点的子集上的代码,或者在CONTINUOUS 模式的情况下想杀死所有的运行中的部署(living deployment),您应该改变用户版本。用户版本是在META-INF/ignite.xml中指定的。您的类路径的xml文件如下:
<!-- User version. --><bean id="userVersion" class="java.lang.String">    <constructor-arg value="0"/></bean>
默认情况下,所有的ignite启动脚本(ignite.sh或者ignite.bat)将会从IGNITE_HOME/config/userversion文件夹里拿用户版本,只需更新该文件夹下的用户版本即可。但是如果是GAR或者JAR方式部署,那么你应该记住去提供包含用户版本号的META-INF/ignite.xml文件。

6.3 Configuration

对于对等类加载的下列配置参数可以在IgniteConfiguration配置:
方法 描述 默认值 setPeerClassLoadingEnabled(boolean) 启用/禁用对等类加载。 false setPeerClassLoadingExecutorService(ExecutorService) 配置线程池以用于对等类加载。如果没有配置,则使用默认值。 null setPeerClassLoadingExecutorServiceShutdown(boolean) 对等类加载执行器服务关闭标志。如果将标志设置为true,则当节点停止时,对等类加载线程池将被强制关闭。 true setPeerClassLoadingLocalClassPathExclude(String…) 一个系统类路径中的包列表,即使它们在本地存在,也应该是P2P。 null setPeerClassLoadingMissedResourcesCacheSize(int) 遗漏资源缓存的大小。设置0以避免遗漏的资源缓存。 100 setDeploymentMode(DeploymentMode) 设置为部署任务和类的部署模式。 SHARED
<bean class="org.apache.ignite.configuration.IgniteConfiguration">    <!--        Explicitly enable peer class loading. Set to false        to disable the feature.    -->    <property name="peerClassLoadingEnabled" value="true"/>    <!-- Set deployment mode. -->    <property name="deploymentMode" value="CONTINUOUS"/>    <!-- Disable missed resources caching. -->    <property name="peerClassLoadingMissedResourcesCacheSize" value="0"/>    <!--        Exclude force peer class loading of a class,        even if exists locally.    -->    <property name="peerClassLoadingLocalClassPathExclude">        <list>            <value>com.mycompany.MyChangingClass</value>        </list>    </property></bean>
IgniteConfiguration cfg=new IgniteConfiguration();// Explicitly enable peer class loading.cfg.setPeerClassLoadingEnabled(true);// Set deployment mode.cfg.setDeploymentMode(DeploymentMode.CONTINUOUS);// Disable missed resource caching.cfg.setPeerClassLoadingMissedResourcesCacheSize(0);// Exclude force peer class loading of a class, // even if it exists locally.cfg.setPeerClassLoadingLocalClassPathExclude("com.mcompany.MyChangingClass");// Start a node.Ignition.start(cfg);

7. Network Configuration(网络配置)

促进集群内节点间的通信。

7.1 TcpCommunicationSpi

CommunicationSpi 提供基本的管道来发送和接收网格信息,并用于所有分布式网格操作,例如任务执行、监控数据交换、分布式事件查询等。ignite提供TcpCommunicationSpi 作为CommunicationSpi的默认实现,它使用TCP / IP与其他节点通信。为了与其他节点之间交互,TcpCommunicationSpi 添加了TcpCommunicationSpi.ATTR_ADDRS和TcpCommunicationSpi.ATTR_PORT本地节点属性。在启动之初,这个SPI尝试去启动由TcpCommunicationSpi.setLocalPort(int)方法指定的本地端口的监听。如果本地端口占用了,那么SPI江湖自动的提高这个端口的值,知道没有被占用为止并绑定监听。TcpCommunicationSpi.setLocalPortRange(int)配置参数控制着SPI会尝试的最大次数,超过了就失败,避免了一致尝试端口监听。PS:Local Port Range(本地端口范围)    在同一台机器上或同一VM上启动多个网格节点时,端口范围非常方便。在这种情况下,所有节点都可以在配置中没有一个更改而被提起。

7.2 Configuration

以下配置参数可以在TcpCommunicationSpi上配置:
方法 描述 默认值 setLocalAddress(String) 为socket绑定设置本地主机地址 任何可用的本地ip地址 setLocalPort(int) 设置socket绑定的端口 47100 setLocalPortRange(int) 如果所有以前尝试过的端口都被占用,则控制最大本地端口的数量。 100 setTcpNoDelay(boolean) 为TCP_NODELAY选项设置值。接受或创建的每个套接字都将使用提供的值。 这应该被设置为true(默认),用于减少在TCP协议通信期间的请求/响应时间。在大多数情况下,我们不建议改变这个选项。 true setConnectTimeout(long) 设置连接远程节点时使用的连接超时。 1000 setIdleConnectionTimeout(long) 设置连接到客户端的最大空闲连接超时。 30000 setBufferSizeRatio(double) 设置此SPI的缓冲区大小比率。当消息被发送时,缓冲区的大小使用这个比率进行调整。 0.8 or 如果IGNITE_COMMUNICATION_BUF_RESIZE_RATIO设置了,那么用这个属性的值 setMinimumBufferedMessageCount(int) 为这个SPI设置最小数量的消息,在发送之前缓冲。 512 or 如果设置了IGNITE_MIN_BUFFERED_COMMUNICATION_MSG_CNT,那么就用和这个系统属性的值 setDualSocketConnection(boolean) 设置是否强制执行当在节点之间进行dual-socket连接的标记。如果设置true, 将通信节点之间建立两个单独连接:一个用于输出消息,一个用于传入消息。当设置成false的时候,单个TCP连接将用于两个方向.这个标志在一些操作系统上很有用,当TCP_NODELAY标识位是不可用并且信息传递的时间太长 false setConnectionBufferSize(int) 只在setAsyncSend(boolean)设置为false的时候,这个参数才有用。设置同步连接的连接缓冲区大小。如果使用同步发送和发送大量小的消息,则增加缓冲区大小。但是大多数情况下设置为0(默认值) 0 setSelectorsCount(int) 设置在TCP服务器中使用的选择器计数。 选择器的默认计数等于表达式Math.min(4, Runtime.getRuntime().availableProcessors())的结果 setConnectionBufferFlushFrequency(long) 只有当setAsyncSend(boolean)被设置了false时候这个参数才有用。设置连接缓冲区刷新频率以毫秒为单位。当连接缓冲区大小不为0时,此参数只适用于同步发送。如果没有足够的消息使缓冲区自动刷新,缓冲区将在指定期间内刷新。 100 setDirectBuffer(boolean) 使用NIO direct和NIO heap分配缓冲区之间的切换。尽管direct缓冲性能更好,但在某些情况下(特别是在Windows上),它们可能会导致JVM崩溃。如果这种情况发生在您的环境中,则将此属性设置为false。 true setDirectSendBuffer(boolean) 在异步模式下使用NIO direct和NIO堆分配缓冲区的使用之间的切换。 false setAsyncSend(boolean) 同步和异步消息发送之间的切换。如果网格中节点通过多线程发送海量数据,那么这个需要设置为true。然而这是根据环境以及应用需求来的,所以需要测试那种比较好 true setSharedMemoryPort(int) 设置会被IpcSharedMemoryServerEndpoint.使用的端口号。在同一主机上启动的节点将通过IPC共享内存(只针对Linux和MacOS主机)进行通信。将此设置为- 1禁用IPC共享内存通信。 48100 setSocketReceiveBuffer(int) 设置接收由该SPI创建或接受的套接字的缓冲区大小。如果没有提供,默认值是0,在套接字创建(即使用操作系统默认值)之后,缓冲区将保持不变。 0 setSocketSendBuffer(int) 设置发送缓冲区大小为套接字创建或接受这种 spi。如果未提供,则默认值为 0 叶后创建套接字 (即使用操作系统默认值) 不变的缓冲区。 0

样例:

//xml版本<bean class="org.apache.ignite.configuration.IgniteConfiguration">  ...  <property name="communicationSpi">    <bean class="org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi">      <!-- Override local port. -->      <property name="localPort" value="4321"/>    </bean>  </property>  ...</bean>
//java版本TcpCommunicationSpi commSpi = new TcpCommunicationSpi();// Override local port.commSpi.setLocalPort(4321);IgniteConfiguration cfg = new IgniteConfiguration();// Override default communication SPI.cfg.setCommunicationSpi(commSpi);// Start grid.Ignition.start(cfg);

8.SSL\TLS

8.1 Securing Connection Between Nodes

ignite允许你使用SSL socket交互来在所有ignite节点上提供安全的连接。要使用它,请设置Factory<SSLContext>,并在ignite配置中配置SSL区段。ignite提供了默认的SSL上下文工厂,org.apache.ignite.ssl.SslContextFactory,使用可配置的keystore来初始化SSL上下文。
<bean id="cfg" class="org.apache.ignite.configuration.IgniteConfiguration">  <property name="sslContextFactory">    <bean class="org.apache.ignite.ssl.SslContextFactory">      <property name="keyStoreFilePath" value="keystore/server.jks"/>      <property name="keyStorePassword" value="123456"/>      <property name="trustStoreFilePath" value="keystore/trust.jks"/>      <property name="trustStorePassword" value="123456"/>    </bean>  </property></bean>
IgniteConfiguration igniteCfg = new IgniteConfiguration();SslContextFactory factory = new SslContextFactory();factory.setKeyStoreFilePath("keystore/server.jks");factory.setKeyStorePassword("123456".toCharArray());factory.setTrustStoreFilePath("keystore/trust.jks");factory.setTrustStorePassword("123456".toCharArray());igniteCfg.setSslContextFactory(factory);
在某些情况下,在客户端禁用证书验证是有用的,比如在连接到带有自签名证书的服务器时。这可以通过设置一个禁用的信任管理器到这个工厂来实现,这个工厂可以通过getDisabledTrustManager方法获得
<bean id="cfg" class="org.apache.ignite.configuration.IgniteConfiguration">  <property name="sslContextFactory">    <bean class="org.apache.ignite.ssl.SslContextFactory">      <property name="keyStoreFilePath" value="keystore/server.jks"/>      <property name="keyStorePassword" value="123456"/>      <property name="trustManagers">        <bean class="org.apache.ignite.ssl.SslContextFactory" factory-method="getDisabledTrustManager"/>     </property>    </bean>  </property></bean>
IgniteConfiguration igniteCfg = new IgniteConfiguration();SslContextFactory factory = new SslContextFactory();factory.setKeyStoreFilePath("keystore/server.jks");factory.setKeyStorePassword("123456".toCharArray());factory.setTrustManagers(SslContextFactory.getDisabledTrustManager());igniteCfg.setSslContextFactory(factory);
如果配置了安全,那么日志中会包含communication encrypted=on
INFO: Security status [authentication=off, communication encrypted=on]

8.2 SSL and TLS

ignite允许你使用不同的加密技术。它支持http://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html#SSLContext这个网站里的算法,并且可以使用setProtocol 方法进行设置。TLS算法是默认的。
<bean id="cfg" class="org.apache.ignite.configuration.IgniteConfiguration">  <property name="sslContextFactory">    <bean class="org.apache.ignite.ssl.SslContextFactory">      <property name="setProtocol" value="SSL"/>      ...    </bean>  </property>  ...</bean>
IgniteConfiguration igniteCfg = new IgniteConfiguration();SslContextFactory factory = new SslContextFactory();...factory.setProtocol("TLS");igniteCfg.setSslContextFactory(factory);

8.3 Configuration

以下配置参数可以在SslContextFactory上配置

这里写图片描述
偷个懒,安全加密的设置,需要做的自己看下吧