IT 프로그래밍

[Bigdata 저장] Sharding : config 서버접속(영상) , 포트설정 해결하기

잉휴 2021. 3. 9. 15:56
mongod --shardsvr --replSet shareRepl1 --dbpath C:\mongodb\shard\shard1\shardRep1\data -port 30011
mongod --shardsvr --replSet shareRepl1 --dbpath C:\mongodb\shard\shard1\shardRep2\data -port 30012
mongod --shardsvr --replSet shareRepl1 --dbpath C:\mongodb\shard\shard1\shardRep3\data -port 30013

mongod --shardsvr --replSet shareRepl2 --dbpath C:\mongodb\shard\shard2\shardRep1\data -port 30021
mongod --shardsvr --replSet shareRepl2 --dbpath C:\mongodb\shard\shard2\shardRep2\data -port 30022
mongod --shardsvr --replSet shareRepl2 --dbpath C:\mongodb\shard\shard2\shardRep3\data -port 30023

mongod --shardsvr --replSet shareRepl3 --dbpath C:\mongodb\shard\shard3\shardRep1\data -port 30031
mongod --shardsvr --replSet shareRepl3 --dbpath C:\mongodb\shard\shard3\shardRep2\data -port 30032
mongod --shardsvr --replSet shareRepl3 --dbpath C:\mongodb\shard\shard3\shardRep3\data -port 30033

먼저 이전시간에 만든 파일안으로 포트를 9개 생성하겠습니다.

9개 항목을 모두 실행해주고 서버를 끄지 말고 그대로 둬야 합니다!!!!!!!

 

 

 

원래 shardRepl인데 share로 오타를 냈는데 이미 생성된 포트이기 때문에

그대로 shareRepl이라고 맞춰주었습니다

mongo localhost:30011

var config = {
_id : "shareRepl1", members : [
{_id : 0, host : 'localhost:30011'},
{_id : 1, host : 'localhost:30012'},
{_id : 2, host : 'localhost:30013'}
]
}

rs.initiate(config)

이렇게 세 번을 실행하면 영상처럼 Primary(가장 상태가 좋은 포트)인지 Secondary인지 뜹니다

 

30021번과 30031번도 동일하게 실행해줍니다

 

※같은 컴퓨터라서 localhost라고 쓰지만 실제로는 여러대의 컴퓨터를 사용하기 때문에 그 자리에 port번호가 들어갑니다

 

admin-shutdownServer으로 종료하면 정상적으로 종료되지만 그냥 X(닫기)버튼으로 지웠을 경우 

우리가 프로그램을 닫았는데도 작업관리자에서 봤을때 응용프로그램이 돌아가는 것처럼

포트가 지워지지 않고 그대로 돌아간다고 보면된다

따라서 이 경우에는 포트번호를 바꿔야한다

 

만약 너무 복잡해졌다면 재부팅을 하자