LambFerret's Blog

#1 <‎AWS ec2와 mongo atlas free-tier‎‎> 본문

스터디/삽질기록

#1 <‎AWS ec2와 mongo atlas free-tier‎‎>

램페럿 2022. 11. 3. 18:30

잡담 :

더보기

이전 포스트와 1년의 공백기 사이에 많은 일이 있었다. 그 많은일에는 취직과 퇴사, 퇴사후 유럽여행까지 포함되어있다. 일기장마냥 전부 적지는 않겠지만 여러분들께 한가지 추천하는게 있다면 : 동유럽 여행을 꼭 가봅시다.

오흐리드 호수, 북마케도니아. 멋있다

퇴사 이후 작은 프로젝트를 하고싶던 나는 친구들과 놀던 디스코드에서 디스코드 봇이라는 것이 있다는걸 처음 알았다. 트위치를 자주 보기도 하고 트위치와 관련된 나만의 디스코드 봇이 있으면 어떨까 싶은 마음에 nodeJS를 사용하여 몇가지 기능을 만들고 이를 AWS EC2에 배포하였다.

간단히 만든 작업물. 이름은 조교쨩이다

여러곳의 디스코드 서버에서 각기 다른 설정을 하기 위해서는 DB가 필요하다는 것을 깨닿고 mongoDB와 연동시키는 것을 시도하였다.

우선 mongoDB atlas의 무료 체험판으로 연동해보기로 하였다. mongoDB의 선택이유는 간단했다 : 회사에서 쓰던 스택이라서

분명 mySQL이나 mariaDB같은 RDB를 쓰는게 적합해보인다. 하지만 나는 JSON 데이터 형식을 사용하는 NodeJS로서는 mongoDB의 BSON 형식의 적재가 DB 및 백엔드 동시설계에서 편리한 이점을 준다고 생각한다. 즉, 넣는대로 넣어지면 당장은 좋다~ 라는것이다.

무료체험판이라는 것을 왜 굳이 써넣었느냐? 결론부터 말하자면

 

 

 

주의! AWS와 atlas Free-tier는 연동이 안된다. 이는 도큐먼트(VPC-peering)에도 명시되어있다.

 

Feature unavailable in Free and Shared-Tier Clusters

This feature is not available for M0 free clusters, M2, and M5 clusters. To learn more about which features are unavailable, see Atlas M0 (Free Cluster), M2, and M5 Limitations.

 

(대충 mongoDB 의 VPC를 AWS와 peering할 수 없다는 뜻)

 

즉 대안으로 ec2에 mongoDB를 설치해야한다.

 

주의 : ubuntu 22.04 에서는 설치가 불가능하다. (적어도 만들었던 현재는 그렇다)

(출처 : https://www.mongodb.com/community/forums/t/installing-mongodb-over-ubuntu-22-04/159931)

 

 

설치법 공식 도큐먼트

  1. 공개키 import
$wget -qO - https://www.mongodb.org/static/pgp/server-6.0.asc | sudo apt-key add -

gnupg가 설치되어있지 않은경우 먼저

sudo apt-get install gnupg

이후 공개키 import를 한다.

  1. list file 생성
$echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/6.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list
  1. apt 업데이트
$sudo apt-get update
  1. 대망의 다운로드
$sudo apt-get install -y mongodb-org
  1. mongod 프로세스 실행
$sudo systemctl start mongod
  1. mongo shell 실행
$mongosh

Current Mongosh Log ID: 6364b2b6b333ed8617419dd9
Connecting to:          mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+1.5.4
Using MongoDB:          5.0.10
Using Mongosh:          1.5.4

For mongosh info see: https://docs.mongodb.com/mongodb-shell/

------
   The server generated these startup warnings when booting
   2022-08-05T16:56:58.341+00:00: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine. See http://dochub.mongodb.org/core/prodnotes-filesystem
   2022-08-05T16:57:02.330+00:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted
------

------
   Enable MongoDB's free cloud-based monitoring service, which will then receive and display
   metrics about your deployment (disk utilization, CPU, operation statistics, etc).
   
   The monitoring data will be available on a MongoDB website with a unique URL accessible to you
   and anyone you share the URL with. MongoDB may use this information to make product
   improvements and to suggest MongoDB products and deployment options to you.
   
   To enable free monitoring, run the following command: db.enableFreeMonitoring()
   To permanently disable this reminder, run the following command: db.disableFreeMonitoring()
------

Warning: Found ~/.mongorc.js, but not ~/.mongoshrc.js. ~/.mongorc.js will not be loaded.
  You may want to copy or rename ~/.mongorc.js to ~/.mongoshrc.js.
test>

결과. db이름이 test다

잡담2

더보기

제목에서 꺽쇠가 영어로 시작하면 인식못한다 ㅋㅋ 놀랐자나~

Comments