有关在Docker-Compose中设置Apache Ignite的问题

时间:2018-08-09 12:47:13

标签: docker-compose ignite

进一步了解我的更新方案...

我正在尝试在我们的Docker-compose环境中设置Apache Ignite,并且对Ignite以及如何配置有一些疑问。

  1. 如果我在项目中具有Maven依赖项,那么下载并运行Apache Ignite二进制文件的目的是什么?我是否需要在每个模块中也运行Ignite,或者仅具有足够的依赖关系?

  2. Ignite节点的每个实例都需要具有关联的配置,并且它们之间有何不同?

  3. 我有一个包含两个服务的Docker-Compose文件,一个服务拉入Ignite容器,一个Java Shell使我可以运行/测试模块。在我的外壳中,当我运行compose服务时,似乎我的测试发现了ignite服务。当我从IntelliJ中运行测试时,它不会发现其他Ignite服务器。

我的撰写服务:

  #Ignite
  ignite:
    image: apacheignite/ignite
    environment:
      - IGNITE_QUITE=false
    #volumes:
    #  - ./project/src/test/resources/ignite.xml:/opt/ignite/apache-ignite-fabric/config/default-config.xml
    ports:
      - 11211:11211
      - 47100:47100
      - 47500:47500
      - 49112:49112

  # Java Shell
  java:
    image: local/java
    build:
      context: .
    command: /bin/bash
    volumes:
      - .:/project
    depends_on:
      - ignite
    ports:
      - 8000:8000
      - 8080:8080
      - 1099:1099

我在测试中使用的Ignite配置:

 <bean id="ignite.cfg"
          class="org.apache.ignite.configuration.IgniteConfiguration">

        <property name="discoverySpi">
            <bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi">
                <property name="ipFinder">
                    <bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder">
                        <property name="addresses">
                            <list>
                                <!--
                                Explicitly specifying address of a local node to let it start and
                                operate normally even if there is no more nodes in the cluster.
                                You can also optionally specify an individual port or port range.
                                -->
                                <value>127.0.0.1</value>

                                <!--
                                IP Address and optional port range of a remote node.
                                You can also optionally specify an individual port.
                                -->
                                <value>127.0.0.1:47500..47509</value>
                            </list>
                        </property>
                    </bean>
                </property>
            </bean>
        </property>
    </bean>

我的测试:

@Test
    //@Ignore
    public void should_run_cluster()
    {
        try (Ignite ignite = Ignition.start("ignite2.xml"))
        {
            IgniteCache<Integer, String> cache = ignite.getOrCreateCache("myCacheName");

            // Store keys in cache (values will end up on different cache nodes).
            for (int i = 0; i < 10; i++)
            {
                cache.put(i, Integer.toString(i));
            }

            for (int i = 0; i < 10; i++)
            {
                System.out.println("Got [key=" + i + ", val=" + cache.get(i) + ']');
            }
        }
    }

根据我的操作,当我从IntelliJ中耗尽它时,我似乎能够与Ignite节点进行通信,但是它拒绝加入群集的节点。

我尝试从Java服务公开端口(不同的端口号,不仅公开内部端口等),但是没有运气。

如果我尝试将配置附加到Ignite服务,则完全无法正常工作。

我的最终目标是使用Docker-Compose设置一个环境,我可以在本地加入该环境以进行测试,但最终将其移至ECS / Fargate。

我确定我会混淆我的配置,我们将不胜感激...

-----更新-----

因此,我已经能够使用localhost / 127.0.0.1从IntelliJ连接到Ignite,并且能够在容器网络中使用撰写服务名称“ ignite”连接到Ignite。

这是正确的方法吗?我看不到如何为每个节点使用相同的配置,而无需执行某些令牌替换($ {port}),因为似乎我需要为DiscoverySpi和CommunicationSpi具有唯一的端口值。

此外,从我的客户端(在本例中为JUnit)连接时,要花很长时间才能建立初始连接。

