Version
Ubuntu : 22.0.4 SERVER LTS
MongoDB 리포지토리의 GPG 키를 시스템으로 가져옵니다.
wget -qO- \
https://pgp.mongodb.com/server-7.0.asc | \
gpg --dearmor | \
sudo tee /usr/share/keyrings/mongodb-server-7.0.gpg >/dev/null
Shell
복사
파일을 생성하여 MongoDB 리포지토리를 추가합니다.
echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-7.0.gpg ] \
https://repo.mongodb.org/apt/ubuntu $(lsb_release -cs)/mongodb-org/7.0 multiverse" | \
sudo tee -a /etc/apt/sources.list.d/mongodb-org-7.0.list
Shell
복사
APT 업데이트
sudo apt update
Shell
복사
몽고 디비 설치
sudo apt install -y mongodb-org
Shell
복사
서비스를 시작하고 부팅 시 활성화하려면 다음을 실행합니다.
sudo systemctl enable --now mongod
Shell
복사
몽고 디비 외부 접근 설정
vi /etc/mongod.conf
Shell
복사
net:
port: 27017
bindIp: 0.0.0.0 # 모든 IP에서 접속 가능하게 설정
Shell
복사
몽고 디비 재시작
sudo service mongod restart
Shell
복사
유저 & 데이터베이스 추가 방법
# 몽고 접근
mongosh
# use 데이터베이스이름
use beomjunpark
# 유저 추가
db.createUser({
user: "beomjunpark",
pwd: "yourpassword",
roles: [{ role: "readWrite", db: "beomjunpark" }]
})
# 생성된 유저 확인
db.getUsers()
Shell
복사