Przeglądaj źródła

更换redis集群配置=》单机配置

wangpenghui 1 rok temu
rodzic
commit
ba747f93ac

+ 9 - 9
pdf-tech-common/pom.xml

@@ -42,11 +42,11 @@
             <version>2.3.2.RELEASE</version>
         </dependency>
 
-        <dependency>
-            <groupId>org.redisson</groupId>
-            <artifactId>redisson</artifactId>
-            <version>3.11.3</version>
-        </dependency>
+<!--        <dependency>-->
+<!--            <groupId>org.redisson</groupId>-->
+<!--            <artifactId>redisson</artifactId>-->
+<!--            <version>3.11.3</version>-->
+<!--        </dependency>-->
 
         <dependency>
             <groupId>org.apache.commons</groupId>
@@ -101,10 +101,10 @@
             <groupId>org.springframework</groupId>
             <artifactId>spring-web</artifactId>
         </dependency>
-        <dependency>
-            <groupId>org.springframework.boot</groupId>
-            <artifactId>spring-boot-starter-mail</artifactId>
-        </dependency>
+<!--        <dependency>-->
+<!--            <groupId>org.springframework.boot</groupId>-->
+<!--            <artifactId>spring-boot-starter-mail</artifactId>-->
+<!--        </dependency>-->
         <dependency>
             <groupId>com.github.pagehelper</groupId>
             <artifactId>pagehelper</artifactId>

+ 49 - 49
pdf-tech-common/src/main/java/config/RedissonConfig.java

@@ -1,49 +1,49 @@
-package config;
-
-import org.redisson.Redisson;
-import org.redisson.api.RedissonClient;
-import org.redisson.config.Config;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import utils.DistributedLocker;
-import utils.RedissonDistributedLocker;
-
-/**
- * redisson配置
- */
-@Configuration
-public class RedissonConfig {
-    @Value("${spring.redis.cluster.nodes:}")
-    private  String cluster;
-    @Value("${spring.redis.password:}")
-    private String password;
-
-    @Bean
-    public RedissonClient getRedisson(){
-        String[] nodes = cluster.split(",");
-        //redisson版本是3.5,集群的ip前面要加上“redis://”,不然会报错,3.2版本可不加
-        for (int i = 0; i < nodes.length; i++) {
-            StringBuilder buffer = new StringBuilder("redis://");
-            nodes[i] = String.valueOf(buffer.append(nodes[i]));
-        }
-        RedissonClient redisson;
-        Config config = new Config();
-        //这是用的集群server
-        config.useClusterServers()
-                //设置集群状态扫描时间
-                .setScanInterval(2000)
-                .addNodeAddress(nodes)
-                .setPassword(password);
-        redisson = Redisson.create(config);
-
-        //可通过打印redisson.getConfig().toJSON().toString()来检测是否配置成功
-        return redisson;
-    }
-
-    @Bean
-    public DistributedLocker distributedLocker(RedissonClient redissonClient){
-         return new RedissonDistributedLocker(redissonClient);
-    }
-
-}
+//package config;
+//
+//import org.redisson.Redisson;
+//import org.redisson.api.RedissonClient;
+//import org.redisson.config.Config;
+//import org.springframework.beans.factory.annotation.Value;
+//import org.springframework.context.annotation.Bean;
+//import org.springframework.context.annotation.Configuration;
+//import utils.DistributedLocker;
+//import utils.RedissonDistributedLocker;
+//
+///**
+// * redisson配置
+// */
+//@Configuration
+//public class RedissonConfig {
+//    @Value("${spring.redis.cluster.nodes:}")
+//    private  String cluster;
+//    @Value("${spring.redis.password:}")
+//    private String password;
+//
+//    @Bean
+//    public RedissonClient getRedisson(){
+//        String[] nodes = cluster.split(",");
+//        //redisson版本是3.5,集群的ip前面要加上“redis://”,不然会报错,3.2版本可不加
+//        for (int i = 0; i < nodes.length; i++) {
+//            StringBuilder buffer = new StringBuilder("redis://");
+//            nodes[i] = String.valueOf(buffer.append(nodes[i]));
+//        }
+//        RedissonClient redisson;
+//        Config config = new Config();
+//        //这是用的集群server
+//        config.useClusterServers()
+//                //设置集群状态扫描时间
+//                .setScanInterval(2000)
+//                .addNodeAddress(nodes)
+//                .setPassword(password);
+//        redisson = Redisson.create(config);
+//
+//        //可通过打印redisson.getConfig().toJSON().toString()来检测是否配置成功
+//        return redisson;
+//    }
+//
+//    @Bean
+//    public DistributedLocker distributedLocker(RedissonClient redissonClient){
+//         return new RedissonDistributedLocker(redissonClient);
+//    }
+//
+//}

