Linux

리눅스에 설치된 mongodb 외부접속 허용하기

bitcoder 2022. 3. 7. 11:55
728x90

리눅스에 mongodb를 설치하면 기본적으로 외부접속이 허용되지 않습니다.

 

이를 허용하기 위한 방법을 공유합니다.

 

mongodb의 설정파일은 /etc/mongod.conf입니다.

 

이 파일의 내용을 수정하시면 됩니다.

 

설정파일의 소유자가 root이므로 root권한으로 편집기를 열어야합니다.

$ sudo nano /etc/mongod.conf

"bindIP: 127.0.0.1"을 "bindIP: 0.0.0.0"으로 수정합니다.

# mongod.conf

# for documentation of all options, see:
#   http://docs.mongodb.org/manual/reference/configuration-options/

# Where and how to store data.
storage:
  dbPath: /var/lib/mongodb
  journal:
    enabled: true
#  engine:
#  wiredTiger:

# where to write logging data.
systemLog:
  destination: file
  logAppend: true
  path: /var/log/mongodb/mongod.log

# network interfaces
net:
  port: 27017
  bindIp: 0.0.0.0
-  bindIp: 127.0.0.1
+  bindIp: 0.0.0.0

 

그리고 다음 명령으로 mongod를 재시작합니다.

$ sudo systemctl restart mongod

 

이제 다음과 같이 외부에서 접속할 수 있습니다.

 

위의 그림과 같이 외부의 윈도우 호스트에서 Robo 3T와 같은 GUI도구를 이용하여 DB를 다룰 때 편리합니다.

728x90