SMALL
MongoDB는 문서(Document) 기반 오픈 소스 데이터베이스입니다. MongoDB는 Oracle, Mysql, PostgreSQL 같은 관계형 데이터베이스 보다 덜 제한적인 일관성 모델을 이용하는 데이터의 단순 저장 및 검색을 위한 메커니즘을 제공하는 NoSQL로 분류됩니다.
환경 정보
- 운영 체제 : CentOS 7.9
- 실행 계정 : root
- SSH 접속 및 외부 인터넷이 가능한 네트워크 설정
YUM 리포지토리 추가하기
MongoDB 패키지를 제공하는 YUM 리포지토리 추가를 위해 다음 명령을 실행하여 /etc/yum.repos.d/mongodb-org-5.0.repo 파일을 생성합니다.
cat <<EOF> /etc/yum.repos.d/mongodb-org-5.0.repo [mongodb-org-5.0] name=MongoDB Repository baseurl= https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/5.0/x86_64/ gpgcheck=1 enabled=1 gpgkey=https://www.mongodb.org/static/pgp/server-5.0.asc EOF |
MongoDB 이전 버전을 설치하려면 baseurl 라인의 버전 정보인 5.0을 4.x로 변경하고, gpgkey 라인의 5.0을 4.0으로 변경하고 설치하시면 됩니다. /etc/yum.repos.d/mongodb-org-5.0.repo : [mongodb-org-5.0] name=MongoDB Repository baseurl= https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/5.0/x86_64/ gpgcheck=1 enabled=1 gpgkey=https://www.mongodb.org/static/pgp/server-5.0.asc |
yum repolist 명령을 실행하여 MongoDB 리포지토리가 추가되었는지 확인합니다.
yum repolist |
[root@infracody.com ~]# yum repolist repo id repo name status base/7/x86_64 CentOS-7 - Base 10,072 *epel/x86_64 Extra Packages for Enterprise Linux 7 - x86_64 13,756 extras/7/x86_64 CentOS-7 - Extras 513 mongodb-org-5.0 MongoDB Repository 116 updates/7/x86_64 CentOS-7 - Updates 3,773 zabbix/x86_64 Zabbix Official Repository - x86_64 266 zabbix-non-supported/x86_64 Zabbix Official Repository non-supported - x86_64 5 repolist: 28,501 |
MongoDB 패키지 설치하기
yum install -y mongodb-org 명령을 실행하여 MongoDB를 설치합니다.
yum install -y mongodb-org |
[root@infracody.com ~]# yum install -y mongodb-org base | 3.6 kB 00:00:00 epel/x86_64/metalink | 6.6 kB 00:00:00 extras | 2.9 kB 00:00:00 mongodb-org-5.0 | 2.5 kB 00:00:00 updates | 2.9 kB 00:00:00 zabbix | 2.9 kB 00:00:00 zabbix-non-supported | 2.9 kB 00:00:00 (1/10): base/7/x86_64/group_gz | 153 kB 00:00:00 (2/10): base/7/x86_64/primary_db | 6.1 MB 00:00:00 (3/10): epel/x86_64/group_gz | 96 kB 00:00:00 (4/10): epel/x86_64/updateinfo | 1.0 MB 00:00:00 (5/10): extras/7/x86_64/primary_db | 247 kB 00:00:00 (6/10): epel/x86_64/primary_db | 7.0 MB 00:00:00 (7/10): updates/7/x86_64/primary_db | 15 MB 00:00:00 (8/10): zabbix-non-supported/x86_64/primary_db | 3.7 kB 00:00:00 (9/10): mongodb-org-5.0/7/primary_db | 77 kB 00:00:00 (10/10): zabbix/x86_64/primary_db | 158 kB 00:00:00 Resolving Dependencies --> Running transaction check ---> Package mongodb-org.x86_64 0:5.0.8-1.el7 will be installed --> Processing Dependency: mongodb-org-database for package: mongodb-org-5.0.8-1.el7.x86_64 --> Processing Dependency: mongodb-org-tools for package: mongodb-org-5.0.8-1.el7.x86_64 --> Processing Dependency: mongodb-mongosh for package: mongodb-org-5.0.8-1.el7.x86_64 --> Running transaction check ---> Package mongodb-mongosh.x86_64 0:1.4.2-1.el8 will be installed ---> Package mongodb-org-database.x86_64 0:5.0.8-1.el7 will be installed --> Processing Dependency: mongodb-org-server for package: mongodb-org-database-5.0.8-1.el7.x86_64 --> Processing Dependency: mongodb-org-mongos for package: mongodb-org-database-5.0.8-1.el7.x86_64 --> Processing Dependency: mongodb-org-shell for package: mongodb-org-database-5.0.8-1.el7.x86_64 --> Processing Dependency: mongodb-org-database-tools-extra for package: mongodb-org-database-5.0.8-1.el7.x86_64 ---> Package mongodb-org-tools.x86_64 0:5.0.8-1.el7 will be installed --> Processing Dependency: mongodb-database-tools for package: mongodb-org-tools-5.0.8-1.el7.x86_64 --> Running transaction check ---> Package mongodb-database-tools.x86_64 0:100.5.2-1 will be installed --> Processing Dependency: cyrus-sasl-gssapi for package: mongodb-database-tools-100.5.2-1.x86_64 --> Processing Dependency: cyrus-sasl-plain for package: mongodb-database-tools-100.5.2-1.x86_64 --> Processing Dependency: cyrus-sasl for package: mongodb-database-tools-100.5.2-1.x86_64 ---> Package mongodb-org-database-tools-extra.x86_64 0:5.0.8-1.el7 will be installed ---> Package mongodb-org-mongos.x86_64 0:5.0.8-1.el7 will be installed ---> Package mongodb-org-server.x86_64 0:5.0.8-1.el7 will be installed ---> Package mongodb-org-shell.x86_64 0:5.0.8-1.el7 will be installed --> Running transaction check ---> Package cyrus-sasl.x86_64 0:2.1.26-24.el7_9 will be installed ---> Package cyrus-sasl-gssapi.x86_64 0:2.1.26-24.el7_9 will be installed ---> Package cyrus-sasl-plain.x86_64 0:2.1.26-24.el7_9 will be installed --> Finished Dependency Resolution Dependencies Resolved ================================================================================================================================================= Package Arch Version Repository Size ================================================================================================================================================= Installing: mongodb-org x86_64 5.0.8-1.el7 mongodb-org-5.0 6.1 k Installing for dependencies: cyrus-sasl x86_64 2.1.26-24.el7_9 updates 88 k cyrus-sasl-gssapi x86_64 2.1.26-24.el7_9 updates 41 k cyrus-sasl-plain x86_64 2.1.26-24.el7_9 updates 39 k mongodb-database-tools x86_64 100.5.2-1 mongodb-org-5.0 47 M mongodb-mongosh x86_64 1.4.2-1.el8 mongodb-org-5.0 39 M mongodb-org-database x86_64 5.0.8-1.el7 mongodb-org-5.0 6.2 k mongodb-org-database-tools-extra x86_64 5.0.8-1.el7 mongodb-org-5.0 11 k mongodb-org-mongos x86_64 5.0.8-1.el7 mongodb-org-5.0 20 M mongodb-org-server x86_64 5.0.8-1.el7 mongodb-org-5.0 28 M mongodb-org-shell x86_64 5.0.8-1.el7 mongodb-org-5.0 15 M mongodb-org-tools x86_64 5.0.8-1.el7 mongodb-org-5.0 6.1 k Transaction Summary ================================================================================================================================================= Install 1 Package (+11 Dependent packages) Total download size: 149 M Installed size: 557 M Downloading packages: (1/12): cyrus-sasl-gssapi-2.1.26-24.el7_9.x86_64.rpm | 41 kB 00:00:00 (2/12): cyrus-sasl-2.1.26-24.el7_9.x86_64.rpm | 88 kB 00:00:00 (3/12): cyrus-sasl-plain-2.1.26-24.el7_9.x86_64.rpm | 39 kB 00:00:00 warning: /var/cache/yum/x86_64/7/mongodb-org-5.0/packages/mongodb-mongosh-1.4.2.el7.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID e2c63c11: NOKEY Public key for mongodb-mongosh-1.4.2.el7.x86_64.rpm is not installed (4/12): mongodb-mongosh-1.4.2.el7.x86_64.rpm | 39 MB 00:00:00 (5/12): mongodb-org-5.0.8-1.el7.x86_64.rpm | 6.1 kB 00:00:00 (6/12): mongodb-org-database-5.0.8-1.el7.x86_64.rpm | 6.2 kB 00:00:00 (7/12): mongodb-database-tools-100.5.2.x86_64.rpm | 47 MB 00:00:01 (8/12): mongodb-org-database-tools-extra-5.0.8-1.el7.x86_64.rpm | 11 kB 00:00:00 (9/12): mongodb-org-server-5.0.8-1.el7.x86_64.rpm | 28 MB 00:00:00 (10/12): mongodb-org-mongos-5.0.8-1.el7.x86_64.rpm | 20 MB 00:00:00 (11/12): mongodb-org-tools-5.0.8-1.el7.x86_64.rpm | 6.1 kB 00:00:00 (12/12): mongodb-org-shell-5.0.8-1.el7.x86_64.rpm | 15 MB 00:00:00 ------------------------------------------------------------------------------------------------------------------------------------------------- Total 44 MB/s | 149 MB 00:00:03 Retrieving key from https://www.mongodb.org/static/pgp/server-5.0.asc Importing GPG key 0xE2C63C11: Userid : "MongoDB 5.0 Release Signing Key <packaging@mongodb.com>" Fingerprint: f567 9a22 2c64 7c87 527c 2f8c b00a 0bd1 e2c6 3c11 From : https://www.mongodb.org/static/pgp/server-5.0.asc Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : mongodb-org-database-tools-extra-5.0.8-1.el7.x86_64 1/12 Installing : mongodb-org-server-5.0.8-1.el7.x86_64 2/12 Created symlink from /etc/systemd/system/multi-user.target.wants/mongod.service to /usr/lib/systemd/system/mongod.service. Installing : cyrus-sasl-plain-2.1.26-24.el7_9.x86_64 3/12 Installing : cyrus-sasl-2.1.26-24.el7_9.x86_64 4/12 Installing : mongodb-mongosh-1.4.2-1.el8.x86_64 5/12 Installing : mongodb-org-mongos-5.0.8-1.el7.x86_64 6/12 Installing : cyrus-sasl-gssapi-2.1.26-24.el7_9.x86_64 7/12 Installing : mongodb-database-tools-100.5.2-1.x86_64 8/12 Installing : mongodb-org-tools-5.0.8-1.el7.x86_64 9/12 Installing : mongodb-org-shell-5.0.8-1.el7.x86_64 10/12 Verifying : cyrus-sasl-gssapi-2.1.26-24.el7_9.x86_64 2/12 Verifying : mongodb-org-mongos-5.0.8-1.el7.x86_64 3/12 Verifying : mongodb-org-tools-5.0.8-1.el7.x86_64 4/12 Verifying : mongodb-mongosh-1.4.2-1.el8.x86_64 5/12 Verifying : mongodb-org-database-tools-extra-5.0.8-1.el7.x86_64 6/12 Verifying : mongodb-org-database-5.0.8-1.el7.x86_64 7/12 Verifying : cyrus-sasl-2.1.26-24.el7_9.x86_64 8/12 Verifying : cyrus-sasl-plain-2.1.26-24.el7_9.x86_64 9/12 Verifying : mongodb-database-tools-100.5.2-1.x86_64 10/12 Verifying : mongodb-org-5.0.8-1.el7.x86_64 11/12 Verifying : mongodb-org-server-5.0.8-1.el7.x86_64 12/12 Installed: mongodb-org.x86_64 0:5.0.8-1.el7 Dependency Installed: cyrus-sasl.x86_64 0:2.1.26-24.el7_9 cyrus-sasl-gssapi.x86_64 0:2.1.26-24.el7_9 cyrus-sasl-plain.x86_64 0:2.1.26-24.el7_9 mongodb-database-tools.x86_64 0:100.5.2-1 mongodb-mongosh.x86_64 0:1.4.2-1.el8 mongodb-org-database.x86_64 0:5.0.8-1.el7 mongodb-org-database-tools-extra.x86_64 0:5.0.8-1.el7 mongodb-org-mongos.x86_64 0:5.0.8-1.el7 mongodb-org-server.x86_64 0:5.0.8-1.el7 mongodb-org-shell.x86_64 0:5.0.8-1.el7 mongodb-org-tools.x86_64 0:5.0.8-1.el7 Complete! |
MongoDB 서비스 시작하기
MongoDB 설치하면 mongod.service 서비스 파일이 생성되고, 리부팅 혹은 서버 시작 시 자동으로 MongoDB 서비스를 시작하도록 등록되어 있습니다.
다음 명령을 실행하여 MongoDB 서비스를 시작합니다.
systemctl start mongod |
MongoDB 서비스 상태를 확인합니다.
systemctl status mongod |
[root@infracody.com ~]# systemctl status mongod ● mongod.service - MongoDB Database Server Loaded: loaded (/usr/lib/systemd/system/mongod.service; enabled; vendor preset: disabled) Active: active (running) since Wed 2022-05-18 17:03:05 KST; 1min 10s ago Docs: https://docs.mongodb.org/manual Process: 6385 ExecStart=/usr/bin/mongod $OPTIONS (code=exited, status=0/SUCCESS) Process: 6383 ExecStartPre=/usr/bin/chmod 0755 /var/run/mongodb (code=exited, status=0/SUCCESS) Process: 6378 ExecStartPre=/usr/bin/chown mongod:mongod /var/run/mongodb (code=exited, status=0/SUCCESS) Process: 6376 ExecStartPre=/usr/bin/mkdir -p /var/run/mongodb (code=exited, status=0/SUCCESS) Main PID: 6388 (mongod) CGroup: /system.slice/mongod.service └─6388 /usr/bin/mongod -f /etc/mongod.conf May 18 17:03:04 infracody.com systemd[1]: Starting MongoDB Database Server... May 18 17:03:04 infracody.com mongod[6385]: about to fork child process, waiting until server is ready for connections. May 18 17:03:04 infracody.com mongod[6385]: forked process: 6388 May 18 17:03:05 infracody.com mongod[6385]: child process started successfully, parent exiting May 18 17:03:05 infracody.com systemd[1]: Started MongoDB Database Server. |
MongoDB 접속하기
다음 명령을 실행하여 MongoDB에 Shell로 접속합니다.
mongo |
[root@infracody.com ~]# mongo MongoDB shell version v5.0.8 connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb Implicit session: session { "id" : UUID("f244a546-179e-4fab-ab2a-4da5838b6510") } MongoDB server version: 5.0.8 ================ Warning: the "mongo" shell has been superseded by "mongosh", which delivers improved usability and compatibility.The "mongo" shell has been deprecated and will be removed in an upcoming release. For installation instructions, see https://docs.mongodb.com/mongodb-shell/install/ ================ Welcome to the MongoDB shell. For interactive help, type "help". For more comprehensive documentation, see https://docs.mongodb.com/ Questions? Try the MongoDB Developer Community Forums https://community.mongodb.com --- The server generated these startup warnings when booting: 2022-05-18T17:03:05.200+09:00: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine. See http://dochub.mongodb.org/core/prodnotes-filesystem 2022-05-18T17:03:05.931+09:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted 2022-05-18T17:03:05.931+09:00: /sys/kernel/mm/transparent_hugepage/enabled is 'always'. We suggest setting it to 'never' 2022-05-18T17:03:05.931+09:00: /sys/kernel/mm/transparent_hugepage/defrag is 'always'. We suggest setting it to 'never' --- --- 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() --- > |
BIG