간단한 mongodb 2.0.1 replSet 설정 방법(localhost 일때)

start.sh 보통 3대의 구성으로 많이 이용하는 듯 합니다.

#!/bin/sh

/home/charsyam/mongo/mongod –dbpath /home/charsyam/data/mongodb/db1 –port 10001 –replSet charsyammongo/localhost:10002 &
/home/charsyam/mongo/mongod –dbpath /home/charsyam/data/mongodb/db2 –port 10002 –replSet charsyammongo/localhost:10001 &
/home/charsyam/mongo/mongod –dbpath /home/charsyam/data/mongodb/db3 –port 10003 –replSet charsyammongo/localhost:10001,localhost:
10002 &

 

이렇게 실행만 시키면 다음과 같은 오류가 나기 시작합니다.

Sat Nov 19 00:41:48 [rsStart] trying to contact localhost:10002
Sat Nov 19 00:41:48 [rsStart] replSet can’t get local.system.replset config from self or any seed (EMPTYCONFIG)
Sat Nov 19 00:41:49 [rsStart] trying to contact localhost:10001
Sat Nov 19 00:41:49 [rsStart] replSet can’t get local.system.replset config from self or any seed (EMPTYCONFIG)
Sat Nov 19 00:41:49 [rsStart] trying to contact localhost:10001

 

이제 mongo localhost:10001 로 접속을 하고 다음과 같이 입력합니다.

config = {_id: ‘charsyammongo’, members: [
{_id: 0, host: ‘localhost:10001’},
{_id: 1, host: ‘localhost:10002’},
{_id: 2, host: ‘localhost:10003’}]}

rs.initiate(config)

 

그러면 자기들 끼리 마스터를 선출하기 시작합니다.

이제 에러로그가 다음과 같이 바뀝니다.

 

Sat Nov 19 00:42:27 [rsHealthPoll] replSet member localhost:10001 is now in state PRIMARY
Sat Nov 19 00:42:27 [rsHealthPoll] replSet member localhost:10003 is now in state RECOVERING
Sat Nov 19 00:42:27 [rsHealthPoll] replSet member localhost:10001 is now in state PRIMARY

 

설정 끝!!!