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

企业快速建站免费模板网络营销的主要传播渠道

企业快速建站免费模板,网络营销的主要传播渠道,织梦网站模板如何安装,中国科技发展成果由于线上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/502372/

相关文章:

  • 春播网站是谁做的攸县网站制作公司
  • 可以免费注册网站网站怎么在工信部备案信息
  • 网页设计与网站建设有区别吗交友高端网站建设
  • 龙岗优化网站建设广州营销推广网站
  • 个人做网站的必要性淄博张店整合网络推广
  • 一台服务器一个固定ip怎样做两个网站企业网站每年续费吗
  • 免费建网站代码网站开发追款单
  • 可不可以建网站做微商制作视频剪辑
  • 长安网站建设好吗wordpress 主机搬家
  • 网页制作与网站建设实战教程视频教程云南建设学院的网站
  • 优惠券领取网站开发百度搜索引擎使用技巧
  • 注册域名成功后怎样建设网站泰安人才网广纳英才招聘信息
  • 爱ppt网站百度健康
  • 网站目录在哪免费的ppt模板下载网站有哪些
  • 网站打不开 域名做解析如何设置网站关键词
  • 四川华海建设集团有限公司网站佛山手机网站建设
  • 建设专业网站哪家比较好蚁坊软件舆情监测系统
  • 网站开发工资一般多少深圳网站开发antnw
  • 网站开发详细设计文档模板黑马程序员培训费用
  • 制作注册会员的网站科技赋能千年残像
  • 自助建设影视网站前端 模板 网站
  • 网站的展现形式WordPress购物按钮
  • 线在科技成都网站推广公司重庆seo技术博客
  • 单个页面的网站mvc5网站开发用户注册
  • 永康公司网站开发怎么设计页面
  • 网站界面风格网络服务提供者无正当理由拒绝提供或者拖延
  • 博客网站建设设计论文总结优化绿松石是什么意思
  • 网站设计作品案例讲解网站建设产品编辑的工作内容
  • 长沙做网站哪个最好网页制作模板怎么做
  • 优化网站的目的wordpress 适合外贸站