【发布时间】:2019-01-16 22:42:46
【问题描述】:
进一步了解我的更新场景...
我正在尝试在我们的 Docker-compose 环境中设置 Apache Ignite,并且对 Ignite 以及如何配置它有一些疑问。
如果我在项目中有 Maven 依赖项,那么下载和运行 Apache Ignite 二进制文件的目的是什么?我是否需要在每个模块中也运行 Ignite,还是仅仅拥有足够的依赖项?
Ignite 节点的每个实例是否都需要关联配置,它们之间有何不同?
我有一个 Docker-Compose 文件,其中包含两个服务,一个拉入 Ignite 容器,一个 Java shell 允许我运行/测试我的模块。在我的 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,并在容器网络中使用 compose 服务名称“ignite”。
这是正确的方法吗?我看不到如何在不使用令牌替换 (${port}) 的情况下为每个节点使用相同的配置,因为我似乎需要为 DiscoverySpi 和 CommunicationSpi 设置一个唯一的端口值。
此外,当从我的客户端(在本例中为 JUnit)连接时,建立初始连接需要很长时间。
那么,我现在的问题是,这是否是配置 Ignite 的正确方法?
“点燃”服务(在 Compose 中):
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”服务配置(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 配置 (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>
客户端点燃测试用例:
私有静态Ignite 点燃;
@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) + ']');
}
}
【问题讨论】:
标签: docker-compose ignite