mongoDB 설치 및 환경 구축

이해하기 쉽고, 장황하지 않은 자료를 기반으로 강의를 진행합니다.
잔재미코딩 소식 공유
좀더 제약없이, IT 컨텐츠를 공유하고자, 자체 온라인 사이트와, 다음 두 채널도 오픈하였습니다
응원해주시면, 곧 좋은 컨텐츠를 만들어서 공유하겠습니다
●  잔재미코딩 뉴스레터 오픈 [구독해보기]
●  잔재미코딩 유투브 오픈 [구독해보기]

2. mongoDB 설치 및 환경 구축

2.1. EC2(AWS 서버)에 mongodb 설치 방법 (ubuntu 기반)

  • Import the public key(GPG key) used by the package management system.
    • sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6
  • Create a list file for MongoDB.
  • Reload local package database.
    • sudo apt-get update
  • Install the MongoDB packages.
    • sudo apt-get install -y mongodb-org
    • mpngodb-org 패키지: A metapackage that will automatically install the four component packages, mongodb-org-server, mongodb-org-mongos, mongodb-org-shell, and mongodb-org-tools
    • The MongoDB instance stores its data files in /var/lib/mongodb and its log files in /var/log/mongodb by default, and runs using the mongodb user account. You can specify alternate log and data file directories in /etc/mongod.conf.
  • Start MongoDB
    • sudo service mongod start
  • Verify that MongoDB has started successfully
    • Verify that the mongod process has started successfully by checking the contents of the log file at /var/log/mongodb/mongod.log for a line reading
    • [initandlisten] waiting for connections on port
    • where is the port configured in /etc/mongod.conf, 27017 by default.
  • Stop MongoDB
    • sudo service mongod stop

2.2. EC2(AWS 서버)에 mongodb 설정 방법 (ubuntu 기반)

  • AWS Management Console -> EC2 -> Security Groups -> EC2's Security Group -> Add Custom TCP Rule, 27017, AnyWhere

  • 외부 접속 허용

    • sudo vi /etc/mongod.conf
      • bindIp: 0.0.0.0 으로 변경
    • sudo service mongod restart
  • 계정을 만들어야 함 (그렇지 않으면 외부에서 해당 포트/주소로 아무나 접속이 가능하기 때문)

    • EC2 에서 다음 명령 실행
mongo
use admin
db.createUser( 
    {   user: "davelee",
        pwd: "korea123",
        roles: [ "userAdminAnyDatabase",
        "dbAdminAnyDatabase",
        "readWriteAnyDatabase"] 
    } 
)
    - sudo vim /etc/mongod.conf
    - Add the following configurations
security:
  authorization: enabled
   - sudo service mongod restart