안녕하세요. Johncomputer 입니다.
이번에는 아마 최근들어서 더 많은 분들이 이용하고 계신 Aurora MySQL에 대해서 같이 다뤄보려고 합니다.
운영을 하다보면 "자동화", "대규모" 작업을 하게 되는 경우가 있는데
이럴때는 항상 웹 화면에서 하나씩 다루기는 힘들거든요...
그렇다 보니 Lambda 라던가 EC2 아니면 개인 PC에서 CLI로 명령을 할 수 있는 방법이 있는데요
한번 같이 보겠습니다.
디테일한 옵션은 아래에 있고 전 주로 사용하는 스크립트 위주로 올려드릴게요
https://docs.aws.amazon.com/cli/latest/reference/rds/describe-db-clusters.html
describe-db-clusters — AWS CLI 1.38.20 Command Reference
Note: You are viewing the documentation for an older major version of the AWS CLI (version 1). AWS CLI version 2, the latest major version of AWS CLI, is now stable and recommended for general use. To view this page for the AWS CLI version 2, click here. F
docs.aws.amazon.com
1. 기본 사용 명렁어
- 가장 중요한 내용 중 하나인데 DB 개념에서 Cluster, Instance 를 구별해서 볼 수 있어야 합니다.
버전은 Cluster 단위, Type 변경은 Instance 단위로 변경 가능합니다.
#!/bin/bash
# 1. Aurora 클러스터 목록 조회
# 현재 운영 중인 모든 Aurora 클러스터 정보를 확인
aws rds describe-db-clusters
# 2. 특정 클러스터의 상세 정보 조회
# 특정 Aurora 클러스터의 설정 및 상태를 확인
aws rds describe-db-clusters --db-cluster-identifier {my-cluster}
# 3. Aurora 인스턴스 목록 조회
# 현재 운영 중인 모든 데이터베이스 인스턴스를 확인
aws rds describe-db-instances
# 4. 특정 Aurora 인스턴스 상태 조회
# 특정 DB 인스턴스의 상세 정보를 가져옴
aws rds describe-db-instances --db-instance-identifier {my-instance}
# 5. Aurora 클러스터 백업 (스냅샷 생성)
# 클러스터의 백업을 생성하여 데이터 보호
aws rds create-db-cluster-snapshot --db-cluster-snapshot-identifier {my-cluster-snapshot} --db-cluster-identifier {my-cluster}
# 6. 스냅샷 목록 조회
# 생성된 모든 클러스터 스냅샷을 확인
aws rds describe-db-cluster-snapshots
# 7. Aurora 클러스터 복원 (스냅샷에서 복구)
# 기존 백업 스냅샷을 사용하여 새로운 Aurora 클러스터 생성
aws rds restore-db-cluster-from-snapshot --db-cluster-identifier {my-new-cluster} --snapshot-identifier {my-cluster-snapshot}
# 8. Aurora 클러스터 크기 조정 (자동 스케일링 설정 변경)
# Aurora Serverless의 최소 및 최대 용량을 조정
aws rds modify-db-cluster --db-cluster-identifier {my-cluster} --scaling-configuration MinCapacity={2},MaxCapacity={8}
# 9. Aurora 인스턴스 타입 변경 (업그레이드 또는 다운그레이드)
# Aurora 인스턴스의 스펙을 변경 (ex. db.r5.large → db.r6g.large)
aws rds modify-db-instance --db-instance-identifier {my-instance} --db-instance-class {db.r6g.large} --apply-immediately
# 10. Aurora 클러스터 삭제
# 최종 스냅샷 없이 Aurora 클러스터 삭제 (데이터 영구 삭제됨)
aws rds delete-db-cluster --db-cluster-identifier {my-cluster} --skip-final-snapshot
# 11. Aurora 인스턴스 재시작
# 특정 Aurora DB 인스턴스를 재부팅하여 문제 해결
aws rds reboot-db-instance --db-instance-identifier {my-instance}
# 12. Aurora 파라미터 변경
# 특정 파라미터 그룹의 값을 변경하고 적용
aws rds modify-db-cluster-parameter-group --db-cluster-parameter-group-name {my-cluster-param-group} --parameters "ParameterName={max_connections},ParameterValue={500},ApplyMethod=immediate"
# 13. Aurora MySQL 버전 업그레이드
# 기존 Aurora 클러스터의 엔진 버전을 업그레이드 (사전 테스트 필수!)
aws rds modify-db-cluster --db-cluster-identifier {my-cluster} --engine-version {8.0.mysql_aurora.3.04.0} --apply-immediately
2. describe 심화 - 특정 인스턴스 목록 뽑기 jq json
- 아래처럼 쿼리를 이용해서 원하는 출력값만 얻을 수 있습니다.
- output style 은 text, json, table등 보기 편하게도 가능해요
aws rds describe-db-clusters --region ap-northeast-3 --query "DBClusters[?contains(DBClusterIdentifier, '필터값')]" --output json
aws rds describe-db-clusters --query "DBClusters[?contains(DBClusterIdentifier, '필터값')].{DBClusterIdentifier:DBClusterIdentifier, Endpoint:Endpoint, ReaderEndpoint:ReaderEndpoint}" --output text
aws rds describe-db-clusters --query "DBClusters[?contains(DBClusterIdentifier, '필터값')].{DBClusterIdentifier:DBClusterIdentifier, Endpoint:Endpoint, ReaderEndpoint:ReaderEndpoint}" --output table
3. 기타 사용 명령어
--region #실행할 AWS 리전을 지정 --region ap-northeast-2
--output #출력 형식 지정 (json, table, text, yaml) --output table
--query #특정 데이터 필드만 출력 --query "DBClusters[*].DBClusterIdentifier"
--profile #사용할 AWS 프로필 지정 --profile my-profile
--no-paginate #페이지 나누기 없이 전체 데이터 출력 --no-paginate
- paginator의 경우 100개가 넘는 리스트를 다룰 때 사용됩니다.
'프로그래밍 > DB,SQL' 카테고리의 다른 글
MySQL 테이블 DB 사이즈 구하기 - row 개수 / 행 개수 (0) | 2024.10.23 |
---|---|
MySQL 권한 설정 CREATE USER (0) | 2024.06.13 |
MySQL 테스트 데이터 생성하기(Faker) - 아무데이터 넣기 (0) | 2023.03.04 |
MySQL 8.0 Community server 설치 ( 윈도우, 64 bit ) (0) | 2022.11.25 |
ERROR 1872 (HY000) : slave failed to initialize relay log info structure from the repository 에러 해결방법 (0) | 2022.08.25 |