+ 60 - 60
pdf-tech-common/src/main/java/utils/DistributedLocker.java

@@ -1,60 +1,60 @@
-package utils;
-
-import org.redisson.api.RLock;
-
-import java.util.concurrent.TimeUnit;
-
-/**
- * 获取和释放分布式锁
- *
- * @author tangxiangan
- */
-public interface DistributedLocker {
-
-    /**
-     * 获取锁 拿不到lock就不罢休,不然线程就一直block
-     * @param lockKey
-     * @return
-     */
-    RLock lock(String lockKey);
-
-    /**
-     *获取锁 带有时间
-     * @param lockKey
-     * @param timeout 加锁时间 单位为秒
-     * @return
-     */
-    RLock lock(String lockKey, long timeout);
-
-    /**
-     * 获取锁 带有时间 时间单位有unit决定
-     * @param lockKey
-     * @param unit 加锁时间
-     * @param timeout 时间单位
-     * @return
-     */
-    RLock lock(String lockKey, TimeUnit unit, long timeout);
-
-    /**
-     *  带时间限制的获取锁,拿不到lock,就等一段时间,超时返回false.
-     * @param lockKey
-     * @param unit 时间单位
-     * @param waitTime 等待时间
-     * @param leaseTime 获取锁后加锁时间
-     * @return
-     */
-    boolean tryLock(String lockKey, TimeUnit unit, long waitTime, long leaseTime);
-
-    /**
-     * 释放锁
-     * @param lockKey
-     */
-    void unlock(String lockKey);
-
-    /**
-     * 释放锁
-     * @param lock RLock类型
-     */
-    void unlock(RLock lock);
-
-}
+//package utils;
+//
+//import org.redisson.api.RLock;
+//
+//import java.util.concurrent.TimeUnit;
+//
+///**
+// * 获取和释放分布式锁
+// *
+// * @author tangxiangan
+// */
+//public interface DistributedLocker {
+//
+//    /**
+//     * 获取锁 拿不到lock就不罢休,不然线程就一直block
+//     * @param lockKey
+//     * @return
+//     */
+//    RLock lock(String lockKey);
+//
+//    /**
+//     *获取锁 带有时间
+//     * @param lockKey
+//     * @param timeout 加锁时间 单位为秒
+//     * @return
+//     */
+//    RLock lock(String lockKey, long timeout);
+//
+//    /**
+//     * 获取锁 带有时间 时间单位有unit决定
+//     * @param lockKey
+//     * @param unit 加锁时间
+//     * @param timeout 时间单位
+//     * @return
+//     */
+//    RLock lock(String lockKey, TimeUnit unit, long timeout);
+//
+//    /**
+//     *  带时间限制的获取锁,拿不到lock,就等一段时间,超时返回false.
+//     * @param lockKey
+//     * @param unit 时间单位
+//     * @param waitTime 等待时间
+//     * @param leaseTime 获取锁后加锁时间
+//     * @return
+//     */
+//    boolean tryLock(String lockKey, TimeUnit unit, long waitTime, long leaseTime);
+//
+//    /**
+//     * 释放锁
+//     * @param lockKey
+//     */
+//    void unlock(String lockKey);
+//
+//    /**
+//     * 释放锁
+//     * @param lock RLock类型
+//     */
+//    void unlock(RLock lock);
+//
+//}

