服务端器配置两个不同的XML
example1.xml:
<bean abstract=”true” id=”ignite1.cfg” class=”org.apache.ignite.configuration.IgniteConfiguration”>
<property name=”peerClassLoadingEnabled” value=”true”/>
<property name=”discoverySpi”>
<bean class=”org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi”>
<property name=”localPort” value=”48500″/>
<property name=”localPortRange” value=”20″/>
<property name=”ipFinder”>
<bean class=”org.apache.ignite.spi.discovery.tcp.ipfinder.zk.TcpDiscoveryZookeeperIpFinder”>
<property name=”zkConnectionString” value=”192.168.33.12:2181″/>
<property name=”basePath” value=”/ignitecluster/cluster2″/>
</bean>
</property>
</bean>
</property>
<property name=”communicationSpi”>
<bean class=”org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi”>
<property name=”localPort” value=”48100″/>
</bean>
</property>
</bean>
example2.xml:
<bean abstract=”true” id=”ignite2.cfg” class=”org.apache.ignite.configuration.IgniteConfiguration”>
<property name=”peerClassLoadingEnabled” value=”true”/>
<property name=”discoverySpi”>
<bean class=”org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi”>
<property name=”localPort” value=”49500″/>
<property name=”localPortRange” value=”20″/>
<property name=”ipFinder”>
<bean class=”org.apache.ignite.spi.discovery.tcp.ipfinder.zk.TcpDiscoveryZookeeperIpFinder”>
<property name=”zkConnectionString” value=”192.168.33.12:2181″/>
<property name=”basePath” value=”/ignitecluster/cluster2″/>
</bean>
</property>
</bean>
</property>
<property name=”communicationSpi”>
<bean class=”org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi”>
<property name=”localPort” value=”49100″/>
</bean>
</property>
</bean>
使用TcpDiscoveryZookeeperIpFinder 可以用同一个ZOOKEEPER实例,用不同的路径区分集群
ignite-zookeeper 是一个可选模块,需要从libs/optional 下复制出来才能被IGNITE加入CLASSPATH
然后分别启动
bin/ignite.bat examples/config/example1.xml
bin/ignite.bat examples/config/example2.xml
客户端配置
<bean id=”ignite.cfg” class=”org.apache.ignite.configuration.IgniteConfiguration”>
<property name=”persistentStoreConfiguration”>
<bean class=”org.apache.ignite.configuration.PersistentStoreConfiguration”/>
</property>
<property name=”peerClassLoadingEnabled” value=”true”/>
<property name=”gridName” value=”IgniteCache”/>
<property name=”cacheConfiguration”>
….
</property>
<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=”192.168.33.12:2181″/>
<property name=”basePath” value=”/ignitecluster/cluster1″/>
</bean>
</property>
</bean>
</property>
<property name=”communicationSpi”>
<bean class=”org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi”>
<property name=”localPort” value=”48200″/>
</bean>
</property>
</bean>
<bean id=”ignite.cfg1″ class=”org.apache.ignite.configuration.IgniteConfiguration”>
<property name=”persistentStoreConfiguration”>
<bean class=”org.apache.ignite.configuration.PersistentStoreConfiguration”/>
</property>
<property name=”peerClassLoadingEnabled” value=”true”/>
<property name=”gridName” value=”IgniteCache1″/>
<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=”192.168.33.12:2181″/>
<property name=”basePath” value=”/ignitecluster/cluster2″/>
</bean>
</property>
</bean>
</property>
<property name=”communicationSpi”>
<bean class=”org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi”>
<property name=”localPort” value=”49200″/>
</bean>
</property>
</bean>
Ignition.setClientMode(true);
Ignition.start(“applicationContext-ignite.xml”);
Ignite ignite1 = Ignition.ignite(“IgniteCache”);
Ignite ignite2 = Ignition.ignite(“IgniteCache1”);
本地配置需要有多个IgniteConfiguration, 每个对应一个IGNITE集群
每个IgniteConfiguration 中的gridName不同, 对应不同的集群名称
客户端ZookeeperIpFinder的连接字串和路径和对应SERVER匹配
程序中有一个单例IGNITION 但是可以有多个IGNITE实例,每个的名字匹配IgniteConfiguration 中的gridName
注意:如果是本地启动多台SERVER,服务端需要为每台的discoverySpi 和 communicationSpi 配置LOCAL PORT
客户端需要配置communicationSpi的LOCAL PORT,而且和SERVER端不同
原创文章,作者:kepupublish,如若转载,请注明出处:https://blog.ytso.com/194689.html