ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • MongoDB 띄우기
    프로젝트/MongoDB 2020. 5. 14. 18:29
    반응형

    0. 설치

     

    https://www.mongodb.com/download-center/community

    맥용 패키지 관리자 이용해서 wget 설치 하고

      -> brew install wget

    wget 통해서 원하는 위치에 패키지 받아서 설치 하자.

      -> wget 'www.fastdl.mongodb.org/osx/mongodb-osx-ssl-x86_64-4.0.18.tgz'

    압축 해제

    압축 해제 후 디렉토리 명 변경

    mv mongodb-osx-x86_64-4.0.18 mongo

     

     


    1. 설정

    출처 사이트 (https://docs.ncloud.com/ko/database/database-10-3.html)

     

    1-1. 설치 디렉토리 하단에 data, config 디렉터리 생성

    1-2.  생성한 config 디렉터리 하단에 mongodb.conf 파일 생성

            ~/mongo/config/mongodb.conf 에 다음을 작성한다.

    systemLog:
      destination: file
      path: "/Users/banesa/Project/DB/mongo/log/mongodb.log"
      logAppend: false
    storage:
      journal:
        enabled: true
        commitIntervalMs: 200
      dbPath:
        "/Users/banesa/Project/DB/mongo/data"
      wiredTiger:
        engineConfig:
          cacheSizeGB: 2
          journalCompressor: snappy
          directoryForIndexes: false
        collectionConfig:
          blockCompressor: snappy
        indexConfig:
          prefixCompression: true
    processManagement:
      fork: true
      pidFilePath: "/Users/banesa/Project/DB/mongo/mongod.pid"
    net:
      bindIp: 127.0.0.1
      port: 27017
    setParameter:
      enableLocalhostAuthBypass: false

     

    2. 데몬 실행

      2-1.  빠른 실행을 위해 ~/mongo/bin/start.sh. 파일을 생성한다. 

    #/bin/sh
    ./mongod -config ../config/mongodb.conf

      2-2. 실행 모드로 변경한다

    chmod +x start.sh

      2-3. 실행한다.

     

    3. 로그 확인

      데몬을 실행하면 /log 디렉터리에 log파일이 생긴다.

    tail -f mongodb.log

     

    4. 접속

      bin> 에서 mongo를 실행 시키면 mongoDB에 접속한다.

    ➜  bin ./mongo
    MongoDB shell version v4.0.18
    connecting to: mongodb://127.0.0.1:27017/?gssapiServiceName=mongodb
    Implicit session: session { "id" : UUID("fc6fce73-3ca2-44e0-9a60-9b123c8a8f27") }
    MongoDB server version: 4.0.18
    Welcome to the MongoDB shell.
    For interactive help, type "help".
    For more comprehensive documentation, see
    	http://docs.mongodb.org/
    Questions? Try the support group
    	http://groups.google.com/group/mongodb-user
    Server has startup warnings:
    2020-05-14T18:40:26.092+0900 I CONTROL  [initandlisten]
    2020-05-14T18:40:26.092+0900 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
    2020-05-14T18:40:26.093+0900 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
    2020-05-14T18:40:26.094+0900 I CONTROL  [initandlisten]
    2020-05-14T18:40:26.094+0900 I CONTROL  [initandlisten]
    2020-05-14T18:40:26.095+0900 I CONTROL  [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
    ---
    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()
    ---
    
    >

    5. DB 생성

      5-1. use database 를 통해 데이터 베이스 생성 (존재할 경우 스위치) 

    > use maheart
    switched to db maheart

    5-2. 컬렉션 생성 ( 참고 : https://docs.mongodb.com/manual/reference/method/db.createCollection/)

    > db -- 현재 선택된 디비 확인
    maheart
    > db.createCollection('gallery')  --컬렉션 생성(테이블 개념)
    { "ok" : 1 }
    > db.createCollection('gallery', {capped:true,
    ... autoIndex:true,
    ... size:5242880,
    ... max:10000
    ... })  -- 컬렉션 설정정보 세팅
    {
    	"ok" : 0,
    	"errmsg" : "The field 'autoIndex' is not a valid collection option. Options: { capped: true, autoIndex: true, size: 5242880.0, max: 10000.0 }",
    	"code" : 72,
    	"codeName" : "InvalidOptions"
    }


    6. 계정 넣기

    ./mongo 접속 후에 admin디비로 접근한다.

    계정을 생성한다.

    To enable free monitoring, run the following command: db.enableFreeMonitoring()
    To permanently disable this reminder, run the following command: db.disableFreeMonitoring()
    ---
    
    > use admin
    switched to db admin
    > db.createUser({ user:'admin', pwd:’1234’, roles:['userAdminAnyDatabase'] })
    2020-05-14T23:47:30.357+0900 E QUERY    [js] SyntaxError: illegal character @(shell):1:34
    > db.createUser({ user:'admin', pwd:'1234',
    ...  roles:['userAdminAnyDatabase'] })
    Successfully added user: { "user" : "admin", "roles" : [ "userAdminAnyDatabase" ] }
    >

     

     

    반응형

    '프로젝트 > MongoDB' 카테고리의 다른 글

    MongoDB 쉽게 조회 하기 (with Robomongo)  (0) 2020.05.18
Designed by Tistory.