当前位置: 首页 > news >正文

vps做网站空间wordpress支付宝支付宝

vps做网站空间,wordpress支付宝支付宝,erp管理系统免费版,做公司网站价格由于线上Redis要启用TLS,搜遍了google百度也没一个标准的解决方案,要不这个方法没有,要不那个类找不到...要不就是配置了还是一直连不上redis.... 本文基于 spring-data-redis-2.1.9.RELEASE 版本来提供一个解决方案: 1.运维那边提供过来三个文件,分别是redis.crt redis.key …

由于线上Redis要启用TLS,搜遍了google百度也没一个标准的解决方案,要不这个方法没有,要不那个类找不到...要不就是配置了还是一直连不上redis....

本文基于 spring-data-redis-2.1.9.RELEASE 版本来提供一个解决方案:

1.运维那边提供过来三个文件,分别是redis.crt redis.key ca.crt

 redis.crt 是公钥 redis.key是私钥 ca.crt是服务器证书,由于是测试生成的所以我代码中直接不校验,该文件对我无效

2. 使用命令 

openssl pkcs12 -export -in redis.crt -inkey redis.key -out redis_keystore.p12

生成PKCS#12证书束.(如果你们用的是JDK8_301以上版本则可以直接使用该文件)

3.使用命令 

keytool -importkeystore -srckeystore redis_keystore.p12 -srcstoretype PKCS12 -deststoretype JKS -destkeys
tore redis_keystore.jks

生成jks Java密钥库 (如果你们用的是JDK8_301以下版本则需要使用这种格式)

4.yml配置

spring:redis:database: 0host: 192.168.3.231password:port: 6380ssl:enable: truekeystore:file: classpath:redis_keystore.jkspassword: yourpassword

5. 将2/3步骤生成的文件放在resources目录下

6. RedisConfig代码配置

import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import io.lettuce.core.ClientOptions;
import io.lettuce.core.SslOptions;
import lombok.RequiredArgsConstructor;
import org.apache.commons.io.FileUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
import org.springframework.data.redis.connection.lettuce.LettuceClientConfiguration;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;import java.io.File;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.TimeZone;/*** @author felix* @date 2022/10/26*/
@Configuration
@RequiredArgsConstructor
public class RedisConfig {@Value("${spring.redis.host}")private String host;@Value("${spring.redis.port}")private Integer port;@Value("${spring.redis.password:}")private String password;@Value("${spring.redis.ssl.enable:}")private Boolean ssl;@Value("${spring.redis.ssl.keystore.file:}")private Resource keystore;@Value("${spring.redis.ssl.keystore.password:}")private String keystorePassword;private final ResourceLoader resourceLoader;@Beanpublic LettuceConnectionFactory lettuceConnectionFactory() throws Exception {RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration();redisStandaloneConfiguration.setHostName(host);redisStandaloneConfiguration.setPort(port);redisStandaloneConfiguration.setPassword(password);LettuceClientConfiguration.LettuceClientConfigurationBuilder lettuceClientConfigurationBuilder =LettuceClientConfiguration.builder();if (ssl != null && ssl) {//此处解决springboot打包后取不到资源文件问题String tempPath = System.getProperty("java.io.tmpdir") + File.separator + "bms_" + System.currentTimeMillis();String tempFile = tempPath + File.separator + keystore.getFilename();File path = new File(tempPath);if (!path.exists()) {path.mkdir();}File keystoreFile = new File(tempFile);FileUtils.copyInputStreamToFile(keystore.getInputStream(), keystoreFile);//此处配置SSL keystoreSslOptions sslOptions = SslOptions.builder().jdkSslProvider().keystore(keystoreFile, keystorePassword.toCharArray()).build();ClientOptions clientOptions = ClientOptions.builder().sslOptions(sslOptions).build();//disablePeerVerification 关闭证书校验lettuceClientConfigurationBuilder.clientOptions(clientOptions).useSsl().disablePeerVerification();}LettuceClientConfiguration lettuceClientConfiguration = lettuceClientConfigurationBuilder.build();return new LettuceConnectionFactory(redisStandaloneConfiguration, lettuceClientConfiguration);}
}

7.编写test进行测试

 @Testpublic void test() {redisTemplate.opsForValue().set("TEST", "111");}

至此,整个TLS配置就完成了.

由于没有比较完善的方案,整整浪费了我一天多的时间. 

记录一下,希望能帮到更多的人!

http://www.yayakq.cn/news/812779/

相关文章:

  • 网站开发需要学什么网站方案 模板
  • 福州官网建站厂计算机专业培训机构有哪些
  • 网站建设合伙合同优化网站制作公司好吗
  • 沈阳市浑南区城乡建设局网站辽宁专业模板网站建设公司
  • 做一个公司网站大概要多少钱怎么制作海报图片
  • 建设营销型网站公司湖南seo推广服务
  • 网站优化怎么弄传统营销
  • 临沂手机网站信息推广技术公司电话号码网站怎么放到服务器上
  • 如何投诉做网站的公司设计教程网站有哪些
  • 门户网站建设摘要windows优化大师是电脑自带的吗
  • 搭建网站有什么用门户网站app
  • 甘肃省城乡建设局网站wordpress的windows
  • 设计logo网站免费横屏纯色杭州制作网站的公司
  • 类似pinterest的网站要实现对网站中的所有内容进行搜索代码应该怎么写
  • 马鞍山建设银行网站网站建设公司响应式网站模板
  • 大连网站制作-中国互联住房和城乡建设部网站无在建
  • 茂名网站建设找个做游戏的视频网站好
  • thinkphp 网站源码wordpress后台菜单添加设置按钮
  • 传统网站建设团队浙江温州城乡建设网站
  • 比较好网站设计公司重庆做网络推广的公司
  • wordpress 作者列表seo网站监测
  • 专业的手机网站建设wordpress手机网站
  • 合肥做网站加盟长沙企业建站按效果付费
  • 正规品牌网站设计网站建设优選宙斯站长
  • 忽悠别人做商城网站一个好网站设计
  • 网站建设需求分析怎么写广西壮族自治区警官学校
  • 做网站如何突出网站特色宿迁网站建设联系电话
  • 山东高端网站建设服务商怎么给网站在百度地图上做爬虫
  • 租房网站开发需求文档加急网站备案
  • 网站怎样设计网页centos 网站搭建