상세 컨텐츠

본문 제목

MongoDB : Amazon Linux에 설치 및 설정하기

IT/프로그래밍

by James Lee. 2017. 8. 2. 09:38

본문

Edit

MongoDB : Amazon Linux에 설치 및 설정하기

  1. /etc/yum.repos.d 경로에 mongodb-org-3.4.repo 파일 생성 (관리자 권한 필요)
  2. mongodb-org-3.4.repo 파일에 아래의 내용 작성
[mongodb-org-3.4]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/amazon/2013.03/mongodb-org/3.4/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-3.4.asc
  1. yum을 이용하여 설치

    sudo yum install -y mongodb-org

  2. 몽고DB 환경설정 세팅

    • /etc/mongod.conf
    • 기본값은 아래와 같이 잡혀 있다.
# mongod.conf

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

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

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

# how the process runs
processManagement:
fork: true # fork and run in background
pidFilePath: /var/run/mongodb/mongod.pid # location of pidfile

# network interfaces
net:
port: 27017
bindIp: 127.0.0.1 # Listen to local interface only, comment to listen on all interfaces.

  1. MongoDB가 잘 시작되었는지 확인하기

  • /var/log/mongodb/mongod.log 을 확인하여 아래와 같은 메세지가 있는지 본다.
    [initandlisten] waiting for connections on port

원격 설정하기

기본적으로 MongoDB는 원격 연결을 허용하지 않기 때문에 원격 연결을 하는 설정을 별도로 해줘야 한다.

mongod.conf 파일의 bind_ip 프로퍼티를 보자. 기본적으로 로컬에만 바인딩되기 때문에 다른 곳에서 접속을 시도해도 연결되지 않는다.

방법 1

연결을 허용할 IP를 추가한다.
# Listen to local and LAN interfaces.
bind_ip = 127.0.0.1,192.168.161.100

방법 2

bind_ip 프로퍼티를 주석처리하면 모든 ip로부터 connect가 가능해진다. 하지만 __보안상 권장되지 않는다.__
# Listen to local and LAN interfaces.
# bind_ip = 127.0.0.1

참고로, AWS의 인스턴스에 MongoDB를 올렸으니 Inbound 설정도 당연히 해줘야 한다.
모든 포트에서 허용하든, 특정 IP에서만 허용하든 (권장) 본인의 편의대로..

참고

