Docs Menu
Docs Home
/
MongoDB ๋งค๋‰ด์–ผ
/ / /

์ž์ฒด ๊ด€๋ฆฌํ˜• ๋ณต์ œ๋ณธ ์„ธํŠธ๋ฅผ ์ƒค๋“œ ํด๋Ÿฌ์Šคํ„ฐ๋กœ ๋ณ€ํ™˜

์ด ํŽ˜์ด์ง€์˜ ๋‚ด์šฉ

  • ์ด ์ž‘์—…์— ๊ด€ํ•œ ์ •๋ณด
  • ์‹œ์ž‘ํ•˜๊ธฐ ์ „์—
  • ๋‹จ๊ณ„
  • ์ž์„ธํžˆ ์•Œ์•„๋ณด๊ธฐ

์ƒค๋”ฉ๋œ ํด๋Ÿฌ์Šคํ„ฐ๋Š” ์ƒค๋“œ ํ‚ค๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ์—ฌ๋Ÿฌ ์„œ๋ฒ„์— ๊ฑธ์ณ ๋ฐ์ดํ„ฐ๋ฅผ ๋ถ„ํ• ํ•ฉ๋‹ˆ๋‹ค. ์ƒค๋”ฉ๋œ ํด๋Ÿฌ์Šคํ„ฐ๋Š” ๋ฐ์ดํ„ฐ ์„ธํŠธ๊ฐ€ ํฌ๊ณ  ์ž‘์—… ์ฒ˜๋ฆฌ๋Ÿ‰์ด ๋งŽ์€ ๋ฐฐํฌ์˜ ๊ฒฝ์šฐ ๋ณต์ œ๋ณธ ์„ธํŠธ๋ณด๋‹ค ํ™•์žฅ์„ฑ์ด ๋›ฐ์–ด๋‚ฉ๋‹ˆ๋‹ค.

์ด ํŠœํ† ๋ฆฌ์–ผ์—์„œ๋Š” 3๋ช…์˜ ๋ฉค๋ฒ„๋กœ ๊ตฌ์„ฑ๋œ ๋‹จ์ผ ๋ณต์ œ๋ณธ ์„ธํŠธ๋ฅผ 2๊ฐœ์˜ ์ƒค๋“œ๊ฐ€ ์žˆ๋Š” ์ƒค๋”ฉ๋œ ํด๋Ÿฌ์Šคํ„ฐ๋กœ ๋ณ€ํ™˜ํ•ฉ๋‹ˆ๋‹ค. ์ƒˆ ํด๋Ÿฌ์Šคํ„ฐ์˜ ๊ฐ ์ƒค๋“œ๋Š” ๋…๋ฆฝ์ ์ธ 3๊ฐœ์˜ ๋ฉค๋ฒ„๋กœ ๊ตฌ์„ฑ๋œ ๋ณต์ œ๋ณธ ์„ธํŠธ์ž…๋‹ˆ๋‹ค.

MongoDB Atlas์—์„œ ํ˜ธ์ŠคํŒ…๋˜๋Š” ๋ฐฐํฌ์„œ๋ฒ„์— ๋Œ€ํ•ด UI์—์„œ ์ƒค๋”ฉ๋œ ํด๋Ÿฌ์Šคํ„ฐ๋กœ ๋ณ€ํ™˜ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์ด ํŠœํ† ๋ฆฌ์–ผ์—์„œ๋Š” ๋‹ค์Œ ์„œ๋ฒ„๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

ํ˜ธ์ŠคํŠธ ์ด๋ฆ„
ํฌํŠธ
์„ค๋ช…
mongodb0.example.net
27017
์ดˆ๊ธฐ ๋ฐ์ดํ„ฐ ๋ณด์œ  ์ƒค๋“œ์˜ ๋ฉค๋ฒ„ rs0์ž…๋‹ˆ๋‹ค.
mongodb1.example.net
27017
์ดˆ๊ธฐ ๋ฐ์ดํ„ฐ ๋ณด์œ  ์ƒค๋“œ์˜ ๋ฉค๋ฒ„ rs0์ž…๋‹ˆ๋‹ค.
mongodb2.example.net
27017
์ดˆ๊ธฐ ๋ฐ์ดํ„ฐ ๋ณด์œ  ์ƒค๋“œ์˜ ๋ฉค๋ฒ„ rs0์ž…๋‹ˆ๋‹ค.
mongodb3.example.net
27018
๋‘ ๋ฒˆ์งธ ๋ฐ์ดํ„ฐ ๋ณด์œ  ์ƒค๋“œ์˜ ๋ฉค๋ฒ„ rs1์ž…๋‹ˆ๋‹ค.
mongodb4.example.net
27018
๋‘ ๋ฒˆ์งธ ๋ฐ์ดํ„ฐ ๋ณด์œ  ์ƒค๋“œ์˜ ๋ฉค๋ฒ„ rs1์ž…๋‹ˆ๋‹ค.
mongodb5.example.net
27018
๋‘ ๋ฒˆ์งธ ๋ฐ์ดํ„ฐ ๋ณด์œ  ์ƒค๋“œ์˜ ๋ฉค๋ฒ„ rs1์ž…๋‹ˆ๋‹ค.
mongodb6.example.net
27017
์ƒค๋”ฉ๋œ ํด๋Ÿฌ์Šคํ„ฐ์— ์—ฐ๊ฒฐํ•˜๋Š” ๋ฐ ์‚ฌ์šฉ๋˜๋Š” mongos์ž…๋‹ˆ๋‹ค.
mongodb7.example.net
27019
config ์„œ๋ฒ„ ๋ณต์ œ๋ณธ ์„ธํŠธ์˜ ์ž…๋‹ˆ๋‹ค.
mongodb8.example.net
27019
config ์„œ๋ฒ„ ๋ณต์ œ๋ณธ ์„ธํŠธ์˜ ์ž…๋‹ˆ๋‹ค.
mongodb9.example.net
27019
config ์„œ๋ฒ„ ๋ณต์ œ๋ณธ ์„ธํŠธ์˜ ์ž…๋‹ˆ๋‹ค.

์ด ํŠœํ† ๋ฆฌ์–ผ์— ์‚ฌ์šฉ๋œ ํ˜ธ์ŠคํŠธ ์ด๋ฆ„์€ ์˜ˆ์‹œ์ž…๋‹ˆ๋‹ค. ์˜ˆ์‹œ ๋ช…๋ น์— ์‚ฌ์šฉ๋œ ํ˜ธ์ŠคํŠธ ์ด๋ฆ„์„ ๋ฐฐํฌ์— ์‚ฌ์šฉ๋œ ํ˜ธ์ŠคํŠธ ์ด๋ฆ„์œผ๋กœ ๋ฐ”๊ฟ‰๋‹ˆ๋‹ค.

์ค‘์š”

๋ณ€๊ฒฝ๋œ IP ์ฃผ์†Œ๋กœ ์ธํ•ด ๊ตฌ์„ฑ์ด ์—…๋ฐ์ดํŠธ๋˜๋Š” ๊ฒƒ์„ ๋ฐฉ์ง€ํ•˜๋ ค๋ฉด IP ์ฃผ์†Œ ๋Œ€์‹  DNS ํ˜ธ์ŠคํŠธ ์ด๋ฆ„์„ ์‚ฌ์šฉํ•˜์„ธ์š”. ํŠนํžˆ ๋ณต์ œ๋ณธ ์„ธํŠธ ๊ตฌ์„ฑ์› ๋˜๋Š” ์ƒค๋”ฉ๋œ ํด๋Ÿฌ์Šคํ„ฐ ๊ตฌ์„ฑ์›์„ ๊ตฌ์„ฑํ•  ๋•Œ IP ์ฃผ์†Œ ๋Œ€์‹  DNS ํ˜ธ์ŠคํŠธ ์ด๋ฆ„์„ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด ์ค‘์š”ํ•ฉ๋‹ˆ๋‹ค.

IP ์ฃผ์†Œ ๋Œ€์‹  ํ˜ธ์ŠคํŠธ ์ด๋ฆ„์„ ์‚ฌ์šฉํ•˜์—ฌ ์Šคํ”Œ๋ฆฟ ๋„คํŠธ์›Œํฌ ํ˜ธ๋ผ์ด์ฆŒ ์ „๋ฐ˜์— ๊ฑธ์ณ ํด๋Ÿฌ์Šคํ„ฐ๋ฅผ ๊ตฌ์„ฑํ•˜์„ธ์š”. MongoDB 5.0๋ถ€ํ„ฐ IP ์ฃผ์†Œ๋กœ๋งŒ ๊ตฌ์„ฑ๋œ ๋…ธ๋“œ๋Š” ์Šคํƒ€ํŠธ์—… ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ์— ์‹คํŒจํ•˜๋ฉฐ ์‹œ์ž‘๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

