본문 바로가기
Skills/Database

Install MongoDB 5.0 on CentOS 7

by 부르르 2021. 7. 30.

1. MongoDB 레포지토리 추가

# vim /etc/yum.repos.d/mongodb-org-5.0.repo

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

 

2. MongoDB 패키지 설치

# yum install -y mongodb-org ... Installed: ​​mongodb-org.x86_64 0:5.0.1-1.el7 Dependency Installed: ​​cyrus-sasl.x86_64 0:2.1.26-23.el7 ​​cyrus-sasl-gssapi.x86_64 0:2.1.26-23.el7 ​​mongodb-database-tools.x86_64 0:100.4.1-1 ​​mongodb-mongosh.x86_64 0:1.0.3-1.el7 ​​mongodb-org-database.x86_64 0:5.0.1-1.el7 ​​mongodb-org-database-tools-extra.x86_64 0:5.0.1-1.el7 ​​mongodb-org-mongos.x86_64 0:5.0.1-1.el7 ​​mongodb-org-server.x86_64 0:5.0.1-1.el7 ​​mongodb-org-shell.x86_64 0:5.0.1-1.el7 ​​mongodb-org-tools.x86_64 0:5.0.1-1.el7 Complete!

 

3. Mongod 설정

# vim /etc/mongod.conf

mongod.conf 내 bindIp local(127.0.0.1) 에서 any(0.0.0.0) 으로 설정

net: ​​port: 27017 ​​bindIp: 0.0.0.0

 

4. 서비스 시작 및 등록

# systemctl start mongod # systemctl enable mongo

 

5. mongosh 로 MongoDB 접속

# mongosh Current Mongosh Log ID: 61039227a2f573060cd9d3ea Connecting to: mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000 Using MongoDB: 5.0.1 Using Mongosh: 1.0.3 For mongosh info see: https://docs.mongodb.com/mongodb-shell/ ------ ​​​The server generated these startup warnings when booting: ​​​2021-07-30T14:44:33.836+09:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted ​​​2021-07-30T14:44:33.836+09:00: /sys/kernel/mm/transparent_hugepage/enabled is 'always'. We suggest setting it to 'never' ​​​2021-07-30T14:44:33.836+09:00: /sys/kernel/mm/transparent_hugepage/defrag is 'always'. We suggest setting it to 'never' ------ Warning: Found ~/.mongorc.js, but not ~/.mongoshrc.js. ~/.mongorc.js will not be loaded. ​​You may want to copy or rename ~/.mongorc.js to ~/.mongoshrc.js. test>

유저생성

test> use admin switched to db admin admin> db.createUser( { user: "USERNAME", pwd: "USERPASS", roles: [{ role: "userAdminAnyDatabase", db: "admin" }, "readWriteAnyDatabase"] }) { ok: 1 }

MongoDB 종료

admin> db.adminCommand( { shutdown: 1 } ) MongoNetworkError: connection 1 to 127.0.0.1:27017 closed admin> exit

서비스 정지 확인

# systemctl status mongod ● mongod.service - MongoDB Database Server ​​​Loaded: loaded (/usr/lib/systemd/system/mongod.service; enabled; vendor preset: disabled) ​​​Active: inactive (dead) since Fri 2021-07-30 15:02:15 KST; 11s ago ​​​​​Docs: https://docs.mongodb.org/manual ​​Process: 2765 ExecStart=/usr/bin/mongod $OPTIONS (code=exited, status=0/SUCCESS) ​​Process: 2763 ExecStartPre=/usr/bin/chmod 0755 /var/run/mongodb (code=exited, status=0/SUCCESS) ​​Process: 2760 ExecStartPre=/usr/bin/chown mongod:mongod /var/run/mongodb (code=exited, status=0/SUCCESS) ​​Process: 2758 ExecStartPre=/usr/bin/mkdir -p /var/run/mongodb (code=exited, status=0/SUCCESS) ​Main PID: 2769 (code=exited, status=0/SUCCESS) Jul 30 15:02:06 kgh-mongodb systemd[1]: Starting MongoDB Database Server... Jul 30 15:02:06 kgh-mongodb mongod[2765]: about to fork child process, waiting u...s. Jul 30 15:02:06 kgh-mongodb mongod[2765]: forked process: 2769 Jul 30 15:02:07 kgh-mongodb systemd[1]: Started MongoDB Database Server. Hint: Some lines were ellipsized, use -l to show in full.

 

6. Mongod 설정 추가

# vim /etc/mongod.conf

mongod.conf 내 security 항목 추가 및 authorization 활성화

security: ​​authorization: enabled

 

7. Mongod 재기동

# systemctl restart mongod

 

8. 접속테스트

# mongosh -u "USERNAME" --authenticationDatabase "admin" -p Enter password: ******* Current Mongosh Log ID: 610396aeb15bbf4e5ed3145a Connecting to: mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000 Using MongoDB: 5.0.1 Using Mongosh: 1.0.3 For mongosh info see: https://docs.mongodb.com/mongodb-shell/ Warning: Found ~/.mongorc.js, but not ~/.mongoshrc.js. ~/.mongorc.js will not be loaded. ​​You may want to copy or rename ~/.mongorc.js to ~/.mongoshrc.js. test> use admin switched to db admin admin> db.getUsers() { ​​users: [ ​​​​{ ​​​​​​_id: 'admin.dev', ​​​​​​userId: UUID("6aa32838-787e-4f8d-8bcc-adab270603d2"), ​​​​​​user: 'dev', ​​​​​​db: 'admin', ​​​​​​roles: [ ​​​​​​​​{ role: 'readWriteAnyDatabase', db: 'admin' }, ​​​​​​​​{ role: 'userAdminAnyDatabase', db: 'admin' } ​​​​​​], ​​​​​​mechanisms: [ 'SCRAM-SHA-1', 'SCRAM-SHA-256' ] ​​​​} ​​], ​​ok: 1 }

 

참고문헌

728x90
반응형

'Skills > Database' 카테고리의 다른 글

MariaDB 버전 업그레이드 (10.1 -> 10.4)  (0) 2021.09.15

댓글