+ 65 - 65
pdf-tech-common/src/main/java/utils/RedissonDistributedLocker.java

@@ -1,65 +1,65 @@
-package utils;
-
-import org.redisson.api.RLock;
-import org.redisson.api.RedissonClient;
-
-import java.util.concurrent.TimeUnit;
-
-/**
- * 获取和释放分布式锁实现类
- */
-public class RedissonDistributedLocker implements DistributedLocker {
-    //RedissonClient已经由配置类生成,这里自动装配即可
-    private final RedissonClient redissonClient;
-
-    public RedissonDistributedLocker(RedissonClient redissonClient) {
-        this.redissonClient = redissonClient;
-    }
-
-    //lock(), 拿不到lock就不罢休,不然线程就一直block
-    @Override
-    public RLock lock(String lockKey) {
-        RLock lock = redissonClient.getLock(lockKey);
-        lock.lock();
-        return lock;
-    }
-
-    //leaseTime为加锁时间,单位为秒
-    @Override
-    public RLock lock(String lockKey, long leaseTime) {
-        RLock lock = redissonClient.getLock(lockKey);
-        lock.lock(leaseTime, TimeUnit.SECONDS);
-        return lock;
-    }
-
-    //timeout为加锁时间,时间单位由unit确定
-    @Override
-    public RLock lock(String lockKey, TimeUnit unit ,long timeout) {
-        RLock lock = redissonClient.getLock(lockKey);
-        lock.lock(timeout, unit);
-        return lock;
-    }
-
-    //tryLock(),马上返回,拿到lock就返回true,不然返回false。
-    //带时间限制的tryLock(),拿不到lock,就等一段时间,超时返回false.
-    @Override
-    public boolean tryLock(String lockKey, TimeUnit unit, long waitTime, long leaseTime) {
-        RLock lock = redissonClient.getLock(lockKey);
-        try {
-            return lock.tryLock(waitTime, leaseTime, unit);
-        } catch (InterruptedException e) {
-            return false;
-        }
-    }
-
-    @Override
-    public void unlock(String lockKey) {
-        RLock lock = redissonClient.getLock(lockKey);
-        lock.unlock();
-    }
-
-    @Override
-    public void unlock(RLock lock) {
-        lock.unlock();
-    }
-}
+//package utils;
+//
+//import org.redisson.api.RLock;
+//import org.redisson.api.RedissonClient;
+//
+//import java.util.concurrent.TimeUnit;
+//
+///**
+// * 获取和释放分布式锁实现类
+// */
+//public class RedissonDistributedLocker implements DistributedLocker {
+//    //RedissonClient已经由配置类生成,这里自动装配即可
+//    private final RedissonClient redissonClient;
+//
+//    public RedissonDistributedLocker(RedissonClient redissonClient) {
+//        this.redissonClient = redissonClient;
+//    }
+//
+//    //lock(), 拿不到lock就不罢休,不然线程就一直block
+//    @Override
+//    public RLock lock(String lockKey) {
+//        RLock lock = redissonClient.getLock(lockKey);
+//        lock.lock();
+//        return lock;
+//    }
+//
+//    //leaseTime为加锁时间,单位为秒
+//    @Override
+//    public RLock lock(String lockKey, long leaseTime) {
+//        RLock lock = redissonClient.getLock(lockKey);
+//        lock.lock(leaseTime, TimeUnit.SECONDS);
+//        return lock;
+//    }
+//
+//    //timeout为加锁时间,时间单位由unit确定
+//    @Override
+//    public RLock lock(String lockKey, TimeUnit unit ,long timeout) {
+//        RLock lock = redissonClient.getLock(lockKey);
+//        lock.lock(timeout, unit);
+//        return lock;
+//    }
+//
+//    //tryLock(),马上返回,拿到lock就返回true,不然返回false。
+//    //带时间限制的tryLock(),拿不到lock,就等一段时间,超时返回false.
+//    @Override
+//    public boolean tryLock(String lockKey, TimeUnit unit, long waitTime, long leaseTime) {
+//        RLock lock = redissonClient.getLock(lockKey);
+//        try {
+//            return lock.tryLock(waitTime, leaseTime, unit);
+//        } catch (InterruptedException e) {
+//            return false;
+//        }
+//    }
+//
+//    @Override
+//    public void unlock(String lockKey) {
+//        RLock lock = redissonClient.getLock(lockKey);
+//        lock.unlock();
+//    }
+//
+//    @Override
+//    public void unlock(RLock lock) {
+//        lock.unlock();
+//    }
+//}