1

๊ธฐ์กด ์‚ฌ์šฉ์ž ๋ฐ ์—ญํ• ์„ ๊ฐ€์ ธ์˜ค๋ ค๋ฉด mongodump๋ฅผ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.

mongodump -d=admin --out=adminDump -u <adminUser> -p <password> --host <replicaSetURI> --dumpDbUsersAndRoles
2

config ์„œ๋ฒ„์— ๋Œ€ํ•ด 3๋ช…์˜ ๋ฉค๋ฒ„๋กœ ๊ตฌ์„ฑ๋œ ๋ณต์ œ๋ณธ ์„ธํŠธ๋ฅผ ๋ฐฐํฌํ•ฉ๋‹ˆ๋‹ค. ์ด ์˜ˆ์‹œ์—์„œ config ์„œ๋ฒ„๋Š” ๋‹ค์Œ ํ˜ธ์ŠคํŠธ๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

  • mongodb7.example.net

  • mongodb8.example.net

  • mongodb9.example.net

  1. Config ์„œ๋ฒ„ ๊ตฌ์„ฑ

    ๊ฐ Config ์„œ๋ฒ„ ํ˜ธ์ŠคํŠธ์—์„œ mongod ์ธ์Šคํ„ด์Šค๋ฅผ ๊ตฌ์„ฑํ•ฉ๋‹ˆ๋‹ค. ๊ฐ mongod ์ธ์Šคํ„ด์Šค์— ๋Œ€ํ•ด ๊ตฌ์„ฑ ํŒŒ์ผ์—์„œ ์ด๋Ÿฌํ•œ ์˜ต์…˜์„ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค.

    ์˜ต์…˜
    ๊ฐ’
    configReplSet
    configsvr
    localhost, ๊ทธ ๋’ค์— mongod๊ฐ€ ํด๋ผ์ด์–ธํŠธ ์—ฐ๊ฒฐ์„ ์ˆ˜์‹ ํ•ด์•ผ ํ•˜๋Š” ๋‹ค๋ฅธ ํ˜ธ์ŠคํŠธ ์ด๋ฆ„์„ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค.
    replication:
    replSetName: configReplSet
    sharding:
    clusterRole: configsvr
    net:
    bindIp: localhost,<hostname(s)>

    ๋ฐฐํฌ์— ์ ํ•ฉํ•œ ์ถ”๊ฐ€ ์˜ต์…˜์„ ํฌํ•จํ•˜์„ธ์š”.

  2. Config ์„œ๋ฒ„ ์‹œ์ž‘

    ์ง€์ •๋œ ๊ตฌ์„ฑ์œผ๋กœ mongod๋ฅผ ๋ฐฐํฌํ•ฉ๋‹ˆ๋‹ค.

    mongod --config <PATH_TO_CONFIG_FILE>

    config ์„œ๋ฒ„๋Š” ๊ธฐ๋ณธ ๋ฐ์ดํ„ฐ ๋””๋ ‰ํ† ๋ฆฌ /data/configdb ๋ฐ ๊ธฐ๋ณธ ํฌํŠธ 27019๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

  3. config ์„œ๋ฒ„ ์ค‘ ํ•˜๋‚˜์— ์—ฐ๊ฒฐํ•ฉ๋‹ˆ๋‹ค.

    mongosh(์„)๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ config ์„œ๋ฒ„ ์ค‘ ํ•˜๋‚˜์— ์—ฐ๊ฒฐํ•ฉ๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

    mongosh "mongodb://mongodb7.example.net:27019"
  4. config ์„œ๋ฒ„ ๋ณต์ œ๋ณธ ์„ธํŠธ๋ฅผ ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค.

    ๋ณต์ œ๋ณธ ์„ธํŠธ๋ฅผ ์‹œ์ž‘ํ•˜๋ ค๋ฉด rs.initiate()๋ฅผ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.

    rs.initiate( {
    _id: "configReplSet",
    configsvr: true,
    members: [
    { _id: 0, host: "mongodb7.example.net:27019" },
    { _id: 1, host: "mongodb8.example.net:27019" },
    { _id: 2, host: "mongodb9.example.net:27019" }
    ]
    } )

    ์•ž์˜ ๋ช…๋ น์€ ๋กœ์ปฌ ํ˜ธ์ŠคํŠธ ์˜ˆ์™ธ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ธ์ฆ ์—†์ด ๊ด€๋ฆฌ ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•ฉ๋‹ˆ๋‹ค.

    ์ค‘์š”

    ๋ณต์ œ๋ณธ ์„ธํŠธ์— ๋Œ€ํ•ด ๋‹จ mongod rs.initiate() ํ•˜๋‚˜์˜ ์ธ์Šคํ„ด์Šค์—์„œ๋งŒ ๋ฅผ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.

3

mongodump๋ฅผ ์‹คํ–‰ํ–ˆ์„ ๋•Œ ์–ป์€ ๊ธฐ์กด ์‚ฌ์šฉ์ž์™€ ์—ญํ• ์„ ๋ณต์›ํ•ฉ๋‹ˆ๋‹ค.

mongorestore ./adminDump --nsInclude "admin.*" --host <configPrimaryURI>

์•ž์˜ ๋ช…๋ น์€ ๋กœ์ปฌ ํ˜ธ์ŠคํŠธ ์˜ˆ์™ธ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ธ์ฆ ์—†์ด ๊ด€๋ฆฌ ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•ฉ๋‹ˆ๋‹ค.

์ด ๋ช…๋ น์„ ์‹คํ–‰ํ•˜๋ฉด ๋‹ค์Œ๊ณผ ๋น„์Šทํ•œ ๊ฒฐ๊ณผ๊ฐ€ ๋‚˜์˜ฌ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

0 document(s) restored successfully

์ด ๋ฉ”์‹œ์ง€๋Š” ๋ฌธ์ œ๋ฅผ ๋‚˜ํƒ€๋‚ด์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ์ด ์ถœ๋ ฅ์€ ์‚ฌ์šฉ์ž ๋ฐ ์—ญํ•  ์ด์™ธ์˜ 0๊ฐœ์˜ ๋ฌธ์„œ๊ฐ€ ๋ณต์›๋˜์—ˆ์Œ์„ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค.

4

