java - 使用 SSLContext.getDefault() 在 Spring 使用 SSL 设置 Ignite 集群

标签 java spring ssl ignite

我正在尝试设置一个 Ignite在我的 Spring 应用程序中使用 SSL 加密进行集群。 我的目标是在多个节点上设置复制缓存。

我们将应用程序部署到 Tomcat 8 中,并在 Tomcat 启动时为我们的 keystore 和信任库设置环境变量。

我想启动嵌入在我的 Spring 应用程序中的 Ignite。所以我创建了一个返回 CacheManager 的 Bean。

@Bean
public SpringCacheManager replicatedCache() {

    int[] eventTypes = new int[] {EventType.EVT_CACHE_ENTRY_EVICTED, EventType.EVT_CACHE_OBJECT_REMOVED, EventType.EVT_CACHE_ENTRY_DESTROYED, EventType.EVT_CACHE_OBJECT_EXPIRED};

    SpringCacheManager cacheManager = new SpringCacheManager();

    IgniteConfiguration configuration = new IgniteConfiguration();
    configuration.setIncludeEventTypes(eventTypes);
    configuration.setGridName("igniteCluster");

    Slf4jLogger logger = new Slf4jLogger(LoggerFactory.getLogger(IGNITE_CACHE_LOGGER_NAME));
    configuration.setGridLogger(logger);

    CacheConfiguration cacheConfiguration1 = new CacheConfiguration();
    cacheConfiguration1.setName("replicatedCache");
    cacheConfiguration1.setCacheMode(CacheMode.REPLICATED);
    cacheConfiguration1.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);

    configuration.setCacheConfiguration(cacheConfiguration1);

    configuration.setSslContextFactory(() -> {
        try {
            return SSLContext.getDefault();
        } catch (NoSuchAlgorithmException e) {
            throw new WA3InternalErrorException("Could not create SSLContext", e);
        }
    });
    configuration.setLocalHost(env.getProperty("caching.localBind", "0.0.0.0"));

    TcpDiscoveryVmIpFinder ipFinder = new TcpDiscoveryVmIpFinder();
    List<String> nodes = Arrays.stream(env.getRequiredProperty("caching.nodes").split(",")).collect(Collectors.toList());
    ipFinder.setAddresses(nodes);
    TcpDiscoverySpi spi = new TcpDiscoverySpi();
    spi.setIpFinder(ipFinder);
    configuration.setDiscoverySpi(spi);

    TcpCommunicationSpi communicationSpi = new TcpCommunicationSpi();
    communicationSpi.setLocalPort(env.getRequiredProperty("caching.localPort", Integer.class));
    communicationSpi.setConnectTimeout(100000); // Line added in first edit
    configuration.setCommunicationSpi(communicationSpi);

    IgnitePredicate<? extends CacheEvent> localEvent = event -> {
        System.out.println(event);
        return true;
    };

    Map<IgnitePredicate<? extends Event>, int[]> ignitePredicateIntegerMap = Collections.singletonMap(localEvent, eventTypes);
    configuration.setLocalEventListeners(ignitePredicateIntegerMap);

    cacheManager.setConfiguration(configuration);

    return cacheManager;
}

如您所见,我还在这里配置了 Ignite。 绑定(bind)到服务器的 IP 地址并设置一个端口(默认端口为 47100)到 CommunicationSpi。 我在这里使用 SSLContext.getDefault(),所以它使用默认的 keystore 和信任库。

一切正常,当 SSL 被禁用时(不设置 SSLContextFactory)。 但是我一设置Factory,节点仍然可以找到,但是不能相互通信。

指标日志看起来不错,符合预期的 2 个节点:

    Metrics for local node (to disable set 'metricsLogFrequency' to 0)
        ^-- Node [id=41687971, name=igniteCluster, uptime=00:54:00:302]
        ^-- H/N/C [hosts=2, nodes=2, CPUs=4]
        ^-- CPU [cur=33.5%, avg=36.96%, GC=0%]
        ^-- Heap [used=193MB, free=85.51%, comm=627MB]
        ^-- Non heap [used=125MB, free=-1%, comm=127MB]
        ^-- Public thread pool [active=0, idle=2, qSize=0]
        ^-- System thread pool [active=0, idle=7, qSize=0]
        ^-- Outbound messages queue [size=0]

到目前为止,我所看到的是,Ignite 正在尝试连接一个端口 - 但失败了,增加该端口并重试。

2017-05-02T08:15:35,154 []  [] [grid-nio-worker-tcp-comm-1-#18%igniteCluster%] WARN  org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi [warning():104] [] - Communication SPI session write timed out (consider increasing 'socketWriteTimeout' configuration property) [remoteAddr=/10.30.0.106:53603, writeTimeout=2000]
2017-05-02T08:15:39,192 []  [] [grid-nio-worker-tcp-comm-2-#19%igniteCluster%] WARN  org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi [warning():104] [] - Communication SPI session write timed out (consider increasing 'socketWriteTimeout' configuration property) [remoteAddr=/10.30.0.106:53604, writeTimeout=2000]

我不知道那是什么端口。 我已经多次重启所有节点,看起来它是从 30000 到 50000 之间的随机端口开始的。

我最后的问题是: 我在这里错过了什么? 为什么我的 SSL 连接不起作用?

问候


我已经按照 Valentin 的建议增加了超时时间。我的集群仍有问题。

    2017-05-03T12:19:29,429 []  [] [localhost-startStop-1] WARN  org.apache.ignite.internal.processors.cache.GridCachePartitionExchangeManager [warning():104] [] - Failed to wait for initial partition map exchange. Possible reasons are:
      ^-- Transactions in deadlock.
      ^-- Long running transactions (ignore if this is the case).
      ^-- Unreleased explicit locks.

我在尝试连接到集群的节点上收到这些日志消息。

最佳答案

尝试增加 socketWriteTimeout,如错误消息所示。 SSL 连接速度较慢,您的网络中的默认值可能不足以支持它。

关于java - 使用 SSLContext.getDefault() 在 Spring 使用 SSL 设置 Ignite 集群,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43735849/

相关文章:

macos - Mac 上的 Grails 2.3.1 ; ClassNotFound NoUniqueBeanDefinitionException

internet-explorer - Internet Explorer 9 警告站点证书无效

google-app-engine - 如何修复谷歌云 ssl 问题

java - 使用 ASM 树 API 获取字段的修饰符

java - Docker Compose OpenJDK - 卷映射不起作用

java - Jasypt和非对称加密

java - 如何上传 CSV 文件,然后自动将数据插入数据库?

java - 最小 Oracle Java VM 堆内存设置?

Java 依赖类无法通过 System.getProperty() 访问属性

python easy_install 因所有包的 SSL 证书错误而失败