+ 4 - 4
pdf-tech-core/pom.xml

@@ -149,10 +149,10 @@
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-test</artifactId>
         </dependency>
-        <dependency>
-            <groupId>com.alibaba.cloud</groupId>
-            <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
-        </dependency>
+<!--        <dependency>-->
+<!--            <groupId>com.alibaba.cloud</groupId>-->
+<!--            <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>-->
+<!--        </dependency>-->
 
         <!--hutool工具包-->
         <dependency>

+ 3 - 2
pdf-tech-core/src/main/java/cn/kdan/pdf/tech/core/config/BackendCoreConfig.java

@@ -1,7 +1,8 @@
 package cn.kdan.pdf.tech.core.config;
 
 import annotations.EnableCommonTools;
-import config.RedissonConfig;
+//import config.RedissonConfig;
+import config.RedisConfig;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
 import org.springframework.cache.annotation.EnableCaching;
@@ -23,7 +24,7 @@ import pojo.CustomHttpSessionStrategy;
 @Slf4j
 @EnableAspectJAutoProxy
 @EnableCaching
-@Import({RedisConfig.class,RedissonConfig.class})
+@Import({RedisConfig.class})
 public class BackendCoreConfig {
 
     @Bean

+ 65 - 65
pdf-tech-core/src/main/java/cn/kdan/pdf/tech/core/config/RedisConfig.java

@@ -1,65 +1,65 @@
-package cn.kdan.pdf.tech.core.config;
-
-import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.data.redis.connection.RedisClusterConfiguration;
-import org.springframework.data.redis.connection.RedisNode;
-import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
-import org.springframework.data.redis.connection.lettuce.LettucePoolingClientConfiguration;
-
-import java.util.HashSet;
-import java.util.Set;
-
-@Configuration
-public class RedisConfig {
-
-
-    @Value("${spring.redis.cluster.nodes}")
-    private String nodes;
-    @Value("${spring.redis.password}")
-    private String password;
-    @Value("${spring.redis.lettuce.pool.max-idle}")
-    private Integer maxIdle;
-    @Value("${spring.redis.lettuce.pool.min-idle}")
-    private Integer minIdle;
-    @Value("${spring.redis.lettuce.pool.max-active}")
-    private Integer maxTotal;
-    @Value("${spring.redis.lettuce.pool.max-wait}")
-    private Long maxWaitMillis;
-
-    @Bean
-    LettuceConnectionFactory lettuceConnectionFactory() {
-        // 连接池配置
-        GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
-        poolConfig.setMaxIdle(maxIdle == null ? 8 : maxIdle);
-        poolConfig.setMinIdle(minIdle == null ? 1 : minIdle);
-        poolConfig.setMaxTotal(maxTotal == null ? 8 : maxTotal);
-        poolConfig.setMaxWaitMillis(maxWaitMillis == null ? 5000L : maxWaitMillis);
-        LettucePoolingClientConfiguration lettucePoolingClientConfiguration = LettucePoolingClientConfiguration.builder()
-                .poolConfig(poolConfig)
-                .build();
-
-        // 集群redis
-        RedisClusterConfiguration redisConfig = new RedisClusterConfiguration();
-        Set<RedisNode> nodeses = new HashSet<>();
-        String[] hostses = nodes.split(",");
-        for (String h : hostses) {
-            h = h.replaceAll("\\s", "").replaceAll("\n", "");
-            if (!"".equals(h)) {
-                String host = h.split(":")[0];
-                int port = Integer.valueOf(h.split(":")[1]);
-                nodeses.add(new RedisNode(host, port));
-            }
-        }
-        redisConfig.setClusterNodes(nodeses);
-        // 跨集群执行命令时要遵循的最大重定向数量
-        redisConfig.setMaxRedirects(3);
-        redisConfig.setPassword(password);
-
-        return new LettuceConnectionFactory(redisConfig, lettucePoolingClientConfiguration);
-
-    }
-
-}
+//package cn.kdan.pdf.tech.core.config;
+//
+//import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
+//import org.springframework.beans.factory.annotation.Value;
+//import org.springframework.context.annotation.Bean;
+//import org.springframework.context.annotation.Configuration;
+//import org.springframework.data.redis.connection.RedisClusterConfiguration;
+//import org.springframework.data.redis.connection.RedisNode;
+//import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
+//import org.springframework.data.redis.connection.lettuce.LettucePoolingClientConfiguration;
+//
+//import java.util.HashSet;
+//import java.util.Set;
+//
+//@Configuration
+//public class RedisConfig {
+//
+//
+//    @Value("${spring.redis.cluster.nodes}")
+//    private String nodes;
+//    @Value("${spring.redis.password}")
+//    private String password;
+//    @Value("${spring.redis.lettuce.pool.max-idle}")
+//    private Integer maxIdle;
+//    @Value("${spring.redis.lettuce.pool.min-idle}")
+//    private Integer minIdle;
+//    @Value("${spring.redis.lettuce.pool.max-active}")
+//    private Integer maxTotal;
+//    @Value("${spring.redis.lettuce.pool.max-wait}")
+//    private Long maxWaitMillis;
+//
+//    @Bean
+//    LettuceConnectionFactory lettuceConnectionFactory() {
+//        // 连接池配置
+//        GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
+//        poolConfig.setMaxIdle(maxIdle == null ? 8 : maxIdle);
+//        poolConfig.setMinIdle(minIdle == null ? 1 : minIdle);
+//        poolConfig.setMaxTotal(maxTotal == null ? 8 : maxTotal);
+//        poolConfig.setMaxWaitMillis(maxWaitMillis == null ? 5000L : maxWaitMillis);
+//        LettucePoolingClientConfiguration lettucePoolingClientConfiguration = LettucePoolingClientConfiguration.builder()
+//                .poolConfig(poolConfig)
+//                .build();
+//
+//        // 集群redis
+//        RedisClusterConfiguration redisConfig = new RedisClusterConfiguration();
+//        Set<RedisNode> nodeses = new HashSet<>();
+//        String[] hostses = nodes.split(",");
+//        for (String h : hostses) {
+//            h = h.replaceAll("\\s", "").replaceAll("\n", "");
+//            if (!"".equals(h)) {
+//                String host = h.split(":")[0];
+//                int port = Integer.valueOf(h.split(":")[1]);
+//                nodeses.add(new RedisNode(host, port));
+//            }
+//        }
+//        redisConfig.setClusterNodes(nodeses);
+//        // 跨集群执行命令时要遵循的最大重定向数量
+//        redisConfig.setMaxRedirects(3);
+//        redisConfig.setPassword(password);
+//
+//        return new LettuceConnectionFactory(redisConfig, lettucePoolingClientConfiguration);
+//
+//    }
+//
+//}

+ 21 - 20
pdf-tech-core/src/main/resources/application-pro.yml

@@ -17,26 +17,27 @@ jdbc:
   password: postgres
 
 
-redis:
-  max-redirects: 3
-  maxIdle: 100
-  connectionTimeout: 100000
-  socketTimeout: 100000
-  maxAttempts: 5
-  maxTotal: 200
-  minIdle: 10
-  nodes: 35.188.251.105:6371,35.188.251.105:6372,35.188.251.105:6373,35.188.251.105:6374,35.188.251.105:6375,35.188.251.105:6376
-  password: 1qazZAQ2
-
-#ssoUrl: https://pdfreader-dev.oss-cn-shanghai.aliyuncs.com/saas/test-xiangan
-
-#webUrl: https://adminconsole.pdfreaderpro.com
-#createUrl: /sign-up
-#loginUrl: /login
-
-#readerproUrl: https://www.pdfreaderpro.com
-#confirmAddUrl: /join-team
-#emailImagesUrl: https://store.pdfreaderpro.com
+
+#redis:
+#  max-redirects: 3
+#  maxIdle: 100
+#  connectionTimeout: 100000
+#  socketTimeout: 100000
+#  maxAttempts: 5
+#  maxTotal: 200
+#  minIdle: 10
+#  nodes: 35.188.251.105:6371,35.188.251.105:6372,35.188.251.105:6373,35.188.251.105:6374,35.188.251.105:6375,35.188.251.105:6376
+#  password: 1qazZAQ2
+
+ssoUrl: https://pdfreader-dev.oss-cn-shanghai.aliyuncs.com/saas/test-xiangan
+
+webUrl: https://adminconsole.pdfreaderpro.com
+createUrl: /sign-up
+loginUrl: /login
+
+readerproUrl: https://www.pdfreaderpro.com
+confirmAddUrl: /join-team
+emailImagesUrl: https://store.pdfreaderpro.com
 
 #mail:
 #  username: no-reply@pdfreaderpro.com

+ 19 - 8
pdf-tech-core/src/main/resources/application.yml

@@ -33,16 +33,27 @@ spring:
       max-request-size: 20MB
   #redis连接池
   redis:
-    cluster:
-      nodes: ${redis.nodes}
-      max-redirects: ${redis.max-redirects}
-    password: ${redis.password}
+    host: 101.132.103.13
+    port: 33465
+    password: 1qazZAQ2
+    dataBase: 0
     lettuce:
       pool:
-        max-active: ${redis.maxTotal}
-        max-wait: ${redis.socketTimeout}
-        max-idle: ${redis.maxIdle}
-        min-idle: ${redis.minIdle}
+        max-active: 100
+        max-wait: 10000
+        max-idle: 100
+        min-idle: 10
+#  redis:
+#    cluster:
+#      nodes: ${redis.nodes}
+#      max-redirects: ${redis.max-redirects}
+#    password: ${redis.password}
+#    lettuce:
+#      pool:
+#        max-active: ${redis.maxTotal}
+#        max-wait: ${redis.socketTimeout}
+#        max-idle: ${redis.maxIdle}
+#        min-idle: ${redis.minIdle}
   jackson:
     date-format: yyyy-MM-dd HH:mm:ss
     time-zone: GMT+8

+ 9 - 4
pdf-tech-core/src/main/resources/logback-spring.xml

@@ -217,12 +217,17 @@
     </springProfile>
 
     <springProfile name="pro">
+        <logger name="cn.kdan.pdf.tech.core" level="debug"/>
         <root level="info">
-            <appender-ref ref="DEBUG_FILE"/>
-            <appender-ref ref="INFO_FILE"/>
-            <appender-ref ref="ERROR_FILE"/>
-            <appender-ref ref="WARN_FILE"/>
+            <appender-ref ref="CONSOLE"/>
         </root>
+
+<!--        <root level="info">-->
+<!--            <appender-ref ref="DEBUG_FILE"/>-->
+<!--            <appender-ref ref="INFO_FILE"/>-->
+<!--            <appender-ref ref="ERROR_FILE"/>-->
+<!--            <appender-ref ref="WARN_FILE"/>-->
+<!--        </root>-->
     </springProfile>
 
 </configuration>