반응형
몽고DB 포트번호 변경
sudo vi /etc/mongod.conf
# network interface
net:
port: 27027 -> 임의의 포트번호로 변경
bindIp: 127.0.0.1 -> 0.0.0.0
----------------------------
sudo service mongod restart
몽고DB 접속 계정만들기
mongo --port portNumber
계정 추가
> use admin
switched to db admin
> db.createUser(
... {
... user: "admin",
... pwd: "adminPW", // or cleartext password
... roles: [ { role: "root", db: "admin" } ] (슈퍼바이저)
## roles: [ { role: "userAdminAnyDatabase", db: "admin" }] (일반 어드민)
... }
... )
로그인
use admin
db.auth("userID","userPW")
-------------------
/etc/mongod.conf
security:
authorization: enabled
How to Authenticate Users in MongoDB
mongo "mongodb://Admin:${DBPASSWORD}@<host>:<port>/admin?authSource=admin"
어드민 계정
MONGO_URL=mongodb://example:example!@localhost:47172/exampleDB?authSource=admin
DB admin - ID : example PW : example!
일반 DB 계정
MONGO_URL=mongodb://example:example!@localhost:47172/exampleDB
DB exampleDB - ID : example PW : example!
반응형