- Clustering : 어떤 목적을 위한 집합 LIKE 조편성
장애가 날 것을 대비해서 클러스터링 하는 것을 의미- System / Application Clustering:
장애 조치 -> HA(고가용성)
1. 여러대(3대 이상 권장)
2. Data 전체 복제
3. 1대가 Primary(Active Server), 나머지 Seconda(Passive)
4. 설정 서버 구성 필요 (config)
5. 요청 전송 서버 필요 (Routing 개념)
- 시스템 클러스터링
클러스터 : 목적을 위한 집합
장애가 날 것을 대비해서 클러스터링 하는 것을 의미
두 사람 이상이 공동으로 데이터가 똑같이 구성되어 있어야 함. ==> 복제 전략
참고 사이트 : https://riptutorial.com/mongodb/example/22539/mongodb-as-a-replica-set
1) 하나의 시스템이 아니라, 다수의 시스템으로 유지해야 한다.
2) 하나가 사라질 때를 대비해서 똑같은 데이터를 보유하고 있어야 한다.
3) 서비스를 운영중인 애를 선택해두자
4) if primary에 장애가 생겼으면,
그대로 복제되는지 알려면 접속을 해서 collection과 document를 구성해둬야 함 -> 구성한 상태에서 복제가 되는지 확인
장애를 일으켜봄(시스템 다운시킴) -> 전이가 되는지 확인
db 1, 2, 3 생성
db로 쓸 창 3개 띄우기
rs.initiate(config)
mongo --port 40001
mongo --port 40002
primary test
secondary test
db조회가 안됨
db.test.find() 불가
primary 종료
- secondary가 primary 되는지 확인
- test db collection에 alice가 있는지 확인
secondary -> primary로 변경됨
Primary port 다시 살렸을 때, Primary로 바뀌는지 확인하기 => 안바뀜, 시스템은 다시 권한 돌려주지 않음
Shading
[Business Data -> OLTP -> 수정] 원활한 비즈니스 목적
Data 저장, 처리, 관리에는 기준이 있음 -> ACID -> RDB (index, transaction, commit, log ,trigger, lock ...)
- 원자성(Atomicity) : 예약
- 일관성(Consistency) : 규칙 유지 -> Data Type, Constraints
- 고립성(Isolation) : 작업 방어 -> Transaction
- 지속성(Durability) : (Redo) Log (기록을 남겨 데이터가 들어가지 않은 상태에서 재부팅 가능)
[Analysys Data -> OLAP -> 읽기]
- BigData -> NoSQL Data -> ACID [X] <= 대량, 구조?
Volume, Variety, Velocity => BigData 3V
--> BASE
- Basically Available : *Replica Set
- Soft state : 상태 유지
- Eventually Consistent : 이벤트성 일관성(장애 정도만 잡아주는 조건) -->[O] 구조 [X] --> DataType, 범위
이미지 출처 : https://www.cloudduggu.com/mongodb/sharding/
[ directory 5개 ]
mkdir shadb
/config1
/config2
/config3
/shard1
/db1
/db2
/db3
/shard2
/db1
/db2
/db3
/shard3
/db1
/db2
/db3
mongod --configsvr --replSet configRepl --dbpath "C:\data\shadb\config1" -port 31001
mongod --configsvr --replSet configRepl --dbpath "C:\data\shadb\config2" -port 31002
mongod --configsvr --replSet configRepl --dbpath "C:\data\shadb\config3" -port 31003
mongo localhost:31001 (config01 server 접속)
var config = {
_id : "configRepl", members : [
{_id : 0, host : 'localhost:31001'},
{_id : 1, host : 'localhost:31002'},
{_id : 2, host : 'localhost:31003'}
]
}
var config = {_id : "configRepl", members : [ {_id : 0, host : 'localhost:31001'},{_id : 1, host : 'localhost:31002'},{_id : 2, host : 'localhost:31003'} ]}
rs.initiate(config)
rs.status()
1) shard1 --port 41001 / 41002 / 41003
2) shard2 --port 42001 / 42002 / 42003
3) shard3 --port 43001 / 43002 / 43003
mongod --shardsvr --replSet shardRep1 --dbpath "C:\data\shadb\shard1\db1" -port 41001
mongod --shardsvr --replSet shardRep1 --dbpath "C:\data\shadb\shard1\db2" -port 41002
mongod --shardsvr --replSet shardRep1 --dbpath "C:\data\shadb\shard1\db3" -port 41003
mongo localhost:41001 (shardRep1 접속)
var config = {
_id : "shardRep1", members : [
{_id : 0, host : 'localhost:41001'},
{_id : 1, host : 'localhost:41002'},
{_id : 2, host : 'localhost:41003'}
]
}
var config = { _id : "shardRep1", members : [ {_id : 0, host : 'localhost:41001'},{_id : 1, host : 'localhost:41002'}, {_id : 2, host : 'localhost:41003'} ]}
rs.initiate(config)
mongod --shardsvr --replSet shardRep2 --dbpath "C:\data\shadb\shard2\db1" -port 42001
mongod --shardsvr --replSet shardRep2 --dbpath "C:\data\shadb\shard2\db2" -port 42002
mongod --shardsvr --replSet shardRep2 --dbpath "C:\data\shadb\shard2\db3" -port 42003
mongo localhost:42001 (shardRep2 접속)
var config = {
_id : "shardRep2", members : [
{_id : 0, host : 'localhost:42001'},
{_id : 1, host : 'localhost:42002'},
{_id : 2, host : 'localhost:42003'}
]
}
var config = { _id : "shardRep2", members : [ {_id : 0, host : 'localhost:42001'},{_id : 1, host : 'localhost:42002'}, {_id : 2, host : 'localhost:42003'} ]}
rs.initiate(config)
mongod --shardsvr --replSet shardRep3 --dbpath "C:\data\shadb\shard3\db1" -port 43001
mongod --shardsvr --replSet shardRep3 --dbpath "C:\data\shadb\shard3\db2" -port 43002
mongod --shardsvr --replSet shardRep3 --dbpath "C:\data\shadb\shard3\db3" -port 43003
mongo localhost:43001 (shardRep3 접속)
var config = {
_id : "shardRep3", members : [
{_id : 0, host : 'localhost:43001'},
{_id : 1, host : 'localhost:43002'},
{_id : 2, host : 'localhost:43003'}
]
}
var config = { _id : "shardRep3", members : [ {_id : 0, host : 'localhost:43001'},{_id : 1, host : 'localhost:43002'}, {_id : 2, host : 'localhost:43003'} ]}
rs.initiate(config)
mongos --configdb configRepl/localhost:31001,localhost:31002,localhost:31003
** 만약 오류 발생할 경우
서비스 -> mongo 켜져있을 경우 -> 죽이고 다시 실행
<cmd 별도>
mongo --> mongos 확인
sh.addShard("shardRep1/localhost:41001")
sh.addShard("shardRep2/localhost:42001")
sh.addShard("shardRep3/localhost:43001")
sh.shardCollection("msTest.person",{_id:"hashed"});
> use msTest
> show collections
> for(var i=0; i < 100000 ; i++) { db.person.insert({ number: i, name: "kor"+i }); };
> db.person.find().count();
```
#. mongodb shard 구성 실습
[ directory 5개 구성 ]
mkdir shadb
/config1
/config2
/config3
/shard1
/db1
/db2
/db3
/shard2
/db1
/db2
/db3
/shard3
/db1
/db2
/db3
[cmd 창] 5개 띄움
#. Config 3대 환경 구성
<cmd:빨간색>
mongod --configsvr --replSet configRepl --dbpath "C:\data\shadb\config1" -port 31001
mongod --configsvr --replSet configRepl --dbpath "C:\data\shadb\config2" -port 31002
mongod --configsvr --replSet configRepl --dbpath "C:\data\shadb\config3" -port 31003
mongo localhost:31001 (config01 server 접속)
var config = {
_id : "configRepl", members : [
{_id : 0, host : 'localhost:31001'},
{_id : 1, host : 'localhost:31002'},
{_id : 2, host : 'localhost:31003'}
]
}
var config = { _id : "configRepl", members : [ {_id : 0, host : 'localhost:31001'},{_id : 1, host : 'localhost:31002'}, {_id : 2, host : 'localhost:31003'} ]}
rs.initiate(config)
rs.status()
#. Shard 3대 구성 :
[ Port ]
1) shard1 --port 41001 / 41002 / 41003
2) shard2 --port 42001 / 42002 / 42003
3) shard3 --port 43001 / 43002 / 43003
<cmd [shard1] : 파란색 >
mongod --shardsvr --replSet shardRep1 --dbpath "C:\data\shadb\shard1\db1" -port 41001
mongod --shardsvr --replSet shardRep1 --dbpath "C:\data\shadb\shard1\db2" -port 41002
mongod --shardsvr --replSet shardRep1 --dbpath "C:\data\shadb\shard1\db3" -port 41003
mongo localhost:41001
var config = {
_id : "shardRep1", members : [
{_id : 0, host : 'localhost:41001'},
{_id : 1, host : 'localhost:41002'},
{_id : 2, host : 'localhost:41003'}
]
}
var config = { _id : "shardRep1", members : [ {_id : 0, host : 'localhost:41001'},{_id : 1, host : 'localhost:41002'}, {_id : 2, host : 'localhost:41003'} ]}
rs.initiate(config)
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
<cmd [shard2] : 초록색>
mongod --shardsvr --replSet shardRep2 --dbpath "C:\data\shadb\shard2\db1" -port 42001
mongod --shardsvr --replSet shardRep2 --dbpath "C:\data\shadb\shard2\db2" -port 42002
mongod --shardsvr --replSet shardRep2 --dbpath "C:\data\shadb\shard2\db3" -port 42003
mongo localhost:42001
var config = {
_id : "shardRep1", members : [
{_id : 0, host : 'localhost:42001'},
{_id : 1, host : 'localhost:42002'},
{_id : 2, host : 'localhost:42003'}
]
}
var config = { _id : "shardRep2", members : [ {_id : 0, host : 'localhost:42001'},{_id : 1, host : 'localhost:42002'}, {_id : 2, host : 'localhost:42003'} ]}
rs.initiate(config)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
<cmd [shard3] : 보라색>
mongod --shardsvr --replSet shardRep3 --dbpath "C:\data\shadb\shard3\db1" -port 43001
mongod --shardsvr --replSet shardRep3 --dbpath "C:\data\shadb\shard3\db2" -port 43002
mongod --shardsvr --replSet shardRep3 --dbpath "C:\data\shadb\shard3\db3" -port 43003
mongo localhost:43001
var config = {
_id : "shardRep1", members : [
{_id : 0, host : 'localhost:43001'},
{_id : 1, host : 'localhost:43002'},
{_id : 2, host : 'localhost:43003'}
]
}
var config = { _id : "shardRep3", members : [ {_id : 0, host : 'localhost:43001'},{_id : 1, host : 'localhost:43002'}, {_id : 2, host : 'localhost:43003'} ]}
rs.initiate(config)
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#. routing 구성 : mongos 3대 구성
mongos --configdb configRepl/localhost:31001,localhost:31002,localhost:31003
#. mongos 에서 sharding 구성
<cmd 별도>
mongo --> mongos 확인
sh.addShard("shardRep1/localhost:41001")
sh.addShard("shardRep2/localhost:42001")
sh.addShard("shardRep3/localhost:43001")
sh.enableSharding("msTest")
sh.shardCollection("msTest.person",{_id:"hashed"});
use msTest
show collections
for(var i=0; i < 100000 ; i++) { db.person.insert({ number: i, name: "kor"+i }); };
+++++++++++++++++++ [ Sharding 분배 확인 ] ++++++++++++++
> db.person.find().count();
<cmd 별도>
mongo --port 41001
> show dbs
> use msTest
> show collections
> db.person.find().count()
> db.person.find().skip(1000).limit(10);
<shard2 >
mongo --port 42001
> show dbs
> use msTest
> show collections
> db.person.find().count()
> db.person.find().skip(1000).limit(10);
<shard3 >
mongo --port 41001
> show dbs
> use msTest
> show collections
> db.person.find().count()
> db.person.find().skip(1000).limit(10);
참고 https://kslee7746.tistory.com/category/MongoDB