【发布时间】:2018-10-18 10:21:33
【问题描述】:
我正在使用与 apache ignite 集成的 Spring Boot 微服务将密钥和一些值存储在缓存中。
在 ignite 缓存配置文件中,我尝试在具有相同端口的 4 台服务器之间共享我的缓存,即,我应该能够获取但无法在 4 台服务器之间共享缓存,但它只选择 2 台服务器进行集群,在它点燃缓存的其他服务器作为单独的服务器启动,并且不进入集群。请帮忙。
我是否需要对集群 4 服务器进行任何其他配置更改。
Cacheconfig.xml:
<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="addresses">
<list>
<!-- In distributed environment, replace with actual host IP address. -->
<!-- <value>127.0.0.1:47500..47509</value> -->
<value>158.xxx.xx.xxx</value><!--server1 ip-->
<value>158.xxx.xx.xxx</value><!--server2 ip-->
<value>158.xxx.xx.xxx</value><!--server3 ip-->
<value>4444</value><!--my port-->
</list>
</property>
</bean>
</property>
</bean>
</property>
这里我把默认的IP地址替换成了实际需要的服务器IP地址。
但我可以看到,当我以这种方式 <value>158.xxx.xx.xxx:4444..158.xxx.xx.xxx:4444</value> 提供时,它可以在 2 个服务器之间共享。
当它有超过 2 个服务器 IP 地址要添加到列表中时,这将不起作用。
请帮助共享超过 3 个服务器的缓存。
下面是我用来启动 ignite 和激活集群的代码
import java.util.Enumeration;
import java.util.Properties;
import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteCache;
import org.apache.ignite.IgniteException;
import org.apache.ignite.Ignition;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
public class IgniteCacheManager {
private static final Logger LOGGER = LoggerFactory.getLogger(IgniteCacheManager.class);
private Ignite ignite;
public Ignite getIgnite() {
return ignite;
}
@Autowired
private IgniteCacheManager(AppSpecificIgniteProperties igniteProperties) {
Properties p = System.getProperties();
Enumeration<Object> keys = p.keys();
LOGGER.debug("-----------------------------SYSTEM PROPERTIES Start--------------------------------------");
while (keys.hasMoreElements()) {
String key = (String) keys.nextElement();
String value = (String) p.get(key);
LOGGER.info(key);
LOGGER.info(value);
}
LOGGER.debug("-----------------------------SYSTEM PROPERTIES End--------------------------------------");
try {
// Ignite cache will start
ignite=Ignition.start(igniteProperties.getConfigFile());
//Cluster Activation
ignite.cluster().active(true);
LOGGER.info("IGNITE CACHE STARTED");
} catch (IgniteException e) {
LOGGER.error(e.getMessage(), e);
throw e;
}
}
public IgniteCache<String, Integer> getOrCreateCache(String name){
return ignite.getOrCreateCache(name);
}
}
这里的igniteProperties.getproperties 是cacheconfig.xml 文件,其中DiscoverySpi 和缓存到期配置。 要将服务器添加到集群中,我是否必须进行任何其他更改。 请帮忙。
以下是我在启动 ignite 时使用的缓存配置
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util.xsd">
<bean abstract="true" id="ignite.cfg"
class="org.apache.ignite.configuration.IgniteConfiguration">
<!-- Set to true to enable distributed class loading for examples, default
is false. -->
<!-- <property name="clientMode" value="true"/> -->
<property name="peerClassLoadingEnabled" value="true" />
<property name="cacheConfiguration">
<list>
<bean class="org.apache.ignite.configuration.CacheConfiguration">
<property name="name" value="hcache" />
<property name="expiryPolicyFactory">
<!-- <bean id="expiryPolicy" class="javax.cache.expiry.CreatedExpiryPolicy"
factory-method="factoryOf"> -->
<bean id="expiryPolicy" class="javax.cache.expiry.CreatedExpiryPolicy"
factory-method="factoryOf">
<!-- CreatedExpiryPolicy is used to inform the cache provider to remove
the entry after a specified time since the entry’s addition to the cache. -->
<constructor-arg>
<bean class="javax.cache.expiry.Duration">
<constructor-arg value="HOURS" />
<constructor-arg value="1" />
</bean>
</constructor-arg>
</bean>
</property>
</bean>
<bean class="org.apache.ignite.configuration.CacheConfiguration">
<property name="name" value="dcache" />
<property name="expiryPolicyFactory">
<bean id="expiryPolicy" class="javax.cache.expiry.CreatedExpiryPolicy"
factory-method="factoryOf">
<constructor-arg>
<bean class="javax.cache.expiry.Duration">
<constructor-arg value="HOURS" />
<constructor-arg value="24" />
</bean>
</constructor-arg>
</bean>
</property>
</bean>
<bean class="org.apache.ignite.configuration.CacheConfiguration">
<property name="name" value="wcache" />
<property name="expiryPolicyFactory">
<bean id="expiryPolicy" class="javax.cache.expiry.CreatedExpiryPolicy"
factory-method="factoryOf">
<constructor-arg>
<bean class="javax.cache.expiry.Duration">
<constructor-arg value="DAYS" />
<constructor-arg value="7" />
</bean>
</constructor-arg>
</bean>
</property>
</bean>
</list>
</property>
<!-- Enable task execution events for examples. -->
<property name="includeEventTypes">
<list>
<!--Task execution events -->
<util:constant static-field="org.apache.ignite.events.EventType.EVT_TASK_STARTED" />
<util:constant
static-field="org.apache.ignite.events.EventType.EVT_TASK_FINISHED" />
<!-- This event is triggered every time a task finished with an exception -->
<util:constant static-field="org.apache.ignite.events.EventType.EVT_TASK_FAILED" />
<util:constant
static-field="org.apache.ignite.events.EventType.EVT_TASK_TIMEDOUT" />
<util:constant
static-field="org.apache.ignite.events.EventType.EVT_TASK_SESSION_ATTR_SET" />
<util:constant static-field="org.apache.ignite.events.EventType.EVT_TASK_REDUCED" />
<!--Cache events -->
<util:constant
static-field="org.apache.ignite.events.EventType.EVT_CACHE_OBJECT_PUT" />
<util:constant
static-field="org.apache.ignite.events.EventType.EVT_CACHE_OBJECT_READ" />
<util:constant
static-field="org.apache.ignite.events.EventType.EVT_CACHE_OBJECT_REMOVED" />
</list>
</property>
<!-- <property name="eagerTtl" value="true" /> -->
<property name="dataStorageConfiguration">
<bean class="org.apache.ignite.configuration.DataStorageConfiguration">
<property name="defaultDataRegionConfiguration">
<bean class="org.apache.ignite.configuration.DataRegionConfiguration">
<property name="persistenceEnabled" value="true" />
</bean>
</property>
</bean>
</property>
<!-- Explicitly configure TCP discovery SPI to provide list of initial
nodes. -->
<property name="discoverySpi">
<bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi">
<property name="ipFinder">
<!-- Ignite provides several options for automatic discovery that can
be used instead os static IP based discovery. For information on all options
refer to our documentation: http://apacheignite.readme.io/docs/cluster-config -->
<!-- Uncomment static IP finder to enable static-based discovery of
initial nodes. -->
<!--<bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder"> -->
<bean
class="org.apache.ignite.spi.discovery.tcp.ipfinder.multicast.TcpDiscoveryMulticastIpFinder">
<property name="addresses">
<list>
<!-- In distributed environment, replace with actual host IP address. -->
<!-- <value>127.0.0.1:47500..47509</value> -->
<value>server1</value>
<value>server2</value>
<value>server3</value>
<value>server4</value>
</list>
</property>
</bean>
</property>
</bean>
</property>
</bean>
</beans>
【问题讨论】:
标签: java spring spring-boot ignite