所以,我现在的问题是这是否是配置Ignite的正确方法?

“点燃”服务(以撰写方式):

  ignite:
    image: apacheignite/ignite
    environment:
      - IGNITE_QUIET=false
    volumes:
      - ./project/src/test/resources/ignite-main.xml:/opt/ignite/apache-ignite-fabric/config/default-config.xml
    ports:
      - 11211:11211
      - 47100:47100
      - 47500:47500
      - 49112:49112

“点燃”服务配置(ignite-main.xml):

<property name="discoverySpi">
            <bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi">
                <property name="localPort" value="47500"/>
                <property name="ipFinder">
                    <bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder">
                        <property name="addresses">
                            <list>
                                <value>localhost</value>
                                <value>localhost:47500</value>
                            </list>
                        </property>
                    </bean>
                </property>
            </bean>
        </property>
        <property name="communicationSpi">
            <bean class="org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi">
                <property name="localPort" value="47100"/>
            </bean>
        </property>

客户端点火配置(ignite.xml):

<property name="discoverySpi">
            <bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi">
                <property name="localPort" value="47501"/>
                <property name="ipFinder">
                    <bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder">
                        <property name="addresses">
                            <list>
                                <value>localhost</value>
                                <value>localhost:47500</value>
                            </list>
                        </property>
                    </bean>
                </property>
            </bean>
        </property>
        <property name="communicationSpi">
            <bean class="org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi">
                <property name="localPort" value="47101"/>
            </bean>
        </property>

客户端点火测试用例:

私人静态点火器点燃;

@BeforeClass
public static void beforeAll()
{
    ignite = Ignition.start("ignite.xml");
}

@AfterClass
public static void afterAll()
{
    ignite.close();
}

@Test
public void should_prep_cluster()
{
    IgniteCache<Integer, String> cache = ignite.getOrCreateCache("myCacheName");

    // Store keys in cache (values will end up on different cache nodes).
    for (int i = 0; i < 10; i++)
    {
        cache.put(i, Integer.toString(i));
    }

    for (int i = 0; i < 10; i++)
    {
        System.out.println("Got [key=" + i + ", val=" + cache.get(i) + ']');
    }
}

2 个答案:

答案 0 :(得分:2)

作为@alamar答案的补充:

由于Docker Compose服务在单独的容器中启动,因此您无法使用localhost127.0.0.1来发现服务器节点。您可以链接点火服务以使用DNS名称ignite

撰写服务:

# Ignite
ignite:
  image: apacheignite/ignite
  environment:
    - IGNITE_QUIET=false
  # volumes:
  #   - ./project/src/test/resources/ignite.xml:/opt/ignite/apache-ignite-fabric/config/default-config.xml
  # It is not necessary to expose ports outside if they are only used inside docker-compose
  # ports:
  #   - 11211:11211
  #   - 47100:47100
  #   - 47500:47500
  #   - 49112:49112
# Java Shell
java:
  image: local/java
  build:
    context: .
  command: /bin/bash
  volumes:
    - .:/project
  links:
    - ignite
  ports:
    - 8000:8000
    - 8080:8080
    - 1099:1099

客户端点火配置(ignite.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.vm.TcpDiscoveryVmIpFinder">
                <property name="addresses">
                    <list>
                        <value>ignite:47500</value>
                    </list>
                </property>
            </bean>
        </property>
    </bean>
</property>

答案 1 :(得分:0)

  1. ,以便您可以使用任何模块集运行独立的Ignite节点,例如使用sqlline对它运行SQL,或者(在使用对等类加载时)对其连接的Ignite客户端执行几乎任何操作。但是话又说回来,您可以直接从Maven项目中运行Ignite节点(客户端或服务器),在这种情况下,您根本不需要二进制分发。

  2. 是的。除了节点属性或不需要的consistentId外,它们可能是相同的。

  3. 很难说。你能提供日志吗?我认为了解容器的人可以在没有日志的情况下进行检查,但是我不能。