๊ตฌ์„ฑ ์„œ๋ฒ„ ๋ณต์ œ๋ณธ ์„ธํŠธ๋ฅผ ์žฌ๊ตฌ์„ฑํ•˜๊ณ  ๋‹ค์‹œ ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค.

  1. Config ์„œ๋ฒ„ ์žฌ๊ตฌ์„ฑ

    ์ธ์ฆ ๋ฉ”์ปค๋‹ˆ์ฆ˜์˜ ํƒญ์„ ์„ ํƒํ•ฉ๋‹ˆ๋‹ค.

    ๋‹ค์Œ ๊ฐ ํ˜ธ์ŠคํŠธ์—์„œ mongod ์ธ์Šคํ„ด์Šค๋ฅผ ๋‹ค์‹œ ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค.

    • mongodb7.example.net

    • mongodb8.example.net

    • mongodb9.example.net

    ๊ฐ mongod ์ธ์Šคํ„ด์Šค์— ๋Œ€ํ•ด ๊ตฌ์„ฑ ํŒŒ์ผ์—์„œ ์ด๋Ÿฌํ•œ ์˜ต์…˜์„ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค:

    ์˜ต์…˜
    ๊ฐ’
    ์ดˆ๊ธฐ ๋ณต์ œ๋ณธ ์„ธํŠธ์— ์‚ฌ์šฉ๋˜๋Š” ํ‚ค ํŒŒ์ผ์˜ ๊ฒฝ๋กœ์ž…๋‹ˆ๋‹ค.
    security:
    keyFile: <PATH_TO_KEYFILE>
    replication:
    replSetName: configReplSet
    sharding:
    clusterRole: configsvr
    net:
    bindIp: localhost,<hostname(s)>

    ๋ฐฐํฌ์— ์ ํ•ฉํ•œ ์ถ”๊ฐ€ ์˜ต์…˜์„ ํฌํ•จํ•˜์„ธ์š”.

    ๋‹ค์Œ ๊ฐ ํ˜ธ์ŠคํŠธ์—์„œ mongod ์ธ์Šคํ„ด์Šค๋ฅผ ๋‹ค์‹œ ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค.

    • mongodb7.example.net

    • mongodb8.example.net

    • mongodb9.example.net

    ์ด๋ฏธ ๊ตฌ์„ฑํ•œ mongod ์˜ต์…˜ ์™ธ์—๋„ ๊ฐ ์ธ์Šคํ„ด์Šค์— ๋Œ€ํ•œ ๊ตฌ์„ฑ ํŒŒ์ผ์—์„œ ๋‹ค์Œ ์˜ต์…˜์„ ์ง€์ •ํ•˜์„ธ์š”.

    ์˜ต์…˜
    ๊ฐ’
    x509
    requireTLS
    TLS ์ธ์ฆ์„œ์™€ ํ‚ค๊ฐ€ ๋ชจ๋‘ ํฌํ•จ๋œ .pem ํŒŒ์ผ์˜ ์ ˆ๋Œ€ ๊ฒฝ๋กœ์ž…๋‹ˆ๋‹ค.
    ์ธ์ฆ ๊ธฐ๊ด€์˜ ๋ฃจํŠธ ์ธ์ฆ์„œ ์ฒด์ธ์ด ํฌํ•จ๋œ .pem ํŒŒ์ผ์˜ ์ ˆ๋Œ€ ๊ฒฝ๋กœ์ž…๋‹ˆ๋‹ค.

    localhost, ๊ทธ ๋’ค์— mongod๊ฐ€ ํด๋ผ์ด์–ธํŠธ ์—ฐ๊ฒฐ์„ ์ˆ˜์‹ ํ•ด์•ผ ํ•˜๋Š” ๋‹ค๋ฅธ ํ˜ธ์ŠคํŠธ ์ด๋ฆ„์„ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค.

    ๊ฒฝ๊ณ : ๊ณต๊ฐœ์ ์œผ๋กœ ์•ก์„ธ์Šคํ•  ์ˆ˜ ์žˆ๋Š” IP ์ฃผ์†Œ ์— ์ธ์Šคํ„ด์Šค ๋ฅผ ๋ฐ”์ธ๋”ฉํ•˜๊ธฐ ์ „์— ๋ฌด๋‹จ ์•ก์„ธ์Šค ๋กœ๋ถ€ํ„ฐ ํด๋Ÿฌ์Šคํ„ฐ ๋ฅผ ๋ณดํ˜ธํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ๋ณด์•ˆ ๊ถŒ์žฅ ์‚ฌํ•ญ์˜ ์ „์ฒด ๋ชฉ๋ก์€ ์ž์ฒด ๊ด€๋ฆฌ ๋ฐฐํฌ์„œ๋ฒ„๋ฅผ ์œ„ํ•œ ๋ณด์•ˆ ์ฒดํฌ๋ฆฌ์ŠคํŠธ๋ฅผ ์ฐธ์กฐํ•˜์„ธ์š”. ์ตœ์†Œํ•œ ์ธ์ฆ ์„ ํ™œ์„ฑํ™”ํ•˜๊ณ  ๋„คํŠธ์›Œํฌ ์ธํ”„๋ผ๋ฅผ ๊ฐ•ํ™”ํ•˜๋Š” ๊ฒƒ์„ ๊ณ ๋ คํ•˜์„ธ์š”.

    sharding:
    clusterRole: configsvr
    replication:
    replSetName: configReplSet
    security:
    clusterAuthMode: x509
    net:
    tls:
    mode: requireTLS
    certificateKeyFile: <FILE_WITH_COMBINED_CERT_AND_KEY>
    CAFile: <CA_FILE>
    bindIp: localhost,<hostname(s)>

    TLS ์ธ์ฆ์„œ ํ‚ค ํŒŒ์ผ์ด ๋น„๋ฐ€๋ฒˆํ˜ธ๋กœ ์•”ํ˜ธํ™”๋œ ๊ฒฝ์šฐ net.tls.certificateKeyFilePassword์™€ ๊ฐ™์ด ๋ฐฐํฌ์— ์ ํ•ฉํ•œ ์ถ”๊ฐ€ ์˜ต์…˜์„ ํฌํ•จํ•ฉ๋‹ˆ๋‹ค.

  2. MongoDB ๋‹ค์‹œ ์‹œ์ž‘

    ์ง€์ •๋œ ๊ตฌ์„ฑ์œผ๋กœ mongod๋ฅผ ๋‹ค์‹œ ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค.

    mongod --config <PATH_TO_CONFIG_FILE> --shutdown
    mongod --config <PATH_TO_CONFIG_FILE>
5

mongos๋Š” ํด๋ผ์ด์–ธํŠธ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜๊ณผ ์ƒค๋”ฉ๋œ ํด๋Ÿฌ์Šคํ„ฐ ๊ฐ„์˜ ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.

  1. mongos์— ๋Œ€ํ•œ ๊ตฌ์„ฑ ํŒŒ์ผ์„ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

    mongos ๊ตฌ์„ฑ ํŒŒ์ผ์— ๋‹ค์Œ ์˜ต์…˜์„ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค.

    ์˜ต์…˜
    ๊ฐ’
    configReplSet, ๋’ค์— ์Šฌ๋ž˜์‹œ / ๋ฐ config ์„œ๋ฒ„ ํ˜ธ์ŠคํŠธ ์ด๋ฆ„ ๋ฐ ํฌํŠธ ์ค‘ ์ตœ์†Œ ํ•œ ๊ฐœ๊ฐ€ ์ด์–ด์ง‘๋‹ˆ๋‹ค.
    ์ดˆ๊ธฐ ๋ณต์ œ๋ณธ ์„ธํŠธ์— ์‚ฌ์šฉ๋˜๋Š” ํ‚ค ํŒŒ์ผ์˜ ๊ฒฝ๋กœ์ž…๋‹ˆ๋‹ค.
    localhost, ๊ทธ ๋’ค์— mongos๊ฐ€ ํด๋ผ์ด์–ธํŠธ ์—ฐ๊ฒฐ์„ ์ˆ˜์‹ ํ•ด์•ผ ํ•˜๋Š” ๋‹ค๋ฅธ ํ˜ธ์ŠคํŠธ ์ด๋ฆ„์„ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค.
    sharding:
    configDB: configReplSet/mongodb7.example.net:27019,mongodb8.example.net:27019,mongodb9.example.net:27019
    security:
    keyFile: <PATH_TO_KEYFILE>
    net:
    bindIp: localhost,<hostname(s)>

    ๋ฐฐํฌ์— ์ ํ•ฉํ•œ ์ถ”๊ฐ€ ์˜ต์…˜์„ ํฌํ•จํ•˜์„ธ์š”.

    mongos ๊ตฌ์„ฑ ํŒŒ์ผ์— ๋‹ค์Œ ์˜ต์…˜์„ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค.

    ์˜ต์…˜
    ๊ฐ’
    configReplSet, ๋’ค์— ์Šฌ๋ž˜์‹œ / ๋ฐ config ์„œ๋ฒ„ ํ˜ธ์ŠคํŠธ ์ด๋ฆ„ ๋ฐ ํฌํŠธ ์ค‘ ์ตœ์†Œ ํ•œ ๊ฐœ๊ฐ€ ์ด์–ด์ง‘๋‹ˆ๋‹ค.
    x509
    requireTLS
    TLS ์ธ์ฆ์„œ์™€ ํ‚ค๊ฐ€ ๋ชจ๋‘ ํฌํ•จ๋œ .pem ํŒŒ์ผ์˜ ์ ˆ๋Œ€ ๊ฒฝ๋กœ์ž…๋‹ˆ๋‹ค.
    ์ธ์ฆ ๊ธฐ๊ด€์˜ ๋ฃจํŠธ ์ธ์ฆ์„œ ์ฒด์ธ์ด ํฌํ•จ๋œ .pem ํŒŒ์ผ์˜ ์ ˆ๋Œ€ ๊ฒฝ๋กœ์ž…๋‹ˆ๋‹ค.
    localhost, ๊ทธ ๋’ค์— mongos๊ฐ€ ํด๋ผ์ด์–ธํŠธ ์—ฐ๊ฒฐ์„ ์ˆ˜์‹ ํ•ด์•ผ ํ•˜๋Š” ๋‹ค๋ฅธ ํ˜ธ์ŠคํŠธ ์ด๋ฆ„์„ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค.
    sharding:
    configDB: configReplSet/mongodb7.example.net:27019,mongodb8.example.net:27019,mongodb9.example.net:27019
    security:
    clusterAuthMode: x509
    net:
    tls:
    mode: requireTLS
    certificateKeyFile: <FILE_WITH_COMBINED_CERT_AND_KEY>
    CAFile: <CA_FILE>
    bindIp: localhost,<hostname(s)>

    ๋ฐฐํฌ์— ์ ํ•ฉํ•œ ์ถ”๊ฐ€ ์˜ต์…˜์„ ํฌํ•จํ•ฉ๋‹ˆ๋‹ค.

  2. mongos๋ฅผ ๋ฐฐํฌํ•ฉ๋‹ˆ๋‹ค.

    ์ง€์ •๋œ ๊ตฌ์„ฑ์œผ๋กœ mongos๋ฅผ ๋ฐฐํฌํ•ฉ๋‹ˆ๋‹ค.

    mongos --config <PATH_TO_CONFIG_FILE>
