mongoDB 설치 및 환경 구축

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:// --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: 으로 변경
    • sudo service mongod restart
  • 계정을 만들어야 함 (그렇지 않으면 외부에서 해당 포트/주소로 아무나 접속이 가능하기 때문)

    • EC2 에서 다음 명령 실행
use admin
    {   user: "davelee",
        pwd: "korea123",
        roles: [ "userAdminAnyDatabase",
    - sudo vim /etc/mongod.conf
    - Add the following configurations
  authorization: enabled
   - sudo service mongod restart