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

.tgz tarball์„ ์‚ฌ์šฉํ•˜์—ฌ Red Hat ๋˜๋Š” CentOS์— MongoDB Community๋ฅผ ์„ค์น˜ํ•ฉ๋‹ˆ๋‹ค.

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

  • ๊ฐœ์š”
  • ๊ณ ๋ ค ์‚ฌํ•ญ
  • MongoDB Community Edition ์„ค์น˜
  • MongoDB Community Edition ์‹คํ–‰
  • ์ถ”๊ฐ€ ์ •๋ณด

์ด ํŠœํ† ๋ฆฌ์–ผ์„ ์‚ฌ์šฉํ•˜์—ฌ MongoDB 8.0 ์„ ์ˆ˜๋™์œผ๋กœ ์„ค์น˜ํ•ฉ๋‹ˆ๋‹ค. MongoDB Community Edition Red Hat Enterprise Linux, CentOS Linux ๋˜๋Š” Oracle Linux [1] ์—์„œ ์„ ์‹คํ–‰ํ•˜๋ ค๋ฉด ๋‹ค์šด๋กœ๋“œํ•œ .tgz tarball์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

์ด ํŠœํ† ๋ฆฌ์–ผ์—์„œ๋Š” MongoDB 8.0 ๋ฅผ ์„ค์น˜ํ•ฉ๋‹ˆ๋‹ค. Community Edition. ๋‹ค๋ฅธ ๋ฒ„์ „์˜ MongoDB Community๋ฅผ ์„ค์น˜ํ•˜๋ ค๋ฉด ํŽ˜์ด์ง€ ์™ผ์ชฝ ์ƒ๋‹จ์˜ ๋ฒ„์ „ ๋“œ๋กญ๋‹ค์šด ๋ฉ”๋‰ด์—์„œ ํ•ด๋‹น ๋ฒ„์ „์— ๋Œ€ํ•œ ๋ฌธ์„œ๋ฅผ ์„ ํƒํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์ด ๋ฌธ์„œ์˜ ์„ค๋ช…๋Œ€๋กœ ๋‹ค์šด๋กœ๋“œํ•œ .tgz tarball์„ ํ†ตํ•ด MongoDB๋ฅผ ์ˆ˜๋™์œผ๋กœ ์„ค์น˜ํ•  ์ˆ˜ ์žˆ์ง€๋งŒ ๊ฐ€๋Šฅํ•˜๋ฉด ์‹œ์Šคํ…œ์˜ yum ํŒจํ‚ค์ง€ ๊ด€๋ฆฌ์ž๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ MongoDB๋ฅผ ์„ค์น˜ํ•˜๋Š” ๊ฒƒ์ด ์ข‹์Šต๋‹ˆ๋‹ค. ํŒจํ‚ค์ง€ ๊ด€๋ฆฌ์ž๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ํ•„์š”ํ•œ ๋ชจ๋“  ์ข…์† ํ”„๋กœ๊ทธ๋žจ์ด ์ž๋™์œผ๋กœ ์„ค์น˜๋˜๊ณ , ์‹œ์ž‘์— ๋„์›€์ด ๋˜๋Š” ์˜ˆ์‹œ mongod.conf ํŒŒ์ผ์ด ์ œ๊ณต๋˜๋ฉฐ, ํ–ฅํ›„ ์—…๊ทธ๋ ˆ์ด๋“œ ๋ฐ ์œ ์ง€ ๊ด€๋ฆฌ ์ž‘์—…์ด ๊ฐ„์†Œํ™”๋ฉ๋‹ˆ๋‹ค.

์ž์„ธํ•œ ๋‚ด์šฉ์€ yum ํŒจํ‚ค์ง€ ๊ด€๋ฆฌ์ž ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ MongoDB ์„ค์น˜ ๋ฅผ ์ฐธ์กฐํ•˜์„ธ์š”.

.tgz ํŒจํ‚ค์ง€๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์„œ๋ฒ„๋ฅผ ์„ค์น˜ํ•˜๋Š” ๊ฒฝ์šฐ mongosh ์„ค์น˜ ์ง€์นจ์— ๋”ฐ๋ผ mongosh๋ฅผ ๋ณ„๋„๋กœ ๋‹ค์šด๋กœ๋“œํ•˜์—ฌ ์„ค์น˜ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

MongoDB 8.0 MongoDB Community Edition 64 LinuxCentOS LinuxOracle Linux 1์€ Linux x86์—์„œ Red Hat64 Enterprise (RHEL), , [ ] , Rocky ๋ฐ AlmaLinux [2] ์˜ ๋น„ํŠธ ๋ฒ„์ „์„ ์ง€์›ํ•ฉ๋‹ˆ๋‹ค. _ ์•„ํ‚คํ…์ฒ˜:

  • RHEL / CentOS Stream / Oracle / Rocky / AlmaLinux 9

  • RHEL / CentOS Stream / Oracle / Rocky / AlmaLinux 8