6

์ด ์˜ˆ์‹œ์—์„œ ์ดˆ๊ธฐ ๋ณต์ œ๋ณธ ์„ธํŠธ๋Š” 3๋ช…์˜ ๋ฉค๋ฒ„๋กœ ๊ตฌ์„ฑ๋œ ๋ณต์ œ๋ณธ ์„ธํŠธ์ž…๋‹ˆ๋‹ค. ์ด ๋‹จ๊ณ„์—์„œ๋Š” ์ƒค๋”ฉ๋œ ํด๋Ÿฌ์Šคํ„ฐ์— ์ƒค๋“œ๋กœ ์ถ”๊ฐ€๋  ์ˆ˜ ์žˆ๋„๋ก ์ดˆ๊ธฐ ๋ณต์ œ๋ณธ ์„ธํŠธ๋ฅผ ์—…๋ฐ์ดํŠธํ•ฉ๋‹ˆ๋‹ค.

๋ณต์ œ๋ณธ ์„ธํŠธ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์€ ํ˜ธ์ŠคํŠธ์—์„œ ์‹คํ–‰๋ฉ๋‹ˆ๋‹ค.

  • mongodb0.example.net:27017

  • mongodb1.example.net:27017

  • mongodb2.example.net:27017

์ƒค๋”ฉ๋œ ํด๋Ÿฌ์Šคํ„ฐ์˜ ๊ฒฝ์šฐ, ์ƒค๋“œ์˜ ๊ฐ mongod ์ธ์Šคํ„ด์Šค์— ๋Œ€ํ•œ ์—ญํ• ์„ shardsvr๋กœ ์„ค์ •ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์„œ๋ฒ„ ์—ญํ• ์„ ์„ค์ •ํ•˜๋ ค๋ฉด mongod ๊ตฌ์„ฑ ํŒŒ์ผ์—์„œ sharding.clusterRole ์„ค์ •์„ ์ ์šฉํ•ฉ๋‹ˆ๋‹ค.

์ฐธ๊ณ 

shardsvr ์—ญํ• ์„ ๊ฐ€์ง„ mongod ์ธ์Šคํ„ด์Šค์˜ ๊ธฐ๋ณธ ํฌํŠธ๋Š” 27018์ž…๋‹ˆ๋‹ค. ๋‹ค๋ฅธ ํฌํŠธ๋ฅผ ์‚ฌ์šฉํ•˜๋ ค๋ฉด net.port ์„ค์ •์„ ์ง€์ •ํ•˜์„ธ์š”.

  1. ์ดˆ๊ธฐ ๋ณต์ œ๋ณธ ์„ธํŠธ์˜ ๋ฉค๋ฒ„์— ์—ฐ๊ฒฐํ•ฉ๋‹ˆ๋‹ค.

    mongosh๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ดˆ๊ธฐ ๋ณต์ œ๋ณธ ์„ธํŠธ์˜ ๋ฉค๋ฒ„ ์ค‘ ํ•˜๋‚˜์— ์—ฐ๊ฒฐํ•ฉ๋‹ˆ๋‹ค.

    mongosh "mongodb://<username>@mongodb0.example.net:27017"

    ๋ฐฐํฌ์— x.509 ์ธ์ฆ์„ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ ๋‹ค์Œ mongosh ์˜ต์…˜์„ ์ง€์ •ํ•˜์„ธ์š”.

    ์˜ˆ๋ฅผ ๋“ค๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

    mongosh "mongodb://<username>@mongodb0.example.net:27017" --tls --tlsCAFile <CA_FILE> --tlsCertificateKeyFile <filename>
  2. ๋ณต์ œ๋ณธ ์„ธํŠธ์˜ ํ”„๋ผ์ด๋จธ๋ฆฌ ๋ฐ ์„ธ์ปจ๋”๋ฆฌ๋ฅผ ๊ฒฐ์ •ํ•ฉ๋‹ˆ๋‹ค.

    rs.status() ์‹คํ–‰ํ•˜์—ฌ ํ”„๋ผ์ด๋จธ๋ฆฌ ๋ฐ ์„ธ์ปจ๋”๋ฆฌ๋ฅผ ํ•ฉ๋‹ˆ๋‹ค.

    rs.status()

    ๋ช…๋ น ์ถœ๋ ฅ์—์„œ replSetGetStatus.members[n].stateStr ํ•„๋“œ๋Š” ์–ด๋–ค ๋ฉค๋ฒ„๊ฐ€ ํ”„๋ผ์ด๋จธ๋ฆฌ์ด๊ณ  ์–ด๋–ค ๋ฉค๋ฒ„๊ฐ€ ์„ธ์ปจ๋”๋ฆฌ ๋ฉค๋ฒ„์ธ์ง€๋ฅผ ๋‚˜ํƒ€๋ƒ…๋‹ˆ๋‹ค.

  3. --shardsvr ์˜ต์…˜์œผ๋กœ ์„ธ์ปจ๋”๋ฆฌ๋ฅผ ๋‹ค์‹œ ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค.

    ๊ฒฝ๊ณ 

    ์ด ๋‹จ๊ณ„์—์„œ๋Š” ๋ณต์ œ๋ณธ ์„ธํŠธ ์„ธ์ปจ๋”๋ฆฌ์— ์—ฐ๊ฒฐ๋œ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์— ๋Œ€ํ•ด ์•ฝ๊ฐ„์˜ ์ค‘๋‹จ ์‹œ๊ฐ„์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.

    ์„ธ์ปจ๋”๋ฆฌ ๋ฅผ ๋‹ค์‹œ ์‹œ์ž‘ํ•œ ํ›„ ์ดˆ๊ธฐ ๋ณต์ œ๋ณธ ์„ธํŠธ๋ฅผ ์ƒค๋“œ๋กœ ์ถ”๊ฐ€์˜๋‹จ๊ณ„๋ฅผ ์ˆ˜ํ–‰ํ•  ๋•Œ๊นŒ์ง€ ํ•ด๋‹น ์„ธ์ปจ๋”๋ฆฌ ์— ์—ฐ๊ฒฐ๋œ ๋ชจ๋“  ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์€ CannotVerifyAndSignLogicalTime ์˜ค๋ฅ˜๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

    ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ๋‹ค์‹œ ์‹œ์ž‘ํ•˜์—ฌ CannotVerifyAndSignLogicalTime ์˜ค๋ฅ˜๋ฅผ ์ˆ˜์‹ ํ•˜์ง€ ์•Š๋„๋ก ํ•  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค.

    1. ์„ธ์ปจ๋”๋ฆฌ์— ์—ฐ๊ฒฐํ•ฉ๋‹ˆ๋‹ค.

      mongosh๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์„ธ์ปจ๋”๋ฆฌ ์ค‘ ํ•˜๋‚˜์— ์—ฐ๊ฒฐํ•ฉ๋‹ˆ๋‹ค.

      mongosh "mongodb://<username>@<host>:<port>"
    2. ์„ธ์ปจ๋”๋ฆฌ๋ฅผ ์ข…๋ฃŒํ•ฉ๋‹ˆ๋‹ค.

      ๋‹ค์Œ ๋ช…๋ น์„ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.

      use admin
      db.shutdownServer()
    3. ์„ธ์ปจ๋”๋ฆฌ ๊ตฌ์„ฑ ํŒŒ์ผ์„ ํŽธ์ง‘ํ•ฉ๋‹ˆ๋‹ค.

      ์„ธ์ปจ๋”๋ฆฌ ๊ตฌ์„ฑ ํŒŒ์ผ์—์„œ sharding.clusterRole๋ฅผ shardsvr๋กœ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค.

      security:
      keyFile: <PATH_TO_KEYFILE>
      replication:
      replSetName: rs0
      sharding:
      clusterRole: shardsvr
      net:
      port: 27017
      bindIp: localhost,<hostname(s)>

      ๋ฐฐํฌ์— ์ ํ•ฉํ•œ ์ถ”๊ฐ€ ์˜ต์…˜์„ ํฌํ•จํ•˜์„ธ์š”.

    4. ์„ธ์ปจ๋”๋ฆฌ๋ฅผ ์ƒค๋“œ ์„œ๋ฒ„๋กœ ๋‹ค์‹œ ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค.

      ์„ธ์ปจ๋”๋ฆฌ๊ฐ€ ํฌํ•จ๋œ ํ˜ธ์ŠคํŠธ์—์„œ ๋‹ค์Œ ๋ช…๋ น์„ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.

      mongod --config <PATH_TO_CONFIG_FILE>
    5. ๋‹ค๋ฅธ ์„ธ์ปจ๋”๋ฆฌ์— ๋Œ€ํ•ด ์ข…๋ฃŒ ๋ฐ ์žฌ์‹œ์ž‘ ๋‹จ๊ณ„๋ฅผ ๋ฐ˜๋ณตํ•ฉ๋‹ˆ๋‹ค.

    1. ์„ธ์ปจ๋”๋ฆฌ์— ์—ฐ๊ฒฐํ•ฉ๋‹ˆ๋‹ค.

      mongosh๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์„ธ์ปจ๋”๋ฆฌ ์ค‘ ํ•˜๋‚˜์— ์—ฐ๊ฒฐํ•ฉ๋‹ˆ๋‹ค.

      ๋ฐฐํฌ์— x.509 ์ธ์ฆ์„ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ ๋‹ค์Œ mongosh ์˜ต์…˜์„ ์ง€์ •ํ•˜์„ธ์š”.

      mongosh "mongodb://<username>@<host>:<port>" --tls --tlsCAFile <CA_FILE> --tlsCertificateKeyFile <filename>
    2. ์„ธ์ปจ๋”๋ฆฌ๋ฅผ ์ข…๋ฃŒํ•ฉ๋‹ˆ๋‹ค.

      ๋‹ค์Œ ๋ช…๋ น์„ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.

      use admin
      db.shutdownServer()
    3. ์„ธ์ปจ๋”๋ฆฌ ๊ตฌ์„ฑ ํŒŒ์ผ์„ ํŽธ์ง‘ํ•ฉ๋‹ˆ๋‹ค.

      ์„ธ์ปจ๋”๋ฆฌ ๊ตฌ์„ฑ ํŒŒ์ผ์—์„œ sharding.clusterRole๋ฅผ shardsvr๋กœ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค.

      replication:
      replSetName: rs0
      sharding:
      clusterRole: shardsvr
      security:
      clusterAuthMode: x509
      net:
      port: 27017
      tls:
      mode: requireTLS
      certificateKeyFile: <FILE_WITH_COMBINED_CERT_AND_KEY>
      CAFile: <CA_FILE>
      bindIp: localhost,<hostname(s)>

      TLS ์ธ์ฆ์„œ ํ‚ค ํŒŒ์ผ์ด ๋น„๋ฐ€๋ฒˆํ˜ธ๋กœ ์•”ํ˜ธํ™”๋œ ๊ฒฝ์šฐ net.tls.certificateKeyFilePassword์™€ ๊ฐ™์ด ๋ฐฐํฌ์— ์ ํ•ฉํ•œ ์ถ”๊ฐ€ ์˜ต์…˜์„ ํฌํ•จํ•ฉ๋‹ˆ๋‹ค.

    4. ์„ธ์ปจ๋”๋ฆฌ๋ฅผ ์ƒค๋“œ ์„œ๋ฒ„๋กœ ๋‹ค์‹œ ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค.

      ์„ธ์ปจ๋”๋ฆฌ๊ฐ€ ํฌํ•จ๋œ ํ˜ธ์ŠคํŠธ์—์„œ ๋‹ค์Œ ๋ช…๋ น์„ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.

      mongod --config <PATH_TO_CONFIG_FILE>
    5. ๋‹ค๋ฅธ ์„ธ์ปจ๋”๋ฆฌ์— ๋Œ€ํ•ด ์ข…๋ฃŒ ๋ฐ ์žฌ์‹œ์ž‘ ๋‹จ๊ณ„๋ฅผ ๋ฐ˜๋ณตํ•ฉ๋‹ˆ๋‹ค.

