簡體   English   中英

如何在apache ignite緩存配置xml文件中提供多個靜態IP

[英]How to give multiple static ip in apache ignite cache configuration xml file

我正在使用與apache ignite集成的Spring Boot微服務將密鑰和一些值存儲在緩存中。

在ignite緩存配置文件中,我試圖在具有相同端口的4台服務器之間共享我的緩存,即,我應該能夠獲取但無法在4台服務器上共享緩存,但它僅選擇2台服務器進行群集,在其他服務器中ignite緩存是作為單獨的緩存啟動的,並且不進入集群。 請幫忙。

我是否需要對集群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台服務器之間共享。

如果要添加到列表中的服務器IP地址超過2個,則此方法將不起作用。

請幫助共享3台以上服務器的緩存。

以下是用於啟動點火和激活集群的代碼im

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文件。 若要將服務器添加到群集,是否必須進行任何其他更改。 請幫忙。

以下是啟動點火時使用的我的緩存配置

<?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>

如果您不想維護一長串地址,則可以使用其他發現機制

您也不必在此部分列出每個IP。 一旦節點從列表中甚至找到一台服務器,它就會自動知道集群中的所有其他節點。

據我所知,在您提供的示例中,存在幾個問題:

<value>158.xxx.xx.xxx</value> -此行應具有端口范圍。 <value>4444</value> -您不能在其他行上提供端口,您應該在其中列出地址。 <value>158.xxx.xx.xxx:4444..158.xxx.xx.xxx:4444</value> -您可以擁有端口范圍,但不能以這種方式擁有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至少有一個正在運行的節點,則此配置應適用於任意數量的節點的群集。 其余節點將通過發現找到。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM