CentOS에 MongoDB 64bit 설치하기

샤딩과 복제셋을 함께 사용하기 이전에 몽고디비의 기본적인 설치와 실행하는 방법을 익혀보자.

설치방법 참고

yum 저장소 추가

1
2
3
4
5
6
$ vi /etc/yum.repos.d/mongodb.repo
[mongodb]
name=MongoDB Repository
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/
gpgcheck=0
enabled=1

yum으로 설치

1
$ yum -y install mongodb-org

yum -update로 몽고디비가 업데이트되는 것을 방지

1
2
$ vi /etc/yum.conf
exclude=mongodb-org,mongodb-org-server,mongodb-org-shell,mongodb-org-mongos,mongodb-org-tools

실행시키기

1
2
3
4
5
6
$ service mongod start
$ service mongod restart
$ service mongod stop
 
# 부팅시 자동으로 실행하려면
$ chkconfig mongod on

방화벽 오픈

1
2
3
$ iptables -I INPUT 1 -p tcp --dport 27017 -j ACCEPT
$ service iptables save
$ service iptables restart

테스트 해보기

1
2
3
4
5
6
7
$ mongo
MongoDB shell version: 2.6.2
connecting to: test
> db.users.insert({name:'yakolla'})
WriteResult({ "nInserted" : 1 })
> db.users.find({})
{ "_id" : ObjectId("53a3fa85a3484631e5c4cfdd"), "name" : "yakolla" }

mongodb의 설정파일(/etc/mongod.conf) 디폴트 내용

# mongod.conf
#where to log
logpath=/var/log/mongodb/mongod.log
logappend=true
# fork and run in background
fork=true
#port=27017
dbpath=/var/lib/mongo
# location of pidfile
pidfilepath=/var/run/mongodb/mongod.pid
# Listen to local interface only. Comment out to listen on all interfaces.
bind_ip=127.0.0.1
# Disables write-ahead journaling
# nojournal=true
# Enables periodic logging of CPU utilization and I/O wait
#cpu=true
# Turn on/off security. Off is currently the default
#noauth=true
#auth=true
# Verbose logging output.
#verbose=true
# Inspect all client data for validity on receipt (useful for
# developing drivers)
#objcheck=true
# Enable db quota management
#quota=true
# Set oplogging level where n is
# 0=off (default)
# 1=W
# 2=R
# 3=both
# 7=W+some reads
#diaglog=0
# Ignore query hints
#nohints=true
# Disable the HTTP interface (Defaults to localhost:27018).
#nohttpinterface=true
# Turns off server-side scripting. This will result in greatly limited
# functionality
#noscripting=true
# Turns off table scans. Any query that would do a table scan fails.
#notablescan=true
# Disable data file preallocation.
#noprealloc=true
# Specify .ns file size for new databases.
# nssize=<size>
# Replication Options
# in replicated mongo databases, specify the replica set name here
#replSet=setname
# maximum size in megabytes for replication operation log
#oplogSize=1024
# path to a key file storing authentication info for connections
# between replica set members
#keyFile=/path/to/keyfile
view raw gistfile1.sh hosted with ❤ by GitHub

ReplicaSet 설정하기

Sharded ReplicaSet 설정하기