7

๊ฒฝ๊ณ 

์ด ๋‹จ๊ณ„์—์„œ๋Š” ๋ณต์ œ๋ณธ ์„ธํŠธ์˜ ํ”„๋ผ์ด๋จธ๋ฆฌ์— ์—ฐ๊ฒฐ๋œ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์— ๋Œ€ํ•ด ์•ฝ๊ฐ„์˜ ์ค‘๋‹จ ์‹œ๊ฐ„์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.

ํ”„๋ผ์ด๋จธ๋ฆฌ ๋ฅผ ๋‹ค์‹œ ์‹œ์ž‘ํ•œ ํ›„ ์ดˆ๊ธฐ ๋ณต์ œ๋ณธ ์„ธํŠธ๋ฅผ ์ƒค๋“œ๋กœ ์ถ”๊ฐ€์˜๋‹จ๊ณ„๋ฅผ ์ˆ˜ํ–‰ํ•  ๋•Œ๊นŒ์ง€ ํ”„๋ผ์ด๋จธ๋ฆฌ ์— ์—ฐ๊ฒฐ๋œ ๋ชจ๋“  ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์€ CannotVerifyAndSignLogicalTime ์˜ค๋ฅ˜๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ๋‹ค์‹œ ์‹œ์ž‘ํ•˜์—ฌ CannotVerifyAndSignLogicalTime ์˜ค๋ฅ˜๋ฅผ ์ˆ˜์‹ ํ•˜์ง€ ์•Š๋„๋ก ํ•  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค.

  1. ํ”„๋ผ์ด๋จธ๋ฆฌ์— ์—ฐ๊ฒฐํ•ฉ๋‹ˆ๋‹ค.

    mongosh๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํ”„๋ผ์ด๋จธ๋ฆฌ์— ์—ฐ๊ฒฐํ•ฉ๋‹ˆ๋‹ค.

    mongosh "mongodb://<username>@<host>:<port>"
  2. ํ”„๋ผ์ด๋จธ๋ฆฌ์„ ๋‚ด๋ ค๋†“์Šต๋‹ˆ๋‹ค.

    ๋‹ค์Œ ๋ช…๋ น์„ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค:

    rs.stepDown()
  3. ๊ฐ•๋“ฑ์ด ์™„๋ฃŒ๋˜์—ˆ๋Š”์ง€ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.

    rs.status()๋ฅผ ์‹คํ–‰ํ•˜์—ฌ ์—ฐ๊ฒฐ๋œ ๋ฉค๋ฒ„๊ฐ€ ์„ธ์ปจ๋”๋ฆฌ๋กœ ๋ณ€๊ฒฝ๋˜์—ˆ๋Š”์ง€ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.

    rs.status()
  4. ์ด์ „ ํ”„๋ผ์ด๋จธ๋ฆฌ๋ฅผ ์ข…๋ฃŒํ•ฉ๋‹ˆ๋‹ค.

    ๋‹ค์Œ ๋ช…๋ น์„ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.

    use admin
    db.shutdownServer()

    ์ข…๋ฃŒ๊ฐ€ ์™„๋ฃŒ๋  ๋•Œ๊นŒ์ง€ ๊ธฐ๋‹ค๋ฆฝ๋‹ˆ๋‹ค.

  5. ํ”„๋ผ์ด๋จธ๋ฆฌ์˜ ๊ตฌ์„ฑ ํŒŒ์ผ์„ ํŽธ์ง‘ํ•ฉ๋‹ˆ๋‹ค.

    ํ”„๋ผ์ด๋จธ๋ฆฌ ๊ตฌ์„ฑ ํŒŒ์ผ์—์„œ sharding.clusterRole์„ shardsvr๋กœ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค.

    security:
    keyFile: <PATH_TO_KEYFILE>
    replication:
    replSetName: rs0
    sharding:
    clusterRole: shardsvr
    net:
    port: 27017
    bindIp: localhost,<hostname(s)>

    ๋ฐฐํฌ์— ์ ํ•ฉํ•œ ์ถ”๊ฐ€ ์˜ต์…˜์„ ํฌํ•จํ•˜์„ธ์š”.

  6. ํ”„๋ผ์ด๋จธ๋ฆฌ๋ฅผ ์ƒค๋“œ ์„œ๋ฒ„๋กœ ๋‹ค์‹œ ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค.

    ํ”„๋ผ์ด๋จธ๋ฆฌ๊ฐ€ ํฌํ•จ๋œ ํ˜ธ์ŠคํŠธ์—์„œ ๋‹ค์Œ ๋ช…๋ น์„ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.

    mongod --config <PATH_TO_CONFIG_FILE>
  1. ํ”„๋ผ์ด๋จธ๋ฆฌ์— ์—ฐ๊ฒฐํ•ฉ๋‹ˆ๋‹ค.

    mongosh๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์„ธ์ปจ๋”๋ฆฌ ์ค‘ ํ•˜๋‚˜์— ์—ฐ๊ฒฐํ•ฉ๋‹ˆ๋‹ค.

    ๋ฐฐํฌ์— x.509 ์ธ์ฆ์„ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ ๋‹ค์Œ mongosh ์˜ต์…˜์„ ์ง€์ •ํ•˜์„ธ์š”.

    ๋ฐฐํฌ์— x.509 ์ธ์ฆ์„ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ ๋‹ค์Œ mongosh ์˜ต์…˜์„ ์ง€์ •ํ•˜์„ธ์š”.

    mongosh "mongodb://<username>@<host>:<port>" --tls --tlsCAFile <CA_FILE> --tlsCertificateKeyFile <filename>
  2. ํ”„๋ผ์ด๋จธ๋ฆฌ์„ ๋‚ด๋ ค๋†“์Šต๋‹ˆ๋‹ค.

    ๋‹ค์Œ ๋ช…๋ น์„ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค:

    rs.stepDown()
  3. ๊ฐ•๋“ฑ์ด ์™„๋ฃŒ๋˜์—ˆ๋Š”์ง€ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.

    rs.status()๋ฅผ ์‹คํ–‰ํ•˜์—ฌ ์—ฐ๊ฒฐ๋œ ๋ฉค๋ฒ„๊ฐ€ ์„ธ์ปจ๋”๋ฆฌ๋กœ ๋ณ€๊ฒฝ๋˜์—ˆ๋Š”์ง€ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.

    rs.status()
  4. ์ด์ „ ํ”„๋ผ์ด๋จธ๋ฆฌ๋ฅผ ์ข…๋ฃŒํ•ฉ๋‹ˆ๋‹ค.

    ๋‹ค์Œ ๋ช…๋ น์„ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.

    use admin
    db.shutdownServer()

    ์ข…๋ฃŒ๊ฐ€ ์™„๋ฃŒ๋  ๋•Œ๊นŒ์ง€ ๊ธฐ๋‹ค๋ฆฝ๋‹ˆ๋‹ค.

  5. ํ”„๋ผ์ด๋จธ๋ฆฌ์˜ ๊ตฌ์„ฑ ํŒŒ์ผ์„ ํŽธ์ง‘ํ•ฉ๋‹ˆ๋‹ค.

    ํ”„๋ผ์ด๋จธ๋ฆฌ ๊ตฌ์„ฑ ํŒŒ์ผ์—์„œ sharding.clusterRole์„ shardsvr๋กœ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค.

    replication:
    replSetName: rs0
    sharding:
    clusterRole: shardsvr
    security:
    clusterAuthMode: x509
    net:
    port: 27017
    tls:
    mode: requireTLS
    certificateKeyFile: <FILE_WITH_COMBINED_CERT_AND_KEY>
    CAFile: <CA_FILE>
    bindIp: localhost,<hostname(s)>

    TLS ์ธ์ฆ์„œ ํ‚ค ํŒŒ์ผ์ด ๋น„๋ฐ€๋ฒˆํ˜ธ๋กœ ์•”ํ˜ธํ™”๋œ ๊ฒฝ์šฐ net.tls.certificateKeyFilePassword์™€ ๊ฐ™์ด ๋ฐฐํฌ์— ์ ํ•ฉํ•œ ์ถ”๊ฐ€ ์˜ต์…˜์„ ํฌํ•จํ•ฉ๋‹ˆ๋‹ค.

  6. ํ”„๋ผ์ด๋จธ๋ฆฌ๋ฅผ ์ƒค๋“œ ์„œ๋ฒ„๋กœ ๋‹ค์‹œ ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค.

    ํ”„๋ผ์ด๋จธ๋ฆฌ๊ฐ€ ํฌํ•จ๋œ ํ˜ธ์ŠคํŠธ์—์„œ ๋‹ค์Œ ๋ช…๋ น์„ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.

    mongod --config <PATH_TO_CONFIG_FILE>
