MongoDB v6.0
CentOS 7.x로 진행됩니다.
1. yum repository 추가
[root@mongodb-01 ~]# vi /etc/yum.repos.d/mongodb-org-6.0.repo
[mongodb-org-6.0]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/6.0/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-6.0.asc
2. yum repository 확인
yum list 명령어를 통해 mongodb 관련 패키지가 정상적으로 보이는지 확인할 수 있습니다.
[root@mongodb-01 ~]# yum list | grep 'mongodb'
mongocli.x86_64 1.27.0-1 mongodb-org-6.0
mongodb-atlas.x86_64 1.3.0-1 mongodb-org-6.0
mongodb-atlas-cli.x86_64 1.3.0-1 mongodb-org-6.0
mongodb-database-tools.x86_64 100.6.1-1 mongodb-org-6.0
mongodb-mongosh.x86_64 1.6.0-1.el8 mongodb-org-6.0
mongodb-mongosh-shared-openssl11.x86_64 1.6.0-1.el8 mongodb-org-6.0
mongodb-mongosh-shared-openssl3.x86_64 1.6.0-1.el8 mongodb-org-6.0
mongodb-org.x86_64 6.0.3-1.el7 mongodb-org-6.0
mongodb-org-database.x86_64 6.0.3-1.el7 mongodb-org-6.0
mongodb-org-database-tools-extra.x86_64 6.0.3-1.el7 mongodb-org-6.0
mongodb-org-mongos.x86_64 6.0.3-1.el7 mongodb-org-6.0
mongodb-org-server.x86_64 6.0.3-1.el7 mongodb-org-6.0
mongodb-org-tools.x86_64 6.0.3-1.el7 mongodb-org-6.0
3. MongoDB 설치하기
-y 옵션을 주면 확인이 없이 설치가 가능합니다.
[root@mongodb-01 ~]# yum install mongodb-org
....
...
..
.
Dependencies Resolved
=========================================================================================================================================================================================================================================
Package Arch Version Repository Size
=========================================================================================================================================================================================================================================
Installing:
mongodb-org x86_64 6.0.3-1.el7 mongodb-org-6.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
mongodb-database-tools x86_64 100.6.1-1 mongodb-org-6.0 48 M
mongodb-mongosh x86_64 1.6.0-1.el8 mongodb-org-6.0 41 M
mongodb-org-database x86_64 6.0.3-1.el7 mongodb-org-6.0 6.2 k
mongodb-org-database-tools-extra x86_64 6.0.3-1.el7 mongodb-org-6.0 11 k
mongodb-org-mongos x86_64 6.0.3-1.el7 mongodb-org-6.0 21 M
mongodb-org-server x86_64 6.0.3-1.el7 mongodb-org-6.0 31 M
mongodb-org-tools x86_64 6.0.3-1.el7 mongodb-org-6.0 6.1 k
Transaction Summary
=========================================================================================================================================================================================================================================
Install 1 Package (+9 Dependent packages)
Total download size: 142 M
Installed size: 562 M
Is this ok [y/d/N]: y # -y 옵션을 안줬으면 y를 눌러 설치 진행
...
..
.
Installed:
mongodb-org.x86_64 0:6.0.3-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 mongodb-database-tools.x86_64 0:100.6.1-1 mongodb-mongosh.x86_64 0:1.6.0-1.el8 mongodb-org-database.x86_64 0:6.0.3-1.el7
mongodb-org-database-tools-extra.x86_64 0:6.0.3-1.el7 mongodb-org-mongos.x86_64 0:6.0.3-1.el7 mongodb-org-server.x86_64 0:6.0.3-1.el7 mongodb-org-tools.x86_64 0:6.0.3-1.el7
Complete!
4. MongoDB 설치 확인
MongoDB의 서비스 명은 mongod입니다. 이 서비스의 상태를 확인하여 정상 설치되었는지 확인할 수 있습니다.
[root@crinity-mongodb-01 ~]# systemctl start mongod # MongoDB 서비스 시작
[root@crinity-mongodb-01 ~]# systemctl status mongod # MongoDB 서비스 상태 확인
● mongod.service - MongoDB Database Server
Loaded: loaded (/usr/lib/systemd/system/mongod.service; enabled; vendor preset: disabled)
Active: active (running) since Mon 2022-11-28 11:27:37 KST; 3s ago
Docs: https://docs.mongodb.org/manual
Process: 8984 ExecStart=/usr/bin/mongod $OPTIONS (code=exited, status=0/SUCCESS)
Process: 8981 ExecStartPre=/usr/bin/chmod 0755 /var/run/mongodb (code=exited, status=0/SUCCESS)
Process: 8979 ExecStartPre=/usr/bin/chown mongod:mongod /var/run/mongodb (code=exited, status=0/SUCCESS)
Process: 8977 ExecStartPre=/usr/bin/mkdir -p /var/run/mongodb (code=exited, status=0/SUCCESS)
Main PID: 8987 (mongod)
CGroup: /system.slice/mongod.service
└─8987 /usr/bin/mongod -f /etc/mongod.conf
Nov 28 11:27:36 crinity-mongodb-01 systemd[1]: Starting MongoDB Database Server...
Nov 28 11:27:36 crinity-mongodb-01 mongod[8984]: about to fork child process, waiting until server is ready for connections.
Nov 28 11:27:36 crinity-mongodb-01 mongod[8984]: forked process: 8987
Nov 28 11:27:37 crinity-mongodb-01 mongod[8984]: child process started successfully, parent exiting
Nov 28 11:27:37 crinity-mongodb-01 systemd[1]: Started MongoDB Database Server.
5. 트러블 슈팅
5-1. mongodb-{port}.sock 파일 소유자 문제
저의 경우, 서비스를 구동하는데까지는 성공했으나, stop 후 start를 다시 하니 아래와 같이 서비스 Active 상태가 failed로 변경되었습니다. 확인해보니, /tmp/mongodb-{port}.sock 파일의 소유자가 mongod:mongod 사용자/그룹이 아니라 root로 변환되어 문제가 되었습니다.
[root@mongodb-01 tmp]# systemctl start mongod
Job for mongod.service failed because the control process exited with error code. See "systemctl status mongod.service" and "journalctl -xe" for details.
[root@mongodb-01 tmp]# systemctl status mongod
● mongod.service - MongoDB Database Server
Loaded: loaded (/usr/lib/systemd/system/mongod.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Mon 2022-11-28 13:45:01 KST; 7s ago
Docs: https://docs.mongodb.org/manual
Process: 18972 ExecStart=/usr/bin/mongod $OPTIONS (code=exited, status=14)
Process: 18969 ExecStartPre=/usr/bin/chmod 0755 /var/run/mongodb (code=exited, status=0/SUCCESS)
Process: 18965 ExecStartPre=/usr/bin/chown mongod:mongod /var/run/mongodb (code=exited, status=0/SUCCESS)
Process: 18963 ExecStartPre=/usr/bin/mkdir -p /var/run/mongodb (code=exited, status=0/SUCCESS)
Main PID: 18719 (code=exited, status=0/SUCCESS)
Nov 28 13:45:01 crinity-mongodb-01 systemd[1]: Starting MongoDB Database Server...
Nov 28 13:45:01 crinity-mongodb-01 mongod[18972]: about to fork child process, waiting until server is ready for connections.
Nov 28 13:45:01 crinity-mongodb-01 mongod[18972]: forked process: 18975
Nov 28 13:45:01 crinity-mongodb-01 mongod[18972]: ERROR: child process failed, exited with 14
Nov 28 13:45:01 crinity-mongodb-01 mongod[18972]: To see additional information in this output, start without the "--fork" option.
Nov 28 13:45:01 crinity-mongodb-01 systemd[1]: mongod.service: control process exited, code=exited status=14
Nov 28 13:45:01 crinity-mongodb-01 systemd[1]: Failed to start MongoDB Database Server.
Nov 28 13:45:01 crinity-mongodb-01 systemd[1]: Unit mongod.service entered failed state.
Nov 28 13:45:01 crinity-mongodb-01 systemd[1]: mongod.service failed.
따라서 아래와 같이 수정 후 start 하면 정상 구동이 됩니다.
[root@mongodb-01 tmp]# chown mongod:mongod mongodb-{port}.sock
[root@mongodb-01 tmp]# systemctl start mongod
[root@mongodb-01 tmp]# systemctl status mongod
● mongod.service - MongoDB Database Server
Loaded: loaded (/usr/lib/systemd/system/mongod.service; enabled; vendor preset: disabled)
Active: active (running) since Mon 2022-11-28 13:49:06 KST; 57s ago
Docs: https://docs.mongodb.org/manual
Process: 19290 ExecStart=/usr/bin/mongod $OPTIONS (code=exited, status=0/SUCCESS)
Process: 19287 ExecStartPre=/usr/bin/chmod 0755 /var/run/mongodb (code=exited, status=0/SUCCESS)
Process: 19284 ExecStartPre=/usr/bin/chown mongod:mongod /var/run/mongodb (code=exited, status=0/SUCCESS)
Process: 19283 ExecStartPre=/usr/bin/mkdir -p /var/run/mongodb (code=exited, status=0/SUCCESS)
Main PID: 19293 (mongod)
CGroup: /system.slice/mongod.service
└─19293 /usr/bin/mongod -f /etc/mongod.conf
Nov 28 13:49:05 crinity-mongodb-01 systemd[1]: Starting MongoDB Database Server...
Nov 28 13:49:05 crinity-mongodb-01 mongod[19290]: about to fork child process, waiting until server is ready for connections.
Nov 28 13:49:05 crinity-mongodb-01 mongod[19290]: forked process: 19293
Nov 28 13:49:06 crinity-mongodb-01 mongod[19290]: child process started successfully, parent exiting
Nov 28 13:49:06 crinity-mongodb-01 systemd[1]: Started MongoDB Database Server.
6. MongoDB 사용하기
[root@mongodb-01 ~]# mongosh
Current Mongosh Log ID: 6384471091e843a53b2e73bd
Connecting to: mongodb://127.0.0.1:{port}/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+1.6.0
Using MongoDB: 6.0.3
Using Mongosh: 1.6.0
For mongosh info see: https://docs.mongodb.com/mongodb-shell/
------
The server generated these startup warnings when booting
2022-11-28T14:24:52.606+09:00: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine. See http://dochub.mongodb.org/core/prodnotes-filesystem
2022-11-28T14:24:53.749+09:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted
2022-11-28T14:24:53.749+09:00: /sys/kernel/mm/transparent_hugepage/enabled is 'always'. We suggest setting it to 'never'
2022-11-28T14:24:53.749+09:00: /sys/kernel/mm/transparent_hugepage/defrag is 'always'. We suggest setting it to 'never'
2022-11-28T14:24:53.749+09:00: vm.max_map_count is too low
------
------
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()
------
test>
7. 마치며...
이렇게 MongoDB v6.0 버전대를 설치해보았습니다.
NoSQL은 처음이라 익숙하지 않아 더욱 노력해봐야할 것 같습니다.
'데이터베이스 > MongoDB' 카테고리의 다른 글
MongoDB에 Replication을 설정해보자. (0) | 2022.11.28 |
---|
댓글