%23%20MongoDB%20%3A%20Amazon%20Linux%uC5D0%20%uC124%uCE58%20%uBC0F%20%uC124%uC815%uD558%uAE30%0A%0A@%28MongoDB%29%5B%uD2F0%uC2A4%uD1A0%uB9AC%5D%0A1.%20/etc/yum.repos.d%20%uACBD%uB85C%uC5D0%20mongodb-org-3.4.repo%20%uD30C%uC77C%20%uC0DD%uC131%20%28%uAD00%uB9AC%uC790%20%uAD8C%uD55C%20%uD544%uC694%29%0A2.%20mongodb-org-3.4.repo%20%uD30C%uC77C%uC5D0%20%uC544%uB798%uC758%20%uB0B4%uC6A9%20%uC791%uC131%0A%60%60%60%0A%5Bmongodb-org-3.4%5D%0Aname%3DMongoDB%20Repository%0Abaseurl%3Dhttps%3A//repo.mongodb.org/yum/amazon/2013.03/mongodb-org/3.4/x86_64/%0Agpgcheck%3D1%0Aenabled%3D1%0Agpgkey%3Dhttps%3A//www.mongodb.org/static/pgp/server-3.4.asc%0A%60%60%60%0A%0A3.%20yum%uC744%20%uC774%uC6A9%uD558%uC5EC%20%uC124%uCE58%0A%3E%20sudo%20yum%20install%20-y%20mongodb-org%0A%0A4.%20%uBABD%uACE0DB%20%uD658%uACBD%uC124%uC815%20%uC138%uD305%20%0A-%20/etc/mongod.conf%20%0A-%20%uAE30%uBCF8%uAC12%uC740%20%uC544%uB798%uC640%20%uAC19%uC774%20%uC7A1%uD600%20%uC788%uB2E4.%0A%60%60%60%0A%23%20mongod.conf%0A%0A%23%20for%20documentation%20of%20all%20options%2C%20see%3A%0A%23%20%20%20http%3A//docs.mongodb.org/manual/reference/configuration-options/%0A%0A%23%20where%20to%20write%20logging%20data.%0AsystemLog%3A%0A%20%20destination%3A%20file%0A%20%20logAppend%3A%20true%0A%20%20path%3A%20/var/log/mongodb/mongod.log%0A%0A%23%20Where%20and%20how%20to%20store%20data.%0Astorage%3A%0A%20%20dbPath%3A%20/var/lib/mongo%0A%20%20journal%3A%0A%20%20%20%20enabled%3A%20true%0A%23%20%20engine%3A%0A%23%20%20mmapv1%3A%0A%23%20%20wiredTiger%3A%0A%0A%23%20how%20the%20process%20runs%0AprocessManagement%3A%0A%20%20fork%3A%20true%20%20%23%20fork%20and%20run%20in%20background%0A%20%20pidFilePath%3A%20/var/run/mongodb/mongod.pid%20%20%23%20location%20of%20pidfile%0A%0A%23%20network%20interfaces%0Anet%3A%0A%20%20port%3A%2027017%0A%20%20bindIp%3A%20127.0.0.1%20%20%23%20Listen%20to%20local%20interface%20only%2C%20comment%20to%20listen%20on%20all%20interfaces.%0A%60%60%60%0A5.%20MongoDB%uAC00%20%uC798%20%uC2DC%uC791%uB418%uC5C8%uB294%uC9C0%20%uD655%uC778%uD558%uAE30%0A-%20/var/log/mongodb/mongod.log%20%uC744%20%uD655%uC778%uD558%uC5EC%20%uC544%uB798%uC640%20%uAC19%uC740%20%uBA54%uC138%uC9C0%uAC00%20%uC788%uB294%uC9C0%20%uBCF8%uB2E4.%0A%3E%20%5Binitandlisten%5D%20waiting%20for%20connections%20on%20port%20%3Cport%3E%0A%0A%23%23%23%20%uC6D0%uACA9%20%uC124%uC815%uD558%uAE30%0A%0A%uAE30%uBCF8%uC801%uC73C%uB85C%20MongoDB%uB294%20%5B%uC6D0%uACA9%20%uC5F0%uACB0%uC744%20%uD5C8%uC6A9%uD558%uC9C0%20%uC54A%uAE30%20%uB54C%uBB38%uC5D0%5D%28https%3A//www.mkyong.com/mongodb/mongodb-allow-remote-access/%29%20%uC6D0%uACA9%20%uC5F0%uACB0%uC744%20%uD558%uB294%20%uC124%uC815%uC744%20%uBCC4%uB3C4%uB85C%20%uD574%uC918%uC57C%20%uD55C%uB2E4.%20%0A%0Amongod.conf%20%uD30C%uC77C%uC758%20bind_ip%20%uD504%uB85C%uD37C%uD2F0%uB97C%20%uBCF4%uC790.%20%uAE30%uBCF8%uC801%uC73C%uB85C%20%uB85C%uCEEC%uC5D0%uB9CC%20%uBC14%uC778%uB529%uB418%uAE30%20%uB54C%uBB38%uC5D0%20%uB2E4%uB978%20%uACF3%uC5D0%uC11C%20%uC811%uC18D%uC744%20%uC2DC%uB3C4%uD574%uB3C4%20%uC5F0%uACB0%uB418%uC9C0%20%uC54A%uB294%uB2E4.%20%20%0A%0A%23%23%23%23%20%uBC29%uBC95%201%0A%uC5F0%uACB0%uC744%20%uD5C8%uC6A9%uD560%20IP%uB97C%20%uCD94%uAC00%uD55C%uB2E4.%0A%60%60%60%0A%23%20Listen%20to%20local%20and%20LAN%20interfaces.%0Abind_ip%20%3D%20127.0.0.1%2C192.168.161.100%0A%60%60%60%0A%0A%23%23%23%23%20%uBC29%uBC95%202%0Abind_ip%20%uD504%uB85C%uD37C%uD2F0%uB97C%20%uC8FC%uC11D%uCC98%uB9AC%uD558%uBA74%20%uBAA8%uB4E0%20ip%uB85C%uBD80%uD130%20connect%uAC00%20%uAC00%uB2A5%uD574%uC9C4%uB2E4.%20%uD558%uC9C0%uB9CC%20__%uBCF4%uC548%uC0C1%20%uAD8C%uC7A5%uB418%uC9C0%20%uC54A%uB294%uB2E4.__%0A%60%60%60%0A%23%20Listen%20to%20local%20and%20LAN%20interfaces.%0A%23%20bind_ip%20%3D%20127.0.0.1%0A%60%60%60%0A%0A%uCC38%uACE0%uB85C%2C%20AWS%uC758%20%uC778%uC2A4%uD134%uC2A4%uC5D0%20MongoDB%uB97C%20%uC62C%uB838%uC73C%uB2C8%20Inbound%20%uC124%uC815%uB3C4%20%uB2F9%uC5F0%uD788%20%uD574%uC918%uC57C%20%uD55C%uB2E4.%0A%uBAA8%uB4E0%20%uD3EC%uD2B8%uC5D0%uC11C%20%uD5C8%uC6A9%uD558%uB4E0%2C%20%uD2B9%uC815%20IP%uC5D0%uC11C%uB9CC%20%uD5C8%uC6A9%uD558%uB4E0%20%28%uAD8C%uC7A5%29%20%uBCF8%uC778%uC758%20%uD3B8%uC758%uB300%uB85C..%0A%0A%21%5BAlt%20text%5D%28./1501642788899.png%29%0A%0A%0A%23%23%23%20%uCC38%uACE0%0A-%20%5BAmazon%20%uC5D0%20MongoDB%20%uC124%uCE58%uD558%uAE30%20by%20MongoDB%20%uACF5%uC2DD%20%uC0AC%uC774%uD2B8%5D%28https%3A//docs.mongodb.com/manual/tutorial/install-mongodb-on-amazon/%29


관련글 더보기

댓글 영역