From ea85570abed0727a8a5801265db1dd09d09a13bb Mon Sep 17 00:00:00 2001 From: fnzl54 Date: Thu, 21 Sep 2023 17:20:22 +0900 Subject: [PATCH 1/4] =?UTF-8?q?feat:=20redis=20=ED=81=B4=EB=9F=AC=EC=8A=A4?= =?UTF-8?q?=ED=84=B0=20=EA=B5=AC=EC=B6=95=EC=9D=84=20=EC=9C=84=ED=95=9C=20?= =?UTF-8?q?docker-compose,=20conf=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker-compose.yml | 88 ++++++++++++++++++++++++++++---- redis/config/redis-master-1.conf | 5 ++ redis/config/redis-master-2.conf | 5 ++ redis/config/redis-master-3.conf | 5 ++ redis/config/redis-slave-1.conf | 5 ++ redis/config/redis-slave-2.conf | 5 ++ redis/config/redis-slave-3.conf | 5 ++ 7 files changed, 108 insertions(+), 10 deletions(-) create mode 100644 redis/config/redis-master-1.conf create mode 100644 redis/config/redis-master-2.conf create mode 100644 redis/config/redis-master-3.conf create mode 100644 redis/config/redis-slave-1.conf create mode 100644 redis/config/redis-slave-2.conf create mode 100644 redis/config/redis-slave-3.conf diff --git a/docker-compose.yml b/docker-compose.yml index 3b8d9d0..be169b2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -33,18 +33,86 @@ services: networks: default_bridge: ipv4_address: 172.16.1.5 - redis: - container_name: redis - image: redis:latest + +# redis: +# container_name: redis +# image: redis:latest +# ports: +# - 6379:6379 +# volumes: +# - ./redis/data:/data +# labels: +# - "name=redis" +# - "mode=standalone" +# restart: always +# command: redis-server + + redis-master-1: + container_name: redis-master-1 + image: redis + volumes: + - ./redis/config/redis-master-1.conf:/etc/redis.conf + command: redis-server /etc/redis.conf ports: - - 6379:6379 + - 7001:7001 + - 7002:7002 + - 7003:7003 + - 7101:7101 + - 7102:7102 + - 7103:7103 + + redis-master-2: + network_mode: "service:redis-master-1" + container_name: redis-master-2 + image: redis volumes: - - ./redis/data:/data - labels: - - "name=redis" - - "mode=standalone" - restart: always - command: redis-server + - ./redis/config/redis-master-2.conf:/etc/redis.conf + command: redis-server /etc/redis.conf + + redis-master-3: + network_mode: "service:redis-master-1" + container_name: redis-master-3 + image: redis + volumes: + - ./redis/config/redis-master-3.conf:/etc/redis.conf + command: redis-server /etc/redis.conf + + redis-slave-1: + network_mode: "service:redis-master-1" + container_name: redis-slave-1 + image: redis + volumes: + - ./redis/config/redis-slave-1.conf:/etc/redis.conf + command: redis-server /etc/redis.conf + + redis-slave-2: + network_mode: "service:redis-master-1" + container_name: redis-slave-2 + image: redis + volumes: + - ./redis/config/redis-slave-2.conf:/etc/redis.conf + command: redis-server /etc/redis.conf + + redis-slave-3: + network_mode: "service:redis-master-1" + container_name: redis-slave-3 + image: redis + volumes: + - ./redis/config/redis-slave-3.conf:/etc/redis.conf + command: redis-server /etc/redis.conf + + redis-cluster-entry: + network_mode: "service:redis-master-1" + image: redis + container_name: redis-cluster + command: redis-cli --cluster create 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7101 127.0.0.1:7102 127.0.0.1:7103 --cluster-replicas 1 --cluster-yes + depends_on: + - redis-master-1 + - redis-master-2 + - redis-master-3 + - redis-slave-1 + - redis-slave-2 + - redis-slave-3 elasticsearch: restart: always diff --git a/redis/config/redis-master-1.conf b/redis/config/redis-master-1.conf new file mode 100644 index 0000000..87e219b --- /dev/null +++ b/redis/config/redis-master-1.conf @@ -0,0 +1,5 @@ +port 7001 +cluster-enabled yes +cluster-config-file nodes.conf +cluster-node-timeout 3000 +appendonly yes \ No newline at end of file diff --git a/redis/config/redis-master-2.conf b/redis/config/redis-master-2.conf new file mode 100644 index 0000000..042f519 --- /dev/null +++ b/redis/config/redis-master-2.conf @@ -0,0 +1,5 @@ +port 7002 +cluster-enabled yes +cluster-config-file nodes.conf +cluster-node-timeout 3000 +appendonly yes \ No newline at end of file diff --git a/redis/config/redis-master-3.conf b/redis/config/redis-master-3.conf new file mode 100644 index 0000000..a022469 --- /dev/null +++ b/redis/config/redis-master-3.conf @@ -0,0 +1,5 @@ +port 7003 +cluster-enabled yes +cluster-config-file nodes.conf +cluster-node-timeout 3000 +appendonly yes \ No newline at end of file diff --git a/redis/config/redis-slave-1.conf b/redis/config/redis-slave-1.conf new file mode 100644 index 0000000..2e358aa --- /dev/null +++ b/redis/config/redis-slave-1.conf @@ -0,0 +1,5 @@ +port 7101 +cluster-enabled yes +cluster-config-file nodes.conf +cluster-node-timeout 3000 +appendonly yes \ No newline at end of file diff --git a/redis/config/redis-slave-2.conf b/redis/config/redis-slave-2.conf new file mode 100644 index 0000000..9139671 --- /dev/null +++ b/redis/config/redis-slave-2.conf @@ -0,0 +1,5 @@ +port 7102 +cluster-enabled yes +cluster-config-file nodes.conf +cluster-node-timeout 3000 +appendonly yes \ No newline at end of file diff --git a/redis/config/redis-slave-3.conf b/redis/config/redis-slave-3.conf new file mode 100644 index 0000000..bc1ce88 --- /dev/null +++ b/redis/config/redis-slave-3.conf @@ -0,0 +1,5 @@ +port 7103 +cluster-enabled yes +cluster-config-file nodes.conf +cluster-node-timeout 3000 +appendonly yes \ No newline at end of file From e6f4c926898c24f2ef54d802e813337400df80cb Mon Sep 17 00:00:00 2001 From: fnzl54 Date: Thu, 21 Sep 2023 17:21:16 +0900 Subject: [PATCH 2/4] =?UTF-8?q?feat:=20redis=20=ED=81=B4=EB=9F=AC=EC=8A=A4?= =?UTF-8?q?=ED=84=B0=EC=99=80=20spring=20=EC=97=B0=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 1 + .../checkIt/global/config/RedisInfo.java | 20 ++++++++++++++++++ .../global/config/RedisRepositoryConfig.java | 21 ++++++++++++------- 3 files changed, 34 insertions(+), 8 deletions(-) create mode 100644 src/main/java/com/techeer/checkIt/global/config/RedisInfo.java diff --git a/build.gradle b/build.gradle index d50a61f..5fe8fbb 100644 --- a/build.gradle +++ b/build.gradle @@ -36,6 +36,7 @@ dependencies { compileOnly 'org.projectlombok:lombok' runtimeOnly 'com.mysql:mysql-connector-j' annotationProcessor 'org.projectlombok:lombok' + annotationProcessor "org.springframework.boot:spring-boot-configuration-processor" testImplementation 'org.springframework.boot:spring-boot-starter-test' testImplementation 'org.springframework.security:spring-security-test' } diff --git a/src/main/java/com/techeer/checkIt/global/config/RedisInfo.java b/src/main/java/com/techeer/checkIt/global/config/RedisInfo.java new file mode 100644 index 0000000..008b39a --- /dev/null +++ b/src/main/java/com/techeer/checkIt/global/config/RedisInfo.java @@ -0,0 +1,20 @@ +package com.techeer.checkIt.global.config; + +import java.util.List; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +@Getter +@Setter +@NoArgsConstructor +@ConfigurationProperties(prefix = "redis") // 설정 값을 불러올 때 prefix 값을 지정할 수 있다. +@Configuration +public class RedisInfo { + private String host; + private int port; + private RedisInfo master; + private List slaves; +} diff --git a/src/main/java/com/techeer/checkIt/global/config/RedisRepositoryConfig.java b/src/main/java/com/techeer/checkIt/global/config/RedisRepositoryConfig.java index eb44825..f6c32d2 100644 --- a/src/main/java/com/techeer/checkIt/global/config/RedisRepositoryConfig.java +++ b/src/main/java/com/techeer/checkIt/global/config/RedisRepositoryConfig.java @@ -1,11 +1,11 @@ package com.techeer.checkIt.global.config; import lombok.RequiredArgsConstructor; -import org.springframework.boot.autoconfigure.data.redis.RedisProperties; 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.RedisConnectionFactory; -import org.springframework.data.redis.connection.RedisStandaloneConfiguration; +import org.springframework.data.redis.connection.RedisNode; import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.repository.configuration.EnableRedisRepositories; @@ -15,24 +15,30 @@ @Configuration @EnableRedisRepositories public class RedisRepositoryConfig { - private final RedisProperties redisProperties; // lettuce // RedisConnectionFactory 인터페이스를 통해 LettuceConnectionFactory를 생성하여 반환한다. // RedisProperties로 yaml에 저장한 host, post를 가지고 와서 연결한다. + @Bean - public RedisConnectionFactory redisConnectionFactory(){ - return new LettuceConnectionFactory(redisProperties.getHost(), redisProperties.getPort()); + public RedisConnectionFactory redisConnectionFactory() { + RedisClusterConfiguration clusterConfig = new RedisClusterConfiguration(); + clusterConfig.addClusterNode(new RedisNode("127.0.0.1", 7001)); + clusterConfig.addClusterNode(new RedisNode("127.0.0.1", 7002)); + clusterConfig.addClusterNode(new RedisNode("127.0.0.1", 7003)); + clusterConfig.addClusterNode(new RedisNode("127.0.0.1", 7101)); + clusterConfig.addClusterNode(new RedisNode("127.0.0.1", 7102)); + clusterConfig.addClusterNode(new RedisNode("127.0.0.1", 7103)); + + return new LettuceConnectionFactory(clusterConfig); } - // setKeySerializer, setValueSerializer 설정으로 redis-cli를 통해 직접 데이터를 보는게 가능하다. @Bean public RedisTemplate redisTemplate() { RedisTemplate redisTemplate = new RedisTemplate<>(); redisTemplate.setKeySerializer(new StringRedisSerializer()); redisTemplate.setValueSerializer(new StringRedisSerializer()); redisTemplate.setConnectionFactory(redisConnectionFactory()); - redisTemplate.setEnableTransactionSupport(true); return redisTemplate; } @@ -42,7 +48,6 @@ public RedisTemplate redisLikeTemplate() { redisTemplate.setKeySerializer(new StringRedisSerializer()); redisTemplate.setValueSerializer(new StringRedisSerializer()); redisTemplate.setConnectionFactory(redisConnectionFactory()); - redisTemplate.setEnableTransactionSupport(true); return redisTemplate; } } From 55d59f9a92d8d9f45ef1ecc8bc8bdfb039365075 Mon Sep 17 00:00:00 2001 From: fnzl54 Date: Thu, 21 Sep 2023 21:41:04 +0900 Subject: [PATCH 3/4] chore: update security submodule --- src/main/resources/security | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/security b/src/main/resources/security index 3899100..9f706a8 160000 --- a/src/main/resources/security +++ b/src/main/resources/security @@ -1 +1 @@ -Subproject commit 389910087ad62ff547fdeaf643604efcaef1a1e3 +Subproject commit 9f706a81f4e667bc2f3f27488c86d8b90c94d5b5 From bc0b3106e30ad98b55406ae1f7d5149a9413a616 Mon Sep 17 00:00:00 2001 From: fnzl54 Date: Fri, 6 Oct 2023 11:47:06 +0900 Subject: [PATCH 4/4] chore: update security submodule --- src/main/resources/security | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/security b/src/main/resources/security index 9f706a8..60f7214 160000 --- a/src/main/resources/security +++ b/src/main/resources/security @@ -1 +1 @@ -Subproject commit 9f706a81f4e667bc2f3f27488c86d8b90c94d5b5 +Subproject commit 60f7214407bcc48a94f3b61b635a0380669e2445