MongoDB๋Š” ์ด๋Ÿฌํ•œ ํ”Œ๋žซํผ์˜ 64๋น„ํŠธ ๋ฒ„์ „๋งŒ ์ง€์›ํ•ฉ๋‹ˆ๋‹ค.

RHEL/CentOS/Oracle/Rocky/AlmaLinux์˜ MongoDB 8.0 Community Edition์€ ์ผ๋ถ€ ํ”Œ๋žซํผ์—์„œ ARM64 ์•„ํ‚คํ…์ฒ˜๋„ ์ง€์›ํ•ฉ๋‹ˆ๋‹ค.

์ž์„ธํ•œ ์ •๋ณด๋Š” ํ”Œ๋žซํผ ์ง€์›์—์„œ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

[1](1, 2) MongoDB๋Š” Red Hat ํ˜ธํ™˜ ์ปค๋„(RHCK)์„ ์‹คํ–‰ํ•˜๋Š” Oracle Linux๋งŒ ์ง€์›ํ•ฉ๋‹ˆ๋‹ค. MongoDB๋Š” UEK(Unbreakable Enterprise Kernel)๋ฅผ ์ง€์›ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค .
[2] RHEL ๋ฒ„์ „ 8.0 ์ด์ƒ์„ ์ง€์›ํ•˜๋„๋ก ์ถœ์‹œ๋œ MongoDB ์˜จํ”„๋ ˆ๋ฏธ์Šค ์ œํ’ˆ์€ ํ•ด๋‹น ๋ฐฐํฌํŒ์ด ์™„์ „ํ•œ RHEL ํ˜ธํ™˜์„ฑ์„ ์ œ๊ณตํ•  ์˜๋ฌด๋ฅผ ์ถฉ์กฑํ•˜๋Š” ๊ฒฝ์šฐ Rocky Linux ๋ฒ„์ „ 8.0 ์ด์ƒ๊ณผ AlmaLinux ๋ฒ„์ „ 8.0 ์ด์ƒ์„ ํ˜ธํ™˜ ๋ฐ ์ง€์›ํ•ฉ๋‹ˆ๋‹ค.

ํ”„๋กœ๋•์…˜ MongoDB ๋ฐฐํฌ์— ๋Œ€ํ•œ ์„ฑ๋Šฅ ๊ณ ๋ ค ์‚ฌํ•ญ ๋ฐ ๊ตฌ์„ฑ ๊ถŒ์žฅ ์‚ฌํ•ญ์„ ์ œ๊ณตํ•˜๋Š” ์ž์ฒด ๊ด€๋ฆฌํ˜• ๋ฐฐํฌ๋ฅผ ์œ„ํ•œ ํ”„๋กœ๋•์…˜ ๋…ธํŠธ ๋ฌธ์„œ๋ฅผ ๊ฒ€ํ† ํ•œ ์ดํ›„์— ํ”„๋กœ๋•์…˜ ํ™˜๊ฒฝ์— MongoDB๋ฅผ ๋ฐฐํฌํ•ฉ๋‹ˆ๋‹ค.

์•„๋ž˜ ๋ช…๋ น์„ ์‚ฌ์šฉํ•˜์—ฌ MongoDB Community .tgz tarball์— ํ•„์š”ํ•œ ์ข…์†์„ฑ์„ ์„ค์น˜ํ•ฉ๋‹ˆ๋‹ค.

sudo yum install libcurl openssl xz-libs

๋‹ค์Œ ๋‹จ๊ณ„์— ๋”ฐ๋ผ .tgz์—์„œ MongoDB Community Edition์„ ์ˆ˜๋™์œผ๋กœ ์„ค์น˜ํ•ฉ๋‹ˆ๋‹ค.

1

ํ•„์ˆ˜ ์‚ฌ์ „ ํŒจํ‚ค์ง€๋ฅผ ์„ค์น˜ํ•œ ํ›„ ๋‹ค์Œ ๋งํฌ์—์„œ MongoDB Community tgz tarball์„ ๋‹ค์šด๋กœ๋“œํ•ฉ๋‹ˆ๋‹ค.

โžค MongoDB ๋‹ค์šด๋กœ๋“œ ์„ผํ„ฐ

  1. Version ๋“œ๋กญ๋‹ค์šด ๋ฉ”๋‰ด์—์„œ ๋‹ค์šด๋กœ๋“œํ•˜๋ ค๋Š” MongoDB ๋ฒ„์ „์„ ์„ ํƒํ•ฉ๋‹ˆ๋‹ค.

  2. Platform ๋“œ๋กญ๋‹ค์šด ๋ฉ”๋‰ด์—์„œ ์šด์˜ ์ฒด์ œ ๋ฒ„์ „ ๋ฐ ์•„ํ‚คํ…์ฒ˜๋ฅผ ์„ ํƒํ•ฉ๋‹ˆ๋‹ค.

  3. Package ๋“œ๋กญ๋‹ค์šด ๋ฉ”๋‰ด์—์„œ tgz๋ฅผ ์„ ํƒํ•ฉ๋‹ˆ๋‹ค.

  4. Download๋ฅผ ํด๋ฆญํ•ฉ๋‹ˆ๋‹ค.

2

์˜ˆ๋ฅผ ๋“ค์–ด ์‹œ์Šคํ…œ ์…ธ์—์„œ tar ๋ช…๋ น์–ด์„ ์‚ฌ์šฉํ•˜์—ฌ ์ถ”์ถœํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

tar -zxvf mongodb-linux-*-8.0.0.tgz
3

MongoDB ๋ฐ”์ด๋„ˆ๋ฆฌ๋Š” tarball์˜ bin/ ๋””๋ ‰ํ„ฐ๋ฆฌ์— ์žˆ์Šต๋‹ˆ๋‹ค. ๋‹ค์Œ ๋ฐฉ๋ฒ• ์ค‘ ํ•˜๋‚˜๋ฅผ ์„ ํƒํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

  • ๋ฐ”์ด๋„ˆ๋ฆฌ๋ฅผ PATH ๋ณ€์ˆ˜์— ๋‚˜์—ด๋œ ๋””๋ ‰ํ† ๋ฆฌ(์˜ˆ: /usr/local/bin ์— ๋ณต์‚ฌํ•ฉ๋‹ˆ๋‹ค (์ ์ ˆํ•œ ์„ค์น˜ ๋””๋ ‰ํ† ๋ฆฌ๋กœ /path/to/the/mongodb-directory/๋ฅผ ์—…๋ฐ์ดํŠธํ•˜์„ธ์š”).

    sudo cp /path/to/the/mongodb-directory/bin/* /usr/local/bin/
  • PATH ๋ณ€์ˆ˜์— ๋‚˜์—ด๋œ ๋””๋ ‰ํ† ๋ฆฌ (์˜ˆ: /usr/local/bin)์—์„œ ๋ฐ”์ด๋„ˆ๋ฆฌ์— ๋Œ€ํ•œ ์‹ฌ๋ณผ๋ฆญ ๋งํฌ๋ฅผ ๋งŒ๋“ญ๋‹ˆ๋‹ค (์ ์ ˆํ•œ ์„ค์น˜ ๋””๋ ‰ํ„ฐ๋ฆฌ๋กœ /path/to/the/mongodb-directory/๋ฅผ ์—…๋ฐ์ดํŠธํ•˜์„ธ์š”).

    sudo ln -s /path/to/the/mongodb-directory/bin/* /usr/local/bin/
4

์„ค์น˜ mongosh ๊ทธ ๋‹ค์Œ MongoDB Shell์„ ์‚ฌ์šฉํ•˜์—ฌ ๋ฐฐํฌ์„œ๋ฒ„์— ์—ฐ๊ฒฐํ•ฉ๋‹ˆ๋‹ค.

MongoDB ๋‹ค์šด๋กœ๋“œ ์„ผํ„ฐ์—์„œ ํ•„์š”ํ•œ mongosh ๋ฒ„์ „ ํŒจํ‚ค์ง€๋ฅผ ๋‹ค์šด๋กœ๋“œํ•˜๊ณ  ์••์ถ•์„ ํ•ด์ œํ•ฉ๋‹ˆ๋‹ค.

๋Œ€๋ถ€๋ถ„์˜ Unix ๊ณ„์—ด ์šด์˜ ์ฒด์ œ๋Š” ํ”„๋กœ์„ธ์Šค ๊ฐ€ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ์‹œ์Šคํ…œ ๋ฆฌ์†Œ์Šค๋ฅผ ์ œํ•œํ•ฉ๋‹ˆ๋‹ค. ์ด๋Ÿฌํ•œ ์ œํ•œ์€ MongoDB ์ž‘์—…์— ๋ถ€์ •์ ์ธ ์˜ํ–ฅ ์ˆ˜ ์žˆ์œผ๋ฏ€๋กœ ์กฐ์ •ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ํ”Œ๋žซํผ์— ๊ถŒ์žฅ ๋˜๋Š” ์„ค์ •์€ ์ž์ฒด ๊ด€๋ฆฌ ๋ฐฐํฌ์„œ๋ฒ„๋ฅผ ์œ„ํ•œ UNIX ulimit ์„ค์ •์„ ์ฐธ์กฐํ•˜์„ธ์š”.

์ฐธ๊ณ 

์—ด๋ ค ์žˆ๋Š” ํŒŒ์ผ ์ˆ˜์˜ ulimit ๊ฐ’์ด 64000 ๋ฏธ๋งŒ์ธ ๊ฒฝ์šฐ MongoDB๊ฐ€ ์‹œ์ž‘ ๊ฒฝ๊ณ ๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

๊ธฐ๋ณธ์ ์œผ๋กœ MongoDB๋Š” mongod ์‚ฌ์šฉ์ž ๊ณ„์ •์„ ์‚ฌ์šฉํ•˜์—ฌ ์‹คํ–‰๋˜๋ฉฐ ๋‹ค์Œ ๊ธฐ๋ณธ ๋””๋ ‰ํ† ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

  • /var/lib/mongo (๋ฐ์ดํ„ฐ ๋””๋ ‰ํ† ๋ฆฌ)

  • /var/log/mongodb (๋กœ๊ทธ ๋””๋ ‰ํ† ๋ฆฌ)

MongoDB ๋ฐ์ดํ„ฐ ๋ฐ ๋กœ๊ทธ ๋””๋ ‰ํ† ๋ฆฌ๋ฅผ ๋งŒ๋“ญ๋‹ˆ๋‹ค:

sudo mkdir -p /var/lib/mongo
sudo mkdir -p /var/log/mongodb

๊ธฐ๋ณธ์ ์œผ๋กœ MongoDB๋Š” mongod ์‚ฌ์šฉ์ž ๊ณ„์ •์„ ์‚ฌ์šฉํ•˜์—ฌ ์‹คํ–‰๋ฉ๋‹ˆ๋‹ค. mongod์™€ mongodb ๊ทธ๋ฃน์„ ์ƒ์„ฑํ•˜์„ธ์š”.mongod์ด ๊ทธ๋ฃน์— ์†ํ•˜๋Š”์ง€ ํ™•์ธํ•œ ๋‹ค์Œ ์ด๋Ÿฌํ•œ ๋””๋ ‰ํ† ๋ฆฌ์˜ ์†Œ์œ ์ž ๋ฐ ๊ทธ๋ฃน์„ mongod๋กœ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค.

sudo chown -R mongod:mongod /var/lib/mongo
sudo chown -R mongod:mongod /var/log/mongodb

๊ธฐ๋ณธ ๋””๋ ‰ํ† ๋ฆฌ ์ด์™ธ์˜ ๋ฐ์ดํ„ฐ ๋””๋ ‰ํ† ๋ฆฌ ๋ฐ ๋กœ๊ทธ ๋””๋ ‰ํ† ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•˜๋ ค๋ฉด ๋‹ค์Œ์„ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.

  1. ์ƒˆ ๋””๋ ‰ํ† ๋ฆฌ๋ฅผ ํ•˜๋‚˜ ์ด์ƒ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

  2. ๊ตฌ์„ฑ ํŒŒ์ผ /etc/mongod.conf๋ฅผ ํŽธ์ง‘ํ•˜๊ณ  ๊ทธ์— ๋”ฐ๋ผ ๋‹ค์Œ ํ•„๋“œ๋ฅผ ์ˆ˜์ •ํ•ฉ๋‹ˆ๋‹ค.

    • storage.dbPath๋กœ ์ƒˆ๋กœ์šด ๋ฐ์ดํ„ฐ ๋””๋ ‰ํ† ๋ฆฌ ๊ฒฝ๋กœ ์ง€์ •(์˜ˆ: /some/data/directory)

    • systemLog.path๋กœ ์ƒˆ๋กœ์šด ๋กœ๊ทธ ํŒŒ์ผ ๊ฒฝ๋กœ ์ง€์ •(์˜ˆ: /some/log/directory/mongod.log)

  3. MongoDB๋ฅผ ์‹คํ–‰ํ•˜๋Š” ์‚ฌ์šฉ์ž๊ฐ€ ๋””๋ ‰ํ† ๋ฆฌ์— ์•ก์„ธ์Šคํ•  ์ˆ˜ ์žˆ๋Š”์ง€ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.

    sudo chown -R mongod:mongod <directory>

    MongoDB ํ”„๋กœ์„ธ์Šค๋ฅผ ์‹คํ–‰ํ•˜๋Š” ์‚ฌ์šฉ์ž๋ฅผ ๋ณ€๊ฒฝํ•˜๋ ค๋ฉด ์ƒˆ๋กœ์šด ์‚ฌ์šฉ์ž์—๊ฒŒ ๋””๋ ‰ํ† ๋ฆฌ ์•ก์„ธ์Šค ๊ถŒํ•œ์„ ๋ถ€์—ฌํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

  4. SELinux๊ฐ€ ์ ์šฉ๋˜์–ด ์žˆ๋‹ค๋ฉด, SELinux๋ฅผ ๊ตฌ์„ฑํ•˜์„ธ์š”. ์ž์„ธํ•œ ๋‚ด์šฉ์€ SELinux ๊ตฌ์„ฑ์„ ์ฐธ์กฐํ•˜์„ธ์š”.

๊ฒฝ๊ณ 

๋ถ€์ ์ ˆํ•˜๊ฒŒ ๊ตฌ์„ฑ๋œ SELinux ์ •์ฑ…์€ ์•ˆ์ „ํ•˜์ง€ ์•Š๊ฑฐ๋‚˜ mongod ์ธ์Šคํ„ด์Šค์˜ ์ž‘๋™์„ ์ค‘์ง€์‹œํ‚ฌ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

SELinux๊ฐ€ enforcing ๋ชจ๋“œ์ธ ๊ฒฝ์šฐ MongoDB์— ๋Œ€ํ•œ SELinux ์ •์ฑ…์„ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์‚ฌ์šฉ์ž ์ง€์ •ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

  • ๋‹ค์Œ์— ๋Œ€ํ•œ ์•ก์„ธ์Šค ํ—ˆ์šฉ cgroup

  • ๋‹ค์Œ์— ๋Œ€ํ•œ ์•ก์„ธ์Šค ํ—ˆ์šฉ netstat

ํ˜„์žฌ SELinux ์ •์ฑ…์€ MongoDB ํ”„๋กœ์„ธ์Šค๊ฐ€ ์‹œ์Šคํ…œ์—์„œ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ๊ฒฐ์ •ํ•˜๋Š” ๋ฐ ํ•„์š”ํ•œ /sys/fs/cgroup์— ์ ‘๊ทผํ•˜๋Š” ๊ฒƒ์„ ํ—ˆ์šฉํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.enforcing ๋ชจ๋“œ์—์„œ SELinux๋ฅผ ์‹คํ–‰ํ•˜๋ ค๋ฉด SELinux ์ •์ฑ…์„ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์กฐ์ •ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

  1. ์‹œ์Šคํ…œ์— checkpolicy ํŒจํ‚ค์ง€๊ฐ€ ์„ค์น˜๋˜์–ด ์žˆ๋Š”์ง€ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค:

    sudo yum install checkpolicy
  2. ์‚ฌ์šฉ์ž ์ง€์ • ์ •์ฑ… ํŒŒ์ผ mongodb_cgroup_memory.te์„ ๋งŒ๋“ญ๋‹ˆ๋‹ค.

    cat > mongodb_cgroup_memory.te <<EOF
    module mongodb_cgroup_memory 1.0;
    require {
    type cgroup_t;
    type mongod_t;
    class dir search;
    class file { getattr open read };
    }
    #============= mongod_t ==============
    allow mongod_t cgroup_t:dir search;
    allow mongod_t cgroup_t:file { getattr open read };
    EOF
  3. ์ƒ์„ฑ๋˜๋ฉด ๋‹ค์Œ ์„ธ ๊ฐ€์ง€ ๋ช…๋ น์„ ์‹คํ–‰ํ•˜์—ฌ ์‚ฌ์šฉ์ž ์ง€์ • ์ •์ฑ… ๋ชจ๋“ˆ์„ ์ปดํŒŒ์ผํ•˜๊ณ  ๋กœ๋“œํ•ฉ๋‹ˆ๋‹ค.

    checkmodule -M -m -o mongodb_cgroup_memory.mod mongodb_cgroup_memory.te
    semodule_package -o mongodb_cgroup_memory.pp -m mongodb_cgroup_memory.mod
    sudo semodule -i mongodb_cgroup_memory.pp

์ด์ œ SELinux๋ฅผ enforcing ๋กœ ์„ค์ •ํ•˜์—ฌ MongoDB ํ”„๋กœ์„ธ์Šค๊ฐ€ ์˜ฌ๋ฐ”๋ฅธ ํŒŒ์ผ์— ์•ก์„ธ์Šคํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

ํ˜„์žฌ SELinux ์ •์ฑ…์€ MongoDB ํ”„๋กœ์„ธ์Šค๊ฐ€ FTDC (ํ’€ํƒ€์ž„ ์ง„๋‹จ ๋ฐ์ดํ„ฐ ์บก์ฒ˜)์— ํ•„์š”ํ•œ /proc/net/netstat์„ ์—ด๊ณ  ์ฝ๋Š” ๊ฒƒ์„ ํ—ˆ์šฉํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.enforcing ๋ชจ๋“œ์—์„œ SELinux๋ฅผ ์‹คํ–‰ํ•˜๋ ค๋ฉด SELinux ์ •์ฑ…์„ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์กฐ์ •ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

  1. ์‹œ์Šคํ…œ์— checkpolicy ํŒจํ‚ค์ง€๊ฐ€ ์„ค์น˜๋˜์–ด ์žˆ๋Š”์ง€ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค:

    sudo yum install checkpolicy
  2. ์‚ฌ์šฉ์ž ์ง€์ • ์ •์ฑ… ํŒŒ์ผ mongodb_proc_net.te์„ ๋งŒ๋“ญ๋‹ˆ๋‹ค.

    cat > mongodb_proc_net.te <<EOF
    module mongodb_proc_net 1.0;
    require {
    type cgroup_t;
    type configfs_t;
    type file_type;
    type mongod_t;
    type proc_net_t;
    type sysctl_fs_t;
    type var_lib_nfs_t;
    class dir { search getattr };
    class file { getattr open read };
    }
    #============= mongod_t ==============
    allow mongod_t cgroup_t:dir { search getattr } ;
    allow mongod_t cgroup_t:file { getattr open read };
    allow mongod_t configfs_t:dir getattr;
    allow mongod_t file_type:dir { getattr search };
    allow mongod_t file_type:file getattr;
    allow mongod_t proc_net_t:file { open read };
    allow mongod_t sysctl_fs_t:dir search;
    allow mongod_t var_lib_nfs_t:dir search;
    EOF
  3. ์ƒ์„ฑ๋˜๋ฉด ๋‹ค์Œ ์„ธ ๊ฐ€์ง€ ๋ช…๋ น์„ ์‹คํ–‰ํ•˜์—ฌ ์‚ฌ์šฉ์ž ์ง€์ • ์ •์ฑ… ๋ชจ๋“ˆ์„ ์ปดํŒŒ์ผํ•˜๊ณ  ๋กœ๋“œํ•ฉ๋‹ˆ๋‹ค.

    checkmodule -M -m -o mongodb_proc_net.mod mongodb_proc_net.te
    semodule_package -o mongodb_proc_net.pp -m mongodb_proc_net.mod
    sudo semodule -i mongodb_proc_net.pp
  1. mongod ์„œ๋น„์Šค๊ฐ€ ์ƒˆ ๋””๋ ‰ํ„ฐ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก SELinux ์ •์ฑ…์„ ์—…๋ฐ์ดํŠธํ•˜์„ธ์š”.

    sudo semanage fcontext -a -t <type> </some/MongoDB/directory.*>

    ๋‹ค์Œ ์œ ํ˜• ์ค‘ ํ•˜๋‚˜๋ฅผ ์ ์ ˆํžˆ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค.

    • mongod_var_lib_t ๋ฐ์ดํ„ฐ ๋””๋ ‰ํ† ๋ฆฌ์˜ ๊ฒฝ์šฐ

    • mongod_log_t ๋กœ๊ทธ ํŒŒ์ผ ๋””๋ ‰ํ† ๋ฆฌ์˜ ๊ฒฝ์šฐ

    • mongod_var_run_t pid ํŒŒ์ผ ๋””๋ ‰ํ† ๋ฆฌ์˜ ๊ฒฝ์šฐ

    ์ฐธ๊ณ 

    ๋””๋ ‰ํ† ๋ฆฌ ๋์— .* ์„ ํฌํ•จํ•˜๋Š” ๊ฒƒ์„ ์žŠ์ง€ ๋งˆ์„ธ์š”.

  2. ์ƒˆ ๋””๋ ‰ํ„ฐ๋ฆฌ์— ๋Œ€ํ•œ SELinux ์‚ฌ์šฉ์ž ์ •์ฑ…์„ ์—…๋ฐ์ดํŠธํ•˜์„ธ์š”.

    sudo chcon -Rv -u system_u -t <type> </some/MongoDB/directory>

    ๋‹ค์Œ ์œ ํ˜• ์ค‘ ํ•˜๋‚˜๋ฅผ ์ ์ ˆํžˆ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค.

    • mongod_var_lib_t ๋ฐ์ดํ„ฐ ๋””๋ ‰ํ† ๋ฆฌ์˜ ๊ฒฝ์šฐ

    • mongod_log_t ๋กœ๊ทธ ๋””๋ ‰ํ† ๋ฆฌ์˜ ๊ฒฝ์šฐ

    • mongod_var_run_t pid ํŒŒ์ผ ๋””๋ ‰ํ† ๋ฆฌ์˜ ๊ฒฝ์šฐ

  3. ์—…๋ฐ์ดํŠธ๋œ SELinux ์ •์ฑ…์„ ๋””๋ ‰ํ„ฐ๋ฆฌ์— ์ ์šฉํ•ฉ๋‹ˆ๋‹ค.

    sudo restorecon -R -v </some/MongoDB/directory>

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

ํŒ

semanage fcontext ์ž‘์—…์˜ ๊ฒฝ์šฐ ๋””๋ ‰ํ„ฐ๋ฆฌ ๋์— .*๋ฅผ ๋ฐ˜๋“œ์‹œ ํฌํ•จ์‹œํ‚ค์„ธ์š”.

  • /mongodb/data์˜ ๊ธฐ๋ณธ์ด ์•„๋‹Œ MongoDB ๋ฐ์ดํ„ฐ ๊ฒฝ๋กœ๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ:

    sudo semanage fcontext -a -t mongod_var_lib_t '/mongodb/data.*'
    sudo chcon -Rv -u system_u -t mongod_var_lib_t '/mongodb/data'
    sudo restorecon -R -v '/mongodb/data'
  • ๊ธฐ๋ณธ๊ฐ’์ด ์•„๋‹Œ /mongodb/log์˜ MongoDB ๋กœ๊ทธ ๋””๋ ‰ํ„ฐ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ (์˜ˆ: ๋กœ๊ทธ ํŒŒ์ผ ๊ฒฝ๋กœ๊ฐ€ /mongodb/log/mongod.log์ธ ๊ฒฝ์šฐ):

    sudo semanage fcontext -a -t mongod_log_t '/mongodb/log.*'
    sudo chcon -Rv -u system_u -t mongod_log_t '/mongodb/log'
    sudo restorecon -R -v '/mongodb/log'
sudo semanage port -a -t mongod_port_t -p tcp <portnumber>

์ค‘์š”

์œ„์˜ ์‚ฌํ•ญ ์™ธ์—๋„ SELinux๊ฐ€ enforcing ๋ชจ๋“œ์ธ ๊ฒฝ์šฐ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๊ฐ ์ƒํ™ฉ์— ๋Œ€ํ•ด SELinux ์ •์ฑ…์„ ์ถ”๊ฐ€๋กœ ์‚ฌ์šฉ์ž ์ง€์ •ํ•ด์•ผ ํ•  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค.

  • ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์กฐํ•ฉ์— ๊ธฐ๋ณธ ๊ฒฝ๋กœ๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋Œ€์‹  ์‚ฌ์šฉ์ž ์ง€์ • ๋””๋ ‰ํ† ๋ฆฌ ๊ฒฝ๋กœ๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

  • ๊ธฐ๋ณธ MongoDB ํฌํŠธ ์‚ฌ์šฉํ•˜๋Š” ๋Œ€์‹  ์‚ฌ์šฉ์ž ์ง€์ • ํฌํŠธ ๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

  • MongoDB ์„ค์น˜์— ๋‹ค๋ฅธ ๋ณ€๊ฒฝ ์‚ฌํ•ญ์„ ์ ์šฉํ•œ ๊ฒฝ์šฐ.

๋‹ค์Œ ๋‹จ๊ณ„์— ๋”ฐ๋ผ ์‹œ์Šคํ…œ์—์„œ MongoDB Community Edition์„ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค. ์ด ์ง€์นจ์€ ๊ธฐ๋ณธ ์„ค์ •์„ ์‚ฌ์šฉํ•œ๋‹ค๊ณ  ๊ฐ€์ •ํ•ฉ๋‹ˆ๋‹ค.

1

MongoDB ์ธ์Šคํ„ด์Šค๊ฐ€ ๋ฐ์ดํ„ฐ๋ฅผ ์ €์žฅํ•˜๋Š” ๋””๋ ‰ํ† ๋ฆฌ๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค. ์˜ˆ์‹œ:

sudo mkdir -p /var/lib/mongo

MongoDB ์ธ์Šคํ„ด์Šค๊ฐ€ ๋กœ๊ทธ๋ฅผ ์ €์žฅํ•˜๋Š” ๋””๋ ‰ํ„ฐ๋ฆฌ๋ฅผ ๋งŒ๋“ญ๋‹ˆ๋‹ค. ์˜ˆ์‹œ:

sudo mkdir -p /var/log/mongodb

MongoDB ํ”„๋กœ์„ธ์Šค๋ฅผ ์‹œ์ž‘ํ•˜๋Š” ์‚ฌ์šฉ์ž๋Š” ์ด๋Ÿฌํ•œ ๋””๋ ‰ํ† ๋ฆฌ์— ๋Œ€ํ•œ ์ฝ๊ธฐ ๋ฐ ์“ฐ๊ธฐ ๊ถŒํ•œ์„ ๋ฐ˜๋“œ์‹œ ๋ณด์œ ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด MongoDB๋ฅผ ์ง์ ‘ ์‹คํ–‰ํ•˜๋ ค๋ฉด ๋‹ค์Œ์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.

sudo chown `whoami` /var/lib/mongo # Or substitute another user
sudo chown `whoami` /var/log/mongodb # Or substitute another user
2

MongoDB๋ฅผ ์‹คํ–‰ํ•˜๋ ค๋ฉด ์‹œ์Šคํ…œ ํ”„๋กฌํ”„ํŠธ์—์„œ mongod ํ”„๋กœ์„ธ์Šค๋ฅผ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.

mongod --dbpath /var/lib/mongo --logpath /var/log/mongodb/mongod.log --fork

๋ช…๋ น์ค„ ์˜ต์…˜ --dbpath ๋ฐ --logpath์— ๋Œ€ํ•œ ์ž์„ธํ•œ ๋‚ด์šฉ์€ ์˜ต์…˜์—์„œ ํ™•์ธ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

3

๋กœ๊ทธ ํŒŒ์ผ /var/log/mongodb/mongod.log์—์„œ ๋‹ค์Œ ์ค„์— ๋Œ€ํ•œ ํ”„๋กœ์„ธ์Šค ์ถœ๋ ฅ์„ ํ™•์ธํ•˜์—ฌ MongoDB๊ฐ€ ์„ฑ๊ณต์ ์œผ๋กœ ์‹œ์ž‘๋˜์—ˆ๋Š”์ง€ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.

[initandlisten] waiting for connections on port 27017

ํ”„๋กœ์„ธ์Šค ์ถœ๋ ฅ์— ์ค‘์š”ํ•˜์ง€ ์•Š์€ ๊ฒฝ๊ณ ๊ฐ€ ํ‘œ์‹œ๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์œ„์˜ ๋กœ๊ทธ ์ค„์ด ํ‘œ์‹œ๋˜์–ด ์žˆ๋‹ค๋ฉด MongoDB๋ฅผ ์ฒ˜์Œ ํ‰๊ฐ€ํ•˜๋Š” ๋™์•ˆ์—๋Š” ์ด๋Ÿฌํ•œ ๊ฒฝ๊ณ ๋ฅผ ๋ฌด์‹œํ•ด๋„ ๋ฉ๋‹ˆ๋‹ค.

4

mongod์™€ ๋™์ผํ•œ ํ˜ธ์ŠคํŠธ ๋จธ์‹ ์—์„œ mongosh ์„ธ์…˜์„ ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค. ๋ช…๋ น์ค„ ์˜ต์…˜ ์—†์ด mongosh๋ฅผ ์‹คํ–‰ํ•˜์—ฌ ๊ธฐ๋ณธ ํฌํŠธ 27017์—์„œ localhost์—์„œ ์‹คํ–‰ ์ค‘์ธ mongod์— ์—ฐ๊ฒฐํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

mongosh

๋‹ค๋ฅธ ํ˜ธ์ŠคํŠธ ๋ฐ/๋˜๋Š” ํฌํŠธ์—์„œ ์‹คํ–‰ํ•˜๋Š” mongod ์ธ์Šคํ„ด์Šค์— ์—ฐ๊ฒฐํ•˜๋Š” ๋“ฑ mongosh(์„)๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์—ฐ๊ฒฐํ•˜๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•œ ์ž์„ธํ•œ ๋‚ด์šฉ์€ mongosh ๋ฌธ์„œ๋ฅผ ์ฐธ์กฐํ•˜์„ธ์š”.

MongoDB๋Š” ์‚ฌ์šฉ์„ ์‹œ์ž‘ํ•˜๋Š” ๋ฐ ๋„์›€์ด ๋˜๋„๋ก ๋‹ค์–‘ํ•œ ๋“œ๋ผ์ด๋ฒ„ ์—๋””์…˜์— ๋Œ€ํ•ด ์‹œ์ž‘ ๊ฐ€์ด๋“œ๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค. ๋“œ๋ผ์ด๋ฒ„ ์„ค๋ช…์„œ๋Š” MongoDB๋กœ ๊ฐœ๋ฐœ ์‹œ์ž‘ํ•˜๊ธฐ๋ฅผ ์ฐธ์กฐํ•˜์„ธ์š”.

MongoDB๋Š” bindIp๊ฐ€ ๋กœ์ปฌ ํ˜ธ์ŠคํŠธ ๋„คํŠธ์›Œํฌ ์ธํ„ฐํŽ˜์ด์Šค์— ๋ฐ”์ธ๋”ฉ๋˜๋Š” 127.0.0.1๋กœ ์„ค์ •๋˜์–ด ์‹คํ–‰๋˜๋„๋ก ๊ธฐ๋ณธ ์„ค์ •๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค. ์ด๋Š” mongod๊ฐ€ ๋™์ผํ•œ ์‹œ์Šคํ…œ์—์„œ ์‹คํ–‰ ์ค‘์ธ ํด๋ผ์ด์–ธํŠธ์˜ ์—ฐ๊ฒฐ๋งŒ ํ—ˆ์šฉํ•  ์ˆ˜ ์žˆ์Œ์„ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค. ์›๊ฒฉ ํด๋ผ์ด์–ธํŠธ๋Š” mongod์— ์—ฐ๊ฒฐํ•  ์ˆ˜ ์—†์œผ๋ฉฐ, ์ด ๊ฐ’์ด ์œ ํšจํ•œ ๋„คํŠธ์›Œํฌ ์ธํ„ฐํŽ˜์ด์Šค๋กœ ์„ค์ •๋˜์–ด ์žˆ์ง€ ์•Š์œผ๋ฉด mongod๋Š” ๋ณต์ œ๋ณธ ์„ธํŠธ๋ฅผ ์ดˆ๊ธฐํ™”ํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.

์ด ๊ฐ’์€ ๋‹ค์Œ ์ค‘ ํ•œ ๊ฐ€์ง€ ๋ฐฉ๋ฒ•์œผ๋กœ ๊ตฌ์„ฑํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

  • MongoDB ๊ตฌ์„ฑ ํŒŒ์ผ์—์„œ bindIp๋ฅผ ํ†ตํ•ด

  • ๋ช…๋ น์ค„ ์ธ์ˆ˜๋ฅผ ํ†ตํ•ด --bind_ip

๊ฒฝ๊ณ 

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

bindIp ๊ตฌ์„ฑ์— ๋Œ€ํ•œ ์ž์„ธํ•œ ๋‚ด์šฉ ์€ ์ž์ฒด ๊ด€๋ฆฌ ๋ฐฐํฌ์„œ๋ฒ„์˜ IP ๋ฐ”์ธ๋”ฉ์„ ์ฐธ์กฐํ•˜์„ธ์š”.

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

Red Hat์— ์„ค์น˜