8

์ดˆ๊ธฐ ๋ณต์ œ๋ณธ ์„ธํŠธ(rs0)๋ฅผ ์ƒค๋“œ๋กœ ๋ณ€ํ™˜ํ•œ ํ›„ ์ด๋ฅผ ์ƒค๋”ฉ๋œ ํด๋Ÿฌ์Šคํ„ฐ์— ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค.

  1. ํด๋Ÿฌ์Šคํ„ฐ์˜ ๊ด€๋ฆฌ ์‚ฌ์šฉ์ž๋กœ mongos์— ์—ฐ๊ฒฐํ•ฉ๋‹ˆ๋‹ค.

    mongos ์ธ์Šคํ„ด์Šค๊ฐ€ ํ˜ธ์ŠคํŠธ mongodb6.example.net์—์„œ ์‹คํ–‰ ์ค‘์ž…๋‹ˆ๋‹ค.

    mongosh์„ mongos์— ์—ฐ๊ฒฐํ•˜๋ ค๋ฉด ๋‹ค์Œ ๋ช…๋ น์„ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค:

    mongosh "mongodb://admin01@mongodb6.example.net:27017"

    ๋ฐฐํฌ์— x.509 ์ธ์ฆ์„ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ ๋‹ค์Œ mongosh ์˜ต์…˜์„ ์ง€์ •ํ•˜์„ธ์š”.

    ๋ฐฐํฌ์— x.509 ์ธ์ฆ์„ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ ๋‹ค์Œ mongosh ์˜ต์…˜์„ ์ง€์ •ํ•˜์„ธ์š”.

    mongosh "mongodb://admin01@mongodb6.example.net:27017" --tls --tlsCAFile <CA_FILE> --tlsCertificateKeyFile <filename>

    ์ด ๋ช…๋ น์€ ์ƒค๋”ฉ๋œ ํด๋Ÿฌ์Šคํ„ฐ์—์„œ ์ƒ์„ฑํ•œ admin01 ์‚ฌ์šฉ์ž๋กœ ์ธ์ฆํ•ฉ๋‹ˆ๋‹ค. ๋ช…๋ น์„ ์ž…๋ ฅํ•œ ํ›„ ์‚ฌ์šฉ์ž ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ฉ๋‹ˆ๋‹ค.

  2. ์ƒค๋“œ๋ฅผ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค.

    ํด๋Ÿฌ์Šคํ„ฐ์— ์ƒค๋“œ๋ฅผ ์ถ”๊ฐ€ํ•˜๋ ค๋ฉด sh.addShard() ๋ฉ”์„œ๋“œ๋ฅผ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.

    sh.addShard( "rs0/mongodb0.example.net:27017,mongodb1.example.net:27017,mongodb2.example.net:27017" )

    ๊ฒฝ๊ณ 

    ์ƒˆ ์ƒค๋“œ๊ฐ€ ํ™œ์„ฑํ™”๋˜๋ฉด mongosh ๋ฐ ๋‹ค๋ฅธ ํด๋ผ์ด์–ธํŠธ๋Š” ํ•ญ์ƒ mongos ์ธ์Šคํ„ด์Šค์— ์—ฐ๊ฒฐํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. mongod ์ธ์Šคํ„ด์Šค์— ์ง์ ‘ ์—ฐ๊ฒฐํ•˜์ง€ ๋งˆ์„ธ์š”. ํด๋ผ์ด์–ธํŠธ๊ฐ€ ์ƒค๋“œ์— ์ง์ ‘ ์—ฐ๊ฒฐํ•˜๋Š” ๊ฒฝ์šฐ ๋ฐ์ดํ„ฐ ๋˜๋Š” ๋ฉ”ํƒ€๋ฐ์ดํ„ฐ ๋ถˆ์ผ์น˜๊ฐ€ ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

9

ํด๋Ÿฌ์Šคํ„ฐ์— ์ฒซ ๋ฒˆ์งธ ์ƒค๋“œ๋ฅผ ์ถ”๊ฐ€ํ•œ ํ›„, ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์—์„œ ์‚ฌ์šฉํ•˜๋Š” ์—ฐ๊ฒฐ ๋ฌธ์ž์—ด์„ ์ƒค๋”ฉ๋œ ํด๋Ÿฌ์Šคํ„ฐ์˜ ์—ฐ๊ฒฐ ๋ฌธ์ž์—ด๋กœ ์—…๋ฐ์ดํŠธํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋Ÿฐ ๋‹ค์Œ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ๋‹ค์‹œ ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค.

10

rs1์ด๋ผ๋Š” ์ƒˆ ๋ณต์ œ๋ณธ ์„ธํŠธ๋ฅผ ๋ฐฐํฌํ•ฉ๋‹ˆ๋‹ค. ๋ณต์ œ๋ณธ ์„ธํŠธ rs1์˜ ๋ฉค๋ฒ„๊ฐ€ ๋‹ค์Œ ํ˜ธ์ŠคํŠธ์— ์žˆ์Šต๋‹ˆ๋‹ค.

  • mongodb3.example.net

  • mongodb4.example.net

  • mongodb5.example.net

  1. ๋ณต์ œ๋ณธ ์„ธํŠธ์˜ ๊ฐ ๋ฉค๋ฒ„๋ฅผ ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค.

    ๋ณต์ œ๋ณธ ์„ธํŠธ์˜ ๊ฐ mongod ์ธ์Šคํ„ด์Šค์— ๋Œ€ํ•ด ๋‹ค์Œ ์˜ต์…˜์„ ์‚ฌ์šฉํ•˜์—ฌ ๊ตฌ์„ฑ ํŒŒ์ผ์„ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

    ์˜ต์…˜
    ๊ฐ’
    ์ดˆ๊ธฐ ๋ณต์ œ๋ณธ ์„ธํŠธ์— ์‚ฌ์šฉ๋˜๋Š” ํ‚ค ํŒŒ์ผ์˜ ๊ฒฝ๋กœ์ž…๋‹ˆ๋‹ค.
    rs1
    shardsvr
    localhost, ๊ทธ ๋’ค์— mongod๊ฐ€ ํด๋ผ์ด์–ธํŠธ ์—ฐ๊ฒฐ์„ ์ˆ˜์‹ ํ•ด์•ผ ํ•˜๋Š” ๋‹ค๋ฅธ ํ˜ธ์ŠคํŠธ ์ด๋ฆ„์„ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค.
    security:
    keyFile: <PATH_TO_KEYFILE>
    replication:
    replSetName: rs1
    sharding:
    clusterRole: shardsvr
    net:
    bindIp: localhost,<hostname(s)>

    ๋ฐฐํฌ์— ์ ํ•ฉํ•œ ์ถ”๊ฐ€ ์˜ต์…˜์„ ํฌํ•จํ•˜์„ธ์š”.

    ๊ฐ ๋ฉค๋ฒ„์— ๋Œ€ํ•ด ๋‹ค์Œ ์˜ต์…˜์„ ์‚ฌ์šฉํ•˜์—ฌ mongod๋ฅผ ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค.

    ์˜ต์…˜
    ๊ฐ’
    rs1
    shardsvr
    x509
    requireTLS
    TLS ์ธ์ฆ์„œ์™€ ํ‚ค๊ฐ€ ๋ชจ๋‘ ํฌํ•จ๋œ .pem ํŒŒ์ผ์˜ ์ ˆ๋Œ€ ๊ฒฝ๋กœ์ž…๋‹ˆ๋‹ค.
    ์ธ์ฆ ๊ธฐ๊ด€์˜ ๋ฃจํŠธ ์ธ์ฆ์„œ ์ฒด์ธ์ด ํฌํ•จ๋œ .pem ํŒŒ์ผ์˜ ์ ˆ๋Œ€ ๊ฒฝ๋กœ์ž…๋‹ˆ๋‹ค.
    localhost, ๊ทธ ๋’ค์— mongod๊ฐ€ ํด๋ผ์ด์–ธํŠธ ์—ฐ๊ฒฐ์„ ์ˆ˜์‹ ํ•ด์•ผ ํ•˜๋Š” ๋‹ค๋ฅธ ํ˜ธ์ŠคํŠธ ์ด๋ฆ„์„ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค.
    replication:
    replSetName: rs1
    sharding:
    clusterRole: shardsvr
    security:
    clusterAuthMode: x509
    net:
    tls:
    mode: requireTLS
    certificateKeyFile: <FILE_WITH_COMBINED_CERT_AND_KEY>
    CAFile: <CA_FILE>
    bindIp: localhost,<hostname(s)>

    ์ง€์ •๋œ ๊ตฌ์„ฑ์œผ๋กœ mongod๋ฅผ ๋ฐฐํฌํ•ฉ๋‹ˆ๋‹ค.

    mongod --config <PATH_TO_CONFIG_FILE>

    ์ฐธ๊ณ 

    mongod ์ธ์Šคํ„ด์Šค์— ๋Œ€ํ•ด --shardsvr ์˜ต์…˜์„ ์ง€์ •ํ•˜๋ฉด ์ธ์Šคํ„ด์Šค๋Š” ๊ธฐ๋ณธ์ ์œผ๋กœ ํฌํŠธ 27018์—์„œ ์‹คํ–‰๋ฉ๋‹ˆ๋‹ค.

  2. ๋ณต์ œ๋ณธ ์„ธํŠธ์˜ ๊ฐ ๋ฉค๋ฒ„๋ฅผ ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค.

  3. ๋ณต์ œ๋ณธ ์„ธํŠธ ๋ฉค๋ฒ„์— ์—ฐ๊ฒฐํ•ฉ๋‹ˆ๋‹ค.

    mongosh๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ณต์ œ๋ณธ ์„ธํŠธ ๋ฉค๋ฒ„ ์ค‘ ํ•˜๋‚˜์— ์—ฐ๊ฒฐํ•ฉ๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

    mongosh "mongodb://mongodb3.example.net:27018"
    mongosh "mongodb://mongodb3.example.net:27018" --tls --tlsCAFile <CA_FILE> --tlsCertificateKeyFile <filename>
  4. ๋ณต์ œ๋ณธ ์„ธํŠธ๋ฅผ ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค.

    mongosh์—์„œ rs.initiate() ๋ฉ”์„œ๋“œ๋ฅผ ์‹คํ–‰ํ•˜์—ฌ ํ˜„์žฌ ๋…ธ๋“œ๋ฅผ ํฌํ•จํ•˜๋Š” ๋ณต์ œ๋ณธ ์„ธํŠธ๋ฅผ ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค.

    rs.initiate( {
    _id : "rs1",
    members: [
    { _id: 0, host: "mongodb3.example.net:27018" },
    { _id: 1, host: "mongodb4.example.net:27018" },
    { _id: 2, host: "mongodb5.example.net:27018" }
    ]
    } )

    ์•ž์˜ ์กฐ์น˜๋Š” ๋กœ์ปฌ ํ˜ธ์ŠคํŠธ ์˜ˆ์™ธ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ธ์ฆ ์—†์ด ๊ด€๋ฆฌ ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•ฉ๋‹ˆ๋‹ค.

    ์ค‘์š”

    ๋ณต์ œ๋ณธ ์„ธํŠธ์— ๋Œ€ํ•ด ๋‹จ mongod rs.initiate() ํ•˜๋‚˜์˜ ์ธ์Šคํ„ด์Šค์—์„œ๋งŒ ๋ฅผ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.

  5. ๋ณต์ œ๋ณธ ์„ธํŠธ์— ๋Œ€ํ•œ ๊ด€๋ฆฌ ์‚ฌ์šฉ์ž๋ฅผ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค.

    ๋ณต์ œ๋ณธ ์„ธํŠธ๋ฅผ ๋ฐฐํฌํ•œ ํ›„ ๋กœ์ปฌ ํ˜ธ์ŠคํŠธ ์˜ˆ์™ธ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ณต์ œ๋ณธ ์„ธํŠธ์˜ ์ฒซ ๋ฒˆ์งธ ์‚ฌ์šฉ์ž๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

    1. ๋ณต์ œ๋ณธ ์„ธํŠธ์˜ ํ”„๋ผ์ด๋จธ๋ฆฌ๋ฅผ ๊ฒฐ์ •ํ•ฉ๋‹ˆ๋‹ค.

      ํ”„๋ผ์ด๋จธ๋ฆฌ๋ฅผ ๊ฒฐ์ •ํ•˜๋ ค๋ฉด rs.status()๋ฅผ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.

      rs.status()

      ๋ช…๋ น ์ถœ๋ ฅ์—์„œ replSetGetStatus.members[n].stateStr ํ•„๋“œ๋Š” ์–ด๋–ค ๋ฉค๋ฒ„๊ฐ€ ํ”„๋ผ์ด๋จธ๋ฆฌ์ธ์ง€ ๋‚˜ํƒ€๋ƒ…๋‹ˆ๋‹ค.

    2. ๋ณต์ œ๋ณธ ์„ธํŠธ ํ”„๋ผ์ด๋จธ๋ฆฌ์— ์—ฐ๊ฒฐํ•ฉ๋‹ˆ๋‹ค.

      mongosh๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ณต์ œ๋ณธ ์„ธํŠธ ํ”„๋ผ์ด๋จธ๋ฆฌ์— ์—ฐ๊ฒฐํ•ฉ๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด ํ”„๋ผ์ด๋จธ๋ฆฌ๊ฐ€ mongodb4.example.net์ธ ๊ฒฝ์šฐ ์ด ๋ช…๋ น์„ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.

      mongosh "mongodb://mongodb4.example.net:27018"
    3. ๊ด€๋ฆฌ ์‚ฌ์šฉ์ž๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

      ๋‹ค์Œ db.createUser() ๋ฉ”์„œ๋“œ๋ฅผ ์‹คํ–‰ํ•˜์—ฌ userAdmin ์—ญํ• ์„ ๊ฐ€์ง„ rs1Admin์ด๋ผ๋Š” ์‚ฌ์šฉ์ž๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

      use admin
      db.createUser(
      {
      user: "rs1Admin",
      pwd: passwordPrompt(),
      roles: [
      { role: "userAdmin", db: "admin" }
      ]
      }
      )

      ๋ช…๋ น์„ ์‹คํ–‰ํ•˜๋ฉด rs1Admin ์‚ฌ์šฉ์ž์˜ ์•”ํ˜ธ๋ฅผ ์ž…๋ ฅํ•˜๋ผ๋Š” ๋ฉ”์‹œ์ง€๊ฐ€ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ํ‘œ์‹œ๋ฉ๋‹ˆ๋‹ค.

11

์ƒˆ ๋ณต์ œ๋ณธ ์„ธํŠธ rs1์„ ์ƒค๋”ฉ๋œ ํด๋Ÿฌ์Šคํ„ฐ์— ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค.

  1. mongosh์„ mongos์— ์—ฐ๊ฒฐํ•ฉ๋‹ˆ๋‹ค.

    ๋ช…๋ น์ค„์—์„œ ๋‹ค์Œ ๋ช…๋ น์„ ์‹คํ–‰ํ•˜์—ฌ ํ˜ธ์ŠคํŠธ mongodb6.example.net์—์„œ ์‹คํ–‰ ์ค‘์ธ mongos ์ธ์Šคํ„ด์Šค์— ์—ฐ๊ฒฐํ•ฉ๋‹ˆ๋‹ค.

    mongosh "mongodb://admin01@mongodb6.example.net:27017/admin"
    mongosh "mongodb://admin01@mongodb6.example.net:27017/admin" --tls --tlsCAFile <CA_FILE> --tlsCertificateKeyFile <filename>

    ์ด ๋ช…๋ น์€ ์ƒค๋”ฉ๋œ ํด๋Ÿฌ์Šคํ„ฐ์—์„œ ์ƒ์„ฑํ•œ admin01 ์‚ฌ์šฉ์ž๋กœ ์ธ์ฆํ•ฉ๋‹ˆ๋‹ค. ๋ช…๋ น์„ ์ž…๋ ฅํ•œ ํ›„ ์‚ฌ์šฉ์ž ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ฉ๋‹ˆ๋‹ค.

  2. ๋‘ ๋ฒˆ์งธ ์ƒค๋“œ๋ฅผ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค.

    mongos์— ์—ฐ๊ฒฐํ•œ ํ›„, sh.addShard() ๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํด๋Ÿฌ์Šคํ„ฐ์— ๋ณต์ œ๋ณธ ์„ธํŠธ rs1์„ ์ƒค๋“œ๋กœ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค.

    sh.addShard( "rs1/mongodb3.example.net:27018,mongodb4.example.net:27018,mongodb5.example.net:27018" )
12

์ ˆ์ฐจ์˜ ๋งˆ์ง€๋ง‰ ๋‹จ๊ณ„๋Š” ์ƒค๋”ฉ๋œ ํด๋Ÿฌ์Šคํ„ฐ์—์„œ ์ปฌ๋ ‰์…˜์„ ์ƒค๋”ฉํ•˜๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค.

  1. ์ƒค๋“œ ํ‚ค๋ฅผ ๊ฒฐ์ •ํ•ฉ๋‹ˆ๋‹ค.

    ์ปฌ๋ ‰์…˜์˜ ์ƒค๋“œ ํ‚ค๋ฅผ ๊ฒฐ์ •ํ•ฉ๋‹ˆ๋‹ค. ์ƒค๋“œ ํ‚ค๋Š” MongoDB๊ฐ€ ์ƒค๋“œ ๊ฐ„์— ๋ฌธ์„œ๋ฅผ ๋ฐฐํฌํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ๋‚˜ํƒ€๋ƒ…๋‹ˆ๋‹ค. ์ ์ ˆํ•œ ์ƒค๋“œ ํ‚ค๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

    • ๋ชจ๋“  ๋ฌธ์„œ์— ๊ท ๋“ฑํ•˜๊ฒŒ ๋ถ„์‚ฐ๋œ ๊ฐ’์ด ์žˆ์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

    • ๋™์‹œ์— ์ž์ฃผ ์•ก์„ธ์Šค๋˜๋Š” ๋ฌธ์„œ๋ฅผ ์—ฐ์†๋œ ์ฒญํฌ๋กœ ๊ทธ๋ฃนํ™”ํ•ฉ๋‹ˆ๋‹ค.

    • ์ƒค๋“œ ๊ฐ„์— ํ™œ๋™์„ ํšจ๊ณผ์ ์œผ๋กœ ๋ถ„์‚ฐํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

    ์ž์„ธํ•œ ๋‚ด์šฉ์€ ์ƒค๋“œ ํ‚ค ์„ ํƒ์„ ์ฐธ์กฐํ•˜์„ธ์š”.

    ์ด ์ ˆ์ฐจ์—์„œ๋Š” number ํ•„๋“œ๋ฅผ test_collection ์ปฌ๋ ‰์…˜์˜ ์ƒค๋“œ ํ‚ค๋กœ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

  2. ์ƒค๋“œ ํ‚ค์— ์ธ๋ฑ์Šค๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

    ๋น„์–ด ์žˆ์ง€ ์•Š์€ ์ปฌ๋ ‰์…˜์„ ์ƒค๋”ฉํ•˜๊ธฐ ์ „์— ์ƒค๋“œ ํ‚ค์— ์ธ๋ฑ์Šค๋ฅผ ์ƒ์„ฑํ•˜์„ธ์š”.

    use test
    db.test_collection.createIndex( { "number" : 1 } )
  3. ์ปฌ๋ ‰์…˜์„ ์ƒค๋”ฉํ•ฉ๋‹ˆ๋‹ค.

    test ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์—์„œ test_collection์„ ์ƒค๋”ฉํ•ฉ๋‹ˆ๋‹ค number๋ฅผ ์ƒค๋“œ ํ‚ค๋กœ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค.

    sh.shardCollection( "test.test_collection", { "number" : 1 } )

    ๋‹ค์Œ์— ๋ฐธ๋Ÿฐ์„œ๊ฐ€ ์‹คํ–‰๋  ๋•Œ ์ƒค๋“œ ๊ฐ„์— ๋ฌธ์„œ ์ฒญํฌ๋ฅผ ์žฌ๋ฐฐ๋ถ„ํ•ฉ๋‹ˆ๋‹ค. ํด๋ผ์ด์–ธํŠธ๊ฐ€ ์ด ์ปฌ๋ ‰์…˜์— ์ถ”๊ฐ€ ๋ฌธ์„œ๋ฅผ ์‚ฝ์ž…ํ•˜๋ฉด mongos๋Š” ํ•ด๋‹น ๋ฌธ์„œ๋ฅผ ์ ์ ˆํ•œ ์ƒค๋“œ๋กœ ๋ผ์šฐํŒ…ํ•ฉ๋‹ˆ๋‹ค.

    ๋ฐธ๋Ÿฐ์„œ๊ฐ€ ์ฒญํฌ๋ฅผ ์žฌ๋ถ„๋ฐฐํ•˜๋ฉด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์„ฑ๋Šฅ์— ๋ถ€์ •์ ์ธ ์˜ํ–ฅ์„ ๋ฏธ์น  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์„ฑ๋Šฅ์— ๋ฏธ์น˜๋Š” ์˜ํ–ฅ์„ ์ตœ์†Œํ™”ํ•˜๊ธฐ ์œ„ํ•ด ๋ฐธ๋Ÿฐ์„œ ์‹คํ–‰ ์‹œ๊ธฐ๋ฅผ ์ง€์ •ํ•˜์—ฌ ์‚ฌ์šฉ๋Ÿ‰์ด ๋งŽ์€ ์‹œ๊ฐ„์—๋Š” ์‹คํ–‰๋˜์ง€ ์•Š๋„๋ก ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ž์„ธํžˆ ์•Œ์•„๋ณด๋ ค๋ฉด ๋ฐธ๋Ÿฐ์‹ฑ ๊ธฐ๊ฐ„ ์˜ˆ์•ฝ์„ ์ฐธ์กฐํ•˜์„ธ์š”.

์ƒค๋”ฉ ํŠœํ† ๋ฆฌ์–ผ๊ณผ ์ ˆ์ฐจ์— ๋Œ€ํ•œ ์ž์„ธํ•œ ๋‚ด์šฉ์€ ์ด ํŽ˜์ด์ง€๋ฅผ ์ฐธ์กฐํ•˜์„ธ์š”.

๋Œ์•„๊ฐ€๊ธฐ

์ƒค๋”ฉ๋œ ํด๋Ÿฌ์Šคํ„ฐ๋ฅผ ๋ณต์ œ๋ณธ ์„ธํŠธ๋กœ ๋ณ€ํ™˜