分布式缓存服务 DCS-Redisson客户端连接Redis(Java):SSL连接配置(可选配置)

时间:2025-01-26 10:49:55

SSL连接配置(可选配置)

当实例开启了SSL,通过SSL连接实例时,请将基于Bean方式配置中的RedissonClient构造方法clientConfiguration()中添加如下configRedissonSSL(serverConfig)逻辑,同时将redis的连接地址从redis://ip:port改为rediss://ip:port格式。Redis实例支持SSL的情况请参考配置Redis SSL 数据加密 传输

private void configRedissonSSL(BaseConfig serverConfig) {    TrustManagerFactory trustManagerFactory = null;    try {        //加载自定义路径下的ca证书,可结合具体业务配置        CertificateFactory cf = CertificateFactory.getInstance("X.509");        Certificate ca;        try (InputStream is = new FileInputStream(certificationPath)) {            ca = cf.generateCertificate(is);        }        //创建keystore        String keyStoreType = KeyStore.getDefaultType();        KeyStore keyStore = KeyStore.getInstance(keyStoreType);        keyStore.load(null, null);        keyStore.setCertificateEntry("ca", ca);        //创建TrustManager        trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());        trustManagerFactory.init(keyStore);    } catch (CertificateException | IOException | KeyStoreException | NoSuchAlgorithmException e) {        e.printStackTrace();        return;    }    serverConfig.setSslTrustManagerFactory(trustManagerFactory);}
support.huaweicloud.com/usermanual-dcs/dcs-ug-211105004.html