하트위키
최근 변경
최근 토론
임의 문서
도구
최근 변경
MongoDB
(r12 편집)
[오류!]
편집 권한이 부족합니다. 로그인된 사용자(이)여야 합니다. 해당 문서의
ACL 탭
을 확인하시기 바랍니다.
닫기
RAW 편집
[[분류:DB]] [목차] == 개요 == *MongoDB [* 거대한 DB(humongous DB)에서 따옴] *몽고DB *NoSQL DB의 일종 *도큐먼트 지향 DB *고성능, 스키마 없음. 오픈소스 *쿼리, 인덱스 용이 *BSON[* 바이너리 JSON]으로 계층형 데이터 표현 *AP특성에 맞는 구조로 데이터를 격납 *JSON 형식의 데이터를 REST 엔드포인트로 송수신 *자바스크립트, JSON 문법으로 데이터 질의, 조작 가능 *서비스 기본포트: 27017 == 설치 Guide == *MongoDB 는 공식사이트의 Install 문서가 정말 잘 정리되어 있기로 유명하다. *굳이 다른 블로그나 AI문의하기 보단 공식 문서를 참조해보고, 잘 안되는 부분은 검색을 활용해서 해결하자. *[[Ubuntu]] 계열 설치 방법: [[https://www.mongodb.com/ko-kr/docs/manual/tutorial/install-mongodb-on-ubuntu/|우분투 설치 공식 문서]] *[[Red Hat]] 계열 설치 방법: [[https://www.mongodb.com/ko-kr/docs/manual/tutorial/install-mongodb-on-red-hat/| Red Hat계열 설치 공식 문서]] *[[Debian]] 계열 설치 방법: [[https://www.mongodb.com/ko-kr/docs/manual/tutorial/install-mongodb-on-debian/|Debian 계열 설치 공식 문서]] === 설치 후 최초 설정 === *{{{#FC457A 아래 내용은 mongoDB 8버전대 기준으로 설명함.}}} *mongosh 명령어로 mongoDB CLI 환경 진입 *db.createUser를 통해 admin ID 생성 *예시 {{{db.createUser( { user: "kskim", pwd: passwordPrompt(), roles: [ { role: "userAdminAnyDatabase", db: "admin" }, { role: "readWriteAnyDatabase", db: "admin" } ] } ) }}} *이후 admin ID를 통해 다른 사용자 ID나 추가 작업 수행 *예시 >{{{#FC457A #}}}mongosh >Current Mongosh Log ID: 67f745b38d50f7b8b9d861df >Connecting to: mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&>appName=mongosh+2.5.0 >Using MongoDB: 8.0.6 >Using Mongosh: 2.5.0 > >For mongosh info see: https://www.mongodb.com/docs/mongodb-shell/ > > >To help improve our products, anonymous usage data is collected and sent to MongoDB periodically (https://www.mongodb.com/legal/privacy-policy). >You can opt-out by running the disableTelemetry() command. > >------ > The server generated these startup warnings when booting > 2025-04-10T02:35:54.496+00:00: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine. See http://dochub.mongodb.org/core/prodnotes-filesystem > 2025-04-10T02:35:56.152+00:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted > 2025-04-10T02:35:56.155+00:00: You are running on a NUMA machine. We suggest launching mongod like this to avoid performance problems: numactl --interleave=all mongod [other options] > 2025-04-10T02:35:56.156+00:00: For customers running the current memory allocator, we suggest changing the contents of the following sysfsFile > 2025-04-10T02:35:56.156+00:00: For customers running the current memory allocator, we suggest changing the contents of the following sysfsFile > 2025-04-10T02:35:56.156+00:00: We suggest setting the contents of sysfsFile to 0. > 2025-04-10T02:35:56.156+00:00: We suggest setting swappiness to 0 or 1, as swapping can cause performance problems. >------ > >{{{#FC457A test>}}} use admin >switched to db admin >{{{#FC457A admin>}}} db.createUser( >... { >... user: "kskim", >... pwd: passwordPrompt(), >... roles: [ >... { role: "userAdminAnyDatabase", db: "admin" }, >... { role: "readWriteAnyDatabase", db: "admin" } >... ] >... } >... ) >Enter password >**********{ ok: 1 } >{{{#FC457A admin>}}} exit == 백업 및 복구 == *{{{#FC457A 아래 내용은 mongoDB 8버전대 기준으로 설명함.}}} *역시 공식 사이트에 백업 방법들과 예시가 소개가 되어있다. *공식 사이트 백업파트: [[https://www.mongodb.com/ko-kr/docs/manual/tutorial/backup-and-restore-tools/|백업 공식 문서]] *여기에서는 실제 일부 명령어만 기록한다. === 백업 === >mongodump -u <유저명> -p <비밀번호> --authenticationDatabase admin [* <인증DB> 이름이 다를 경우 다른걸 쓴다. 보통은 admin] \--db <원하는 DB> \--out <백업 디렉토리> > >-예시 >mongodump -u userKskim -p 'password123'[* 반드시 ''로 감싸야한다] \--authenticationDatabase admin \--db myDbName \--out /home/backup/mongo/ === 복원 === >mongorestore -u <유저명> -p <비밀번호>[* 마찬가지로 반드시 ''로 감싸야한다] \--authenticationDatabase admin[* authenticationDatabase를 명시하지 않으면 기본적으로 myDbName에서 인증정보를 찾는다. 꼭 명시하도록 하자] \--db myDbName /home/backup/mongo/myDbName/ *이후 해당 DB CLI 또는 UI Client로 접속해서 해당 DB값을 확인한다. === 복원 후 확인 방법 === *mongoDB shell(mongosh) CLI 진입 후 *DB전체의 용량 확인. *전체 용량이 비슷하다면 잘 복원되었을 가능성이 높다. >db.stats().dataSize *Collection 개수 확인. *양쪽의 Collection의 개수를 확인한다. >show collections *각 collection 별로 내부 데이터 개수 확인. >db.(coleection 이름).estimatedDocumentCount()
Liberty
|
the tree