java - 如何在apache ignite缓存配置xml文件中提供多个静态IP

标签 java spring spring-boot ignite

我正在使用与 apache ignite 集成的 Spring Boot 微服务来将 key 及其一些值存储在缓存中。

在 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>它适用于两台服务器之间的共享。

当要添加到列表中的服务器 IP 地址超过 2 个时,此操作将不起作用。

请帮助共享 3 台以上服务器的缓存。

下面是我用来启动点燃和激活集群的代码

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是discoverySpi和缓存过期配置的cacheconfig.xml文件。 要将服务器添加到集群,我是否必须进行任何其他更改。 请帮忙解决这个问题。

下面是我启动 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>

最佳答案

您可以使用其他discovery mechanisms如果您不想维护一长串地址。

您也不必在此部分列出每个 IP。一旦节点从列表中找到哪怕一台服务器,它就会自动了解集群中的所有其他节点。

关于java - 如何在apache ignite缓存配置xml文件中提供多个静态IP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50234056/

相关文章:

spring-boot - Spring-Boot入门测试导入未解决

java - Jersey 的 EntityHolder 类型中的层次结构

java - 枚举到类对象的转换

java - Spring Boot 集成测试响应空体 - MockMvc

spring - 如何在 Spring Boot 2 JPA 应用程序中选择 InnoDB 或 XtraDB 作为 MariaDB 中的存储引擎

spring - 如何在 Postman 中查看 Spring 5 Reactive API 的响应?

java - 在 Spring Boot 中添加 Spring Security 时无法登录

java - 制作框架模态

java - 自版本 4.3.2 以来未映射 hibernate 实体

java - 从独立客户端访问部署在 JBoss 7.1.1 上的 WAR 中的 @Remote EJB