몽고DB CentOS7 설치. MongoDB Installation guide for CentOS 7

yum으로 mongodb 설치chsh -s which zsh

yum repository 설정

vi /etc/yum.repos.d/mongodb-org-3.2.repo 명령 실행 후 아래내용 붙여넣기

1
2
3
4
5
6
[mongodb-org-3.2]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.2/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-3.2.asc

몽고DB 설치

1
2
3
4

yum -y install mongodb-org mongodb-org-server

yum install -y mongodb-org-3.2.7 mongodb-org-server-3.2.7 mongodb-org-shell-3.2.7 mongodb-org-mongos-3.2.7 mongodb-org-tools-3.2.7

몽고 DB 접속 가능한 IP 추가

vi /etc/mongod.conf

아래 내용 입력

1
2
3
4
# network interfaces
net:
port: 27017
bindIp: [127.0.0.1, xxx.xxx.xxx.xxx] # Listen to local interface only, comment to listen on all interfaces.

몽고 DB Start-Up

1
2

systemctl start mongod

몽고 DB 상태체크

1
systemctl status mongod

몽고 DB 포트 변경

기본포트: 27017

1
mongo --port 22222

방화벽 오픈

1
2
3

firewall-cmd --permanent --zone=public --add-port=27017/tcp
firewall-cmd --reload

삭제

1
2
3
4
5
6

service mongod stop
yum -y erase $(rpm -qa | grep mongodb-org)
rm -rf /var/log/mongodb
rm -rf /var/lib/mongo
rm -rf /var/run/mongodb/

brew로 mongodb 설치

1
2
3
brew update

brew install mongodb

mongod.conf dbPath 수정 (옵션)

1
2
3
4
5
6
7
8
9
10
cat /usr/local/etc/mongod.conf 

systemLog:
destination: file
path: /usr/local/var/log/mongodb/mongo.log
logAppend: true
storage:
dbPath: /usr/local/var/mongodb
net:
bindIp: 127.0.0.1

brew services로 mongodb 실행

1
2
brew services start mongodb
brew services stop mongodb

mongod 실행방법

1
mongod --dbpath <path to data directory>

reference