【问题标题】:How to give multiple static ip in apache ignite cache configuration xml file如何在 apache ignite 缓存配置 xml 文件中提供多个静态 ip
【发布时间】: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地址。

但我可以看到,当我以这种方式 &lt;value&gt;158.xxx.xx.xxx:4444..158.xxx.xx.xxx:4444&lt;/value&gt; 提供时,它可以在 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


    【解决方案1】:

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

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

    【讨论】:

    【解决方案2】:

    就我的理解而言,在您提供的示例中,存在几个问题:

    &lt;value&gt;158.xxx.xx.xxx&lt;/value&gt; - 此行应该有一个或多个端口范围。 &lt;value&gt;4444&lt;/value&gt; - 你不能在附加线路上提供端口,你应该用地址列出它。 &lt;value&gt;158.xxx.xx.xxx:4444..158.xxx.xx.xxx:4444&lt;/value&gt; - 您可以拥有端口范围,但不能以这种方式拥有 IP 地址范围。

       <property name="addresses">
          <list>
            <!-- In distributed environment, replace with actual host IP address. -->
            <value>158.xxx.xx.xxx:47500..47509</value><!--server1 ip-->
            <value>158.xxx.xx.xxx:47500..47509</value><!--server2 ip-->
            <value>158.xxx.xx.xxx:47500..47509</value><!--server3 ip-->
          </list>
        </property>
    

    如果您是新手,我不建议您更改默认端口,因为这需要更改其他设置,您的目标应该是让基本集群正常工作。

    只要服务器 1、2 或 3 至少有一个节点在运行,此配置应该适用于具有任意数量节点的集群。其余节点将通过发现找到。

    【讨论】:

    • 我的一台服务器如何找到另一台服务器并与之集群,除非我在配置文件中的某处提及它
    • 一旦你的服务器会找到例如server1,它会立即知道集群中的所有服务器,并且它们都会知道该服务器。
    • 只有当我提到我发现的那些IP时它才会知道Spi对吗?
    • 不!集群中的所有节点都知道集群中的所有其他节点,关于 discoverySpi 设置。节点不必在列表中即可加入。
    • 如何将节点添加到集群中?我正在使用 example-ignite.xml 文件启动我的 ignite。在我更高的环境中,我将列出服务器下的 BIGVIP。我需要在 4 台服务器之间共享我的缓存。
    猜你喜欢
    • 1970-01-01
    • 2021-09-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-04
    • 2015-10-27
    • 1970-01-01
    相关资源
    最近更新 更多