스프링부트와 AWS로 혼자 구현하는 웹서비스

mkdate : 2020-07-09-Thu

Ch07. AWS RDS

대규모 서비스가 아닌 이상, 백엔드 개발자도 일정 수준 이상으로 DB를 다룰 줄 알아야 함

직접 DB를 설치해서 사용하는 경우, 모니터링, 알람, 백업, HA, Hardware Provisioning, Patch, 구성 등 모두 필요

클라우드 기반 관계형 데이터베이스 활용하면, 자동화된 운영 작업으로 개발에만 집중 가능

RDS 인스턴스 생성

DB

MariaDB 추천

라이센스 비용

  • Oracle/MSSQL 등 상용 DB는 오픈소스 DB에 비해 동일한 사용량 대비 가격이 더 높음

Amazon Aurora 교체 용이성

  • MySQL/PostgreSQL을 AWS에 맞게 재구성한 DB
  • RDS MySQL/PostgreSQL 대비 3~5배 성능
  • 다만 최저 월 10만원 이상이므로 서비스 규모가 커지면 이전

동일 하드웨어 사양으로 MySQL 보다 향상된 성능

좀더 활성화된 커뮤니티

다양한 스토리 엔진 등

DB 인스턴스 식별자, 마스터 사용자 설정

네트워크, 보안 설정

  • 퍼블릭 액세스 가능하도록 설정 후, 보안 그룹에서 지정 IP만 접속 가능하도록 설정
  • 접속 포트 확인

추가설정

생성 완료

몇 분 걸림



파라미터 설정

파라미터 그룹 생성

파라미터 그룹 패밀리 : 생성한 DB 버전과 동일하게

파라미터 편집

time_zone

Character Set

characterset *

  • utf8mb4 : 이모지 저장 가능

collation_ *

  • utf8mb4_bin

max_connections

인스턴스에 따라 자동으로 정해짐, 프리티어에서는 약 60개만 가능,

DB에 파라미터 그룹 연결

데이터베이스 수정 > 데이터베이스 옵션 > DB 파라미터 그룹

재부팅

수정 중

사용가능 뜨면

재부팅으로 설정 완료



로컬PC에서 RDS 접속

RDS-EC2 port 설정

데이터베이스 상세보기 > 연결&보안 > VPC 보안그룹

인바운드 규칙 편집

유형 - MYSQL/Aurora 선택; 자동으로 3306 포트 설정

EC2 보안그룹 ID, 내 IP 선택/입력

IntelliJ DB 플러그인 설치

RDS MariaDB 엔드포인트(접속주소) 확인

IntelliJ Ultimate 인 경우 내장 Database 에서 MariaDB 선택
  • 필요한 DB 라이브러리 자동으로 다운로드

Host, Port, User, Password, Database(MySQL) 입력 후 Test Connection

스키마, 사용자 확인

IntelliJ Community 인 경우, Database Navigator 플러그인 설치하여 MySQL로 선택


New Console

콘솔창 생성 후 사용할 Database 선택


use SpringBoot0709;

쿼리 실행 성공 메시지


SpringBoot0709> show variables like 'c%'
[2020-07-09 17:17:57] 20 rows retrieved starting from 1 in 624 ms (execution: 24 ms, fetching: 600 ms)

character_set, collation 설정 확인

character_set_database, collation_connection 은 latin으로 설정되어 있어 변경해야 함


SpringBoot0709> alter database SpringBoot0709
                character set ='utf8mb4'
                collate = 'utf8mb4_general_ci'
[2020-07-09 17:21:33] 1 row affected in 23 ms

-- 변경 결과 확인
SpringBoot0709> show variables like 'c%'

SpringBoot0709> select @@time_zone, now()
[2020-07-09 17:24:26] 1 row retrieved starting from 1 in 194 ms (execution: 38 ms, fetching: 156 ms)

Timezone 확인


SpringBoot0709> create table test (
                    id bigint(20) not null auto_increment,
                    content varchar(255) default null,
                    primary key (id)
                ) engine = innodb
[2020-07-09 17:26:42] completed in 42 ms

SpringBoot0709> insert into test(content) values ('테스트테스트테스트')
[2020-07-09 17:27:17] 1 row affected in 19 ms

SpringBoot0709> select * from test
[2020-07-09 17:27:30] 1 row retrieved starting from 1 in 169 ms (execution: 31 ms, fetching: 138 ms)

한글 입력 테스트



EC2 - RDS 접속 확인

EC2에 SSH 접속


[ec2-user@gitgitwi-spring ~]$ sudo yum install mysql

EC2에서 MySQL 접근 테스트를 위해 MySQL CLI 설치


[ec2-user@gitgitwi-spring ~]$ mysql -u gitgitwi -p -h springboot-0709.cgcwwzekltsf.ap-northeast-2.rds.amazonaws.com
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 36
Server version: 5.5.5-10.3.13-MariaDB Source distribution

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

계정, host url 사용하여 접속 확인


mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| SpringBoot0709     |
| information_schema |
| innodb             |
| mysql              |
| performance_schema |
+--------------------+
5 rows in set (0.00 sec)

database 확인

profile
가볍게 TIL 남기는 velog, 꾸준히 성장하는 개발자

0개의 댓글