๐Ÿ‹๏ธโ€โ™‚๏ธ 7์›”์˜ ํ”„๋กœ์ ํŠธ2 (๐Ÿ‘ GCP์— DB๋“ค ์„ค์น˜ํ•˜๊ธฐ)

0

7์›”์˜ ํ”„๋กœ์ ํŠธ

๋ชฉ๋ก ๋ณด๊ธฐ
2/11

ํ”„๋กœ์ ํŠธ๋ฅผ ์‹œ์ž‘ํ•˜๋ฉด์„œ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋“ค์„ ๊ฐ์ž์˜ ๋กœ์ปฌ์„œ๋ฒ„์—์„œ ์šด์˜ํ•˜๋ฉด์„œ ๊ฐ์ž ๋ฐ์ดํ„ฐ๋“ค์˜ ๋ณ€์ˆ˜๋„ ๋‹ค๋ฅด๊ณ  ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์—์„œ ๋ถˆ๋Ÿฌ์˜ค๋Š” ๋ฐฉ์‹๋„ ๋‹ค๋ฅด๊ณ  ํ•˜๋‹ค๋ณด๋‹ˆ ๋นจ๋ฆฌ ๋ฐ์ดํ„ฐ๋“ค์˜ ํ‚ค๊ฐ’ ๋˜๋Š” ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋ฅผ ์—ฐ๋™ํ•˜๋Š” ๋ฐฉ์‹๋„ ํ†ต์ผํ•ด์•ผํ•œ๋‹ค๊ณ  ์ƒ๊ฐ์„ ํ–ˆ์Šต๋‹ˆ๋‹ค.
์ €ํฌ๊ฐ€ ์„ค์น˜ํ•ด์•ผํ•˜๋Š” ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋Š” ์„ธ๊ฐ€์ง€๋กœ MySQL, MongoDB, redis์ž…๋‹ˆ๋‹ค.

๐Ÿšฆ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์˜ ์ข…๋ฅ˜๋“ค

MySQL

์‹ค์ œ ์žฅ๊ณ ์—์„œ ์šด์˜ํ•˜๋ฉด์„œ ํšŒ์›์˜ ์ •๋ณด๋“ค๊ณผ ๊ฒŒ์‹œํŒ์˜ ์ •๋ณด๋“ค์„ ์ •ํ•ด์ง„ ๋ฐ์ดํ„ฐํƒ€์ž…์œผ๋กœ ๋ฐ›์•„์•ผํ•˜๊ณ , ํšŒ์›์ •๋ณด๋“ค์ค‘ ๊ธฐ๋ณธํ‚ค์™€ ์™ธ๋ž˜ํ‚ค๋“ฑ์„ ์ด์šฉํ•ด์„œ ์ค‘๋ณต์„ ๋ฐฉ์ง€ํ•˜๊ฑฐ๋‚˜ joinํ•ด์„œ ์ •๋ณด๋“ค์„ ๊ฐ€์ ธ์˜ค๊ธฐ ์œ„ํ•ด์„œ์ž…๋‹ˆ๋‹ค.

MongoDB

์šด์˜ํ•˜๋ฉด์„œ ํ•„์š”ํ–ˆ๋˜ ์˜ํ™”์ •๋ณด์ด ๋งŽ๊ณ  ๊ทธ๋Ÿฐ ์ •๋ณด๋“ค์„ ์ฝ๊ธฐ์†๋„๊ฐ€ ๋น ๋ฅธ ๋น„๊ด€๊ณ„ํ˜•์„ ์‚ฌ์šฉํ•˜๋ฉด์„œ ์†๋„๋ฅผ ๊ฐœ์„ ํ•˜์˜€์Šต๋‹ˆ๋‹ค.

Redis

์ตœ๊ทผ ๋งŽ์ด ์‚ฌ์šฉํ•˜๋ฉฐ, ๋ฐ์ดํ„ฐ๋ฅผ ๋””์Šคํฌ๋‚˜ SSD์— ๋†“๋Š”๊ฒƒ์ด ์•„๋‹Œ ์„œ๋ฒ„์˜ ์ฃผ ๋ฉ”๋ชจ๋ฆฌ์— ๋‘๋ฉด์„œ ์†๋„๊ฐ€ ๋น ๋ฅด๋ฉฐ, ๋”•์…”๋„ˆ๋ฆฌ์˜ ํ˜•ํƒœ๋กœ ๋ฐ์ดํ„ฐ๊ฐ€ ์ €์žฅ๋˜๋ฉด์„œ ์†๋„๊ฐ€ ๋”๋น ๋ฅด๋‹ค๋Š” ์žฅ์ ์œผ๋กœ ์‚ฌ์šฉ์ž๊ฐ€ ์ตœ๊ทผ์— ๊ฒ€์ƒ‰ํ•˜๊ฑฐ๋‚˜ ํด๋ฆญํ•˜์—ฌ ๋“ค์–ด๊ฐ„ ์˜ํ™”๋“ค์„ ํŽ˜์ด์ง€ ํ•˜๋‹จ์— ๋ณด์—ฌ์ฃผ๊ธฐ ์œ„ํ•ด์„œ ์„ ์ •ํ•˜์˜€์Šต๋‹ˆ๋‹ค.


๐Ÿ™‰ ๊ณ ๋ฏผ๋“ค

์œ„์˜ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋“ค์„ ์–ด๋–ป๊ฒŒ ํด๋ผ์šฐ๋“œ ์„œ๋ฒ„์— ๊ตฌ์„ฑ์„ ํ•ด์•ผํ• ๊นŒ ๊ณ ๋ฏผ์„ ๋งŽ์ด ํ•˜์˜€์Šต๋‹ˆ๋‹ค.
๊ณ ๋ฏผํ–ˆ๋˜๊ฒƒ๋“ค์€ ์•„๋ž˜์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค.

1๏ธโƒฃ. ๋„์ปค์ปดํฌ์ฆˆ๋กœ ๋ฌถ์–ด์„œ ์ปจํ…Œ์ด๋„ˆ3๊ฐœ๋ฅผ ๋งŒ๋“ค์–ด์•ผ ํ• ๊นŒ?
2๏ธโƒฃ. ์ธ์Šคํ„ด์Šค๋ฅผ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์šฉ์œผ๋กœ ๋งŒ๋“ค์–ด์„œ ์„œ๋ฒ„์— ๊ทธ๋ƒฅ ์„ค์น˜๋ฅผ ํ•ด์•ผํ• ๊นŒ?

์ œ๊ฐ€ ๊ฐ€์žฅ ๊ณ ๋ฏผํ–ˆ๋˜๊ฒƒ์€ ํฌ๊ฒŒ 2๊ฐ€์ง€์ธ ๋ฐ์ดํ„ฐ๋“ค์˜ ์˜์†์„ฑ, ์•ˆ์ •์„ฑ์ด์—ˆ์Šต๋‹ˆ๋‹ค.

์˜์†์„ฑ

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

์•ˆ์ •์„ฑ

๊ทธ๋ฆฌ๊ณ  ์•ˆ์ •์„ฑ์„ ์ƒ๊ฐํ•œ ์ด์œ ๋Š” ๋งŒ์•ฝ ๊ฐ€์ƒํ™˜๊ฒฝ์— ๋„์ปค๋กœ ๊ฐ€์ƒํ™˜๊ฒฝ์„ ๋˜๋งŒ๋“ค๊ฒŒ ๋œ๋‹ค๋ฉด ๊ฐ€์ƒ+๊ฐ€์ƒ์ด๋˜๋ฉด์„œ
๊ด€๋ฆฌ๋ฅผ ํฌ์ธํŠธ๋“ค๋„ ๋งŽ๊ณ , ์•„๋ฌด๋ฆฌ ๋„์ปค๋กœ ๋ณผ๋ฅจ์„ ํ–ˆ์–ด๋„ ๋ฐ์ดํ„ฐ๋“ค์˜ ๋ฐ”์ด๋„ˆ๋ฆฌํŒŒ์ผ์ด๋‚˜ ๋ชจ๋“ ์ฟผ๋ฆฌ๋“ค์ด ๋กœ๊ทธ๋กœ ๊ด€๋ฆฌ๊ฐ€ ์–ด๋ ต๊ณ , AWS์˜ RDS์ฒ˜๋Ÿผ ์•ˆ์ •์„ฑ์ด ๋ณด์žฅ๋˜๋ฉด์„œ ๋ฐฑ์—…์— ๋Œ€ํ•œ ๋ฌธ์ œ์ ๋„ ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค.


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

  • ์ธ๋ฐ”์šด๋“œ๋Š” ํฌํŠธ๋ฅผ ํ†ตํ•ด ๋“ค์–ด์˜ฌ์ˆ˜์žˆ๋Š” ip๋ฅผ ์„ค์ •ํ•˜๋ฉฐ
  • ์•„์›ƒ๋ฐ”์šด๋“œ๋Š” ์„œ๋ฒ„๋ฅผ ๋‚˜๊ฐ€๋Š” ๋ฐ์ดํ„ฐ๋“ค์˜ ๊ทœ์น™์ž…๋‹ˆ๋‹ค.

๐Ÿฆค๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์„ค์น˜

์ œ์ผ๋จผ์ € ์ €๋Š” ubuntu์— ์„ค์น˜ํ•˜๊ธฐ ๋•Œ๋ฌธ์— ๋ฒ„์ „์„ ํ™•์ธํ•˜๊ธฐ์œ„ํ•ด
$ lsb_release -dc๋ฅผ ์‚ฌ์šฉํ•ด์„œ ubuntu์˜ ๋ฒ„์ „์„ ํ™•์ธํ•˜์˜€์Šต๋‹ˆ๋‹ค.

โš™๏ธ GCP์— MySQL์„ค์น˜ํ•˜๊ธฐ

  1. apt-get ์—…๋ฐ์ดํŠธํ•˜๊ธฐ
    $ sudo install apt-get update

  2. MySQL ์„œ๋ฒ„๋‹ค์šด๋กœ๋“œ
    $ sudo apt-get install mysql-server

  3. ๊ณ„์ •๊ด€๋ฆฌ๋ฅผ ์œ„ํ•œ mysql_secure_installation ์„ค์น˜
    $ sudo apt-get install mysql_secure_installation

  4. ์›๊ฒฉ์ ‘์†ํ—ˆ์šฉํ•˜๊ธฐ

  • $ sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
    mysql์˜ ์„ค์ •ํŒŒ์ผ์„ ์—ด์–ด์„œ ์„ค์ •์„ ๋ฐ”๊ฟ”์ฃผ์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

  • bind-address ๋ณ€๊ฒฝ
    bind-address๋ฅผ 0.0.0.0๋ฐ”๊ฟ”์„œ ๋ชจ๋“  ์•„์ดํ”ผ๋ฅผ ์ ‘์†์„ ํ—ˆ์šฉํ•ด์•ผํ•ฉ๋‹ˆ๋‹ค.
    ํ•˜์ง€๋งŒ ๋ณด์•ˆ์ƒ ํŠน์ •์•„์ดํ”ผ๋งŒ ํ—ˆ์šฉํ•˜๋Š”๊ฒƒ์ด ์ข‹์•„๋ณด์ž…๋‹ˆ๋‹ค.

  1. ๊ณ„์ •์ƒ์„ฑ๊ณผ ๊ถŒํ•œ์„ค์ •
  • CREATE USER [์œ ์ €์ด๋ฆ„];
  • SET PASSWORD FOR [์œ ์ €์ด๋ฆ„] = PASSWORD('[๋น„๋ฐ€๋ฒˆํ˜ธ]');
  • GRANT ์‚ฌ์šฉ๊ถŒํ•œ ON PRIVILEGES TO [์œ ์ €์ด๋ฆ„]@'[ํ˜ธ์ŠคํŠธ]' IDENTIFIED BY '[ํŒจ์Šค์›Œ๋“œ]';
  • FLUSH PRIVILEGES

โš™๏ธ GCP์— MongoDB์„ค์น˜ํ•˜๊ธฐ

  1. apt-get ์—…๋ฐ์ดํŠธํ•˜๊ธฐ
    MySQL์„ค์น˜ํ•˜๋ฉด์„œ ํ–ˆ๊ธฐ๋•Œ๋ฌธ์— ์ƒ๋žตํ–ˆ์Šต๋‹ˆ๋‹ค.

  2. ์ƒˆ ๋ฆฌํฌ์ง€ํ† ๋ฆฌ๋ฅผ ์ถ”๊ฐ€ํ•˜๋Š” ๋ฐ ํ•„์š”ํ•œ ์ข…์†์„ฑ์„ ์„ค์น˜
    $ sudo apt install dirmngr gnupg apt-transport-https ca-certificates software-properties-common

    ๋กœ์ปฌ์—์„œ์™€ ํด๋ผ์šฐ๋“œ์„œ๋ฒ„์—์„œ์˜ OS ์„ค์ • ๋ฐ ํŒจํ‚ค์ง€ ๊ด€๋ฆฌ ๋ฐฉ์‹์˜ ์ฐจ์ด๋กœ ์ธํ•ด ์„ค์น˜ ๋ฐฉ๋ฒ•์ด ๋‹ค๋ฆ…๋‹ˆ๋‹ค.
    ๊ทธ๋ฆฌ๊ณ  ์ตœ์‹  ๋ฒ„์ „์˜ MongoDB๋Š” Ubuntu 20.04 ๊ธฐ๋ณธ ๋ฆฌํฌ์ง€ํ† ๋ฆฌ์—์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ ์‹œ์Šคํ…œ์— ๊ณต์‹ MongoDB ๋ฆฌํฌ์ง€ํ† ๋ฆฌ๋ฅผ ์ถ”๊ฐ€ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค

  • dirmngr : ํ‚ค ์‚ฌ์šฉ์— ๊ด€๋ จ๋œ ์„œ๋ฒ„์™€ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์ œ์–ด๋ฅผ ๋‹ด๋‹นํ•˜๋Š” ๋ฐ๋ชฌ์ž…๋‹ˆ๋‹ค. ๋ฆฌํฌ์ง€ํ† ๋ฆฌ์˜ GPG ํ‚ค๋ฅผ ๋‹ค๋ฃจ๊ธฐ ์œ„ํ•ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.

  • gnupg : GPG์— ๊ด€๋ จ์ž…๋‹ˆ๋‹ค.

    • GPGํ‚ค๋Š” ๋ฐ์ดํ„ฐ ์•”ํ˜ธํ™” ๋ฐ ๋””์ง€ํ„ธ์„œ๋ช…๊ณผ ์ธ์ฆ์— ์‚ฌ์šฉ๋˜๋Š” ์•”ํ˜ธํ™” ๋„๊ตฌ๋กœ ๋ฐ์ดํ„ฐ ์†ก์ˆ˜์‹ ์— ์‚ฌ์šฉ๋˜๋Š” ๋ณด์•ˆํ‘œ์ค€์ค‘ ํ•˜๋‚˜์ž…๋‹ˆ๋‹ค.
  • apt-transport-https : apt๋Š” ๊ธฐ๋ณธ์ ์œผ๋กœ http๋งŒ ์ˆ˜์‹ ์ด ๊ฐ€๋Šฅํ•˜์ง€๋งŒ https๋กœ๋„ ์ˆ˜์‹ ์ด ๊ฐ€๋Šฅํ•˜๊ฒŒ ํ•ฉ๋‹ˆ๋‹ค.

  • ca-certificates : ์ผ๋ฐ˜์ ์ธ root ์ธ์ฆ์„œ๋ฅผ ์šฐ๋ถ„ํˆฌ ์‹œ์Šคํ…œ์— ์„ค์น˜ํ•ฉ๋‹ˆ๋‹ค. ์ด๋ ‡๊ฒŒ ํ•˜๋ฉด ๋ฆฌํฌ์ง€ํ† ๋ฆฌ์— ๋Œ€ํ•œ TLS/SSL ์—ฐ๊ฒฐ์— ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

  • software-properties-common : ๋ฆฌํฌ์ง€ํ† ๋ฆฌ๋ฅผ ์ถ”๊ฐ€ํ•˜๊ณ  ์ œ๊ฑฐํ•  ์ˆ˜ ์žˆ๋Š” ๋ช…๋ น์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.

  1. MongoDB์˜ GPGํ‚ค๋ฅผ ๊ฐ€์ ธ์˜ต๋‹ˆ๋‹ค.
    $ wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add -

  2. MongoDB์˜ ๊ณต์‹ ๋ฆฌํฌ์ง€ํ† ๋ฆฌ๋ฅผ ubuntu์— ์ถ”๊ฐ€
    $ sudo add-apt-repository 'deb [arch=amd64] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/4.4 multiverse'

  3. mongodb-org ๋ฉ”ํƒ€ ํŽ˜ํ‚ค์ง€ ์„ค์น˜
    $ sudo apt install mongodb-org


โš™๏ธ MongoDB๋ฅผ ์‹œ์ž‘ํ•˜๊ณ  ๊ณ„์ • ๋งŒ๋“ค๊ธฐ

  1. MongoDB ์‹œ์ž‘
    $ sudo systemctl start mongod

  2. MongoDB์˜ ์‰˜์— ๋“ค์–ด๊ฐ€๊ธฐ
    $ mongo

  3. ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ๋งŒ๋“ค๊ธฐ
    > use ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋ช…

  4. root ์—ญํ• ์„ ๊ฐ€์ง„ ๊ณ„์ •๋งŒ๋“ค๊ธฐ

>db.createUser(
  {
    user: "๊ณ„์ • ์ด๋ฆ„",
    pwd: "๊ณ„์ • ๋น„๋ฐ€๋ฒˆํ˜ธ",
    roles: [ { role: "root", db: "๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋ช…" } ]
  }
)
  1. ์‰˜์„ ๋‚˜๊ฐ„๋’ค ๋ณ€๊ฒฝ์‚ฌํ•ญ ํ…Œ์ŠคํŠธ
  • > mongo -u [๊ณ„์ • ์ด๋ฆ„] -p --authenticationDatabase [๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋ช…]
  • > use [๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋ช…]
  • > show users ๋ฅผ ์ž…๋ ฅํ•˜๊ฒŒ๋˜๋ฉด ์œ ์ €์˜ ์ •๋ณด๊ฐ€ ๋‚˜์˜ต๋‹ˆ๋‹ค.
  1. ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์˜ ๋„ํ๋จผํŠธ๋ฅผ ์ถ”๊ฐ€ํ•ด ์ƒ์„ฑํ™•์ธํ•˜๊ธฐ
    > db ๋ฅผ ์น˜๊ฒŒ๋˜๋ฉด ํ˜„์žฌ ์‚ฌ์šฉ์ค‘์ธ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋ฅผ ํ™•์ธ์ด ๊ฐ€๋Šฅํ•˜์ง€๋งŒ
    > show dbs๋ฅผ ์น˜๊ฒŒ๋˜๋ฉด ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ๋ชฉ๋ก์ค‘์—๋Š” ์•ˆ๋‚˜์˜ต๋‹ˆ๋‹ค.
    3๋ฒˆ์—์„œ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋ฅผ ๋งŒ๋“ค์—ˆ์ง€๋งŒ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์•ˆ์— ํ•˜๋‚˜์˜ ๋„ํ๋จผํŠธ๋ผ๋„ ์žˆ์–ด์•ผ ๋ณด์ž…๋‹ˆ๋‹ค.
    > db.[Collection๋ช…].insert({"name": "MongoDB Tutorial", "author": "velopert"});
    ์ด๋ ‡๊ฒŒ ๋„ํ๋จผํŠธ๋ฅผ ๋„ฃ์œผ๋ฉด ์ด์ œ ๋ชฉ๋ก์— ๋‚˜์˜ค๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.

โš™๏ธ ์›๊ฒฉ์ ‘์† ํ—ˆ์šฉํ•˜๊ธฐ

MySQL๊ณผ ๊ฐ™์ด ์„ค์ •ํŒŒ์ผ์— ๋“ค์–ด๊ฐ€ bind-address๋ฅผ ํ’€์–ด์ค˜์•ผ ํ•ฉ๋‹ˆ๋‹ค.

  1. ์„ค์ •ํŒŒ์ผ ๋“ค์–ด๊ฐ€๊ธฐ
    $ sudo vim /etc/mongod.conf

  2. ์„ค์ • ๋ณ€๊ฒฝ

# mongod.conf
# for documentation of all options, see:
# http://docs.mongodb.org/manual/reference/configuration-options/
# Where and how to store data.
storage:
  dbPath: /var/lib/mongodb
  journal:
    enabled: true

#  engine:
#  mmapv1:
#  wiredTiger:
# where to write logging data.
systemLog:
  destination: file
  logAppend: true
  path: /var/log/mongodb/mongod.log

# network interfaces
net:
  port: 27017
  bindIp: 0.0.0.0

processManagement:
  timeZoneInfo: /usr/share/zoneinfo

security:
  authorization: 'enabled'

#operationProfiling:
#replication:
#sharding:
## Enterprise-Only Options:
#auditLog:
#snmp:

๐Ÿ’ก ๋ณด์•ˆ๊ด€์ ์—์„œ๋Š” ๋ชจ๋‘ํ—ˆ์šฉํ•˜๋Š”๊ฒƒ์€ ์ข‹์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ ํŠน์ • ip๋งŒ ์ถ”๊ฐ€ํ•ด์„œ ํ—ˆ์šฉํ•˜๋Š”๊ฒƒ์ด ์ข‹์•„๋ณด์ž…๋‹ˆ๋‹ค.

  1. MongoDB ์žฌ์‹œ์ž‘
    $ sudo systemctl restart mongod

์ด๋ ‡๊ฒŒ ํ•˜๋ฉด MongoDB์˜ ์„ค์ •์„ ๋‹ค ๋งˆ์ณค๊ณ 
ํˆด์ด๋‚˜ ์ฝ”๋“œ์—์„œ ์ ‘์†์„ ํ•˜๊ธฐ์œ„ํ•ด์„œ
mongodb://[๊ณ„์ • ์ด๋ฆ„]:[๋น„๋ฐ€๋ฒˆํ˜ธ]@[IP]:27017/ ์„ ํ†ตํ•ด์„œ ์ ‘์†์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.


โš™๏ธ Redis ์„ค์น˜ํ•˜๊ธฐ

  1. ์ตœ์‹ ์˜ ๋ชจ๋“ˆ์ด๋‚˜ ์„ค์น˜ํ• ๊ฒƒ๋“ค์„ ๊ฐ€์ ธ์˜ต๋‹ˆ๋‹ค.
    $ sudo apt update

  2. redis-server๋ฅผ ์„ค์น˜ํ•ด์ค๋‹ˆ๋‹ค.
    $ sudo apt-get install redis-server

  3. Redis์˜ ์„ค์ •ํŒŒ์ผ์— ip๋ฅผ ์ˆ˜์ •ํ•ด์ค๋‹ˆ๋‹ค.
    $ sudo vim /etc/redis/redis.conf

  • bind 127.0.0.1 ::1 ๋ฅผ bind 0.0.0.0 ::1๋กœ ๋ณ€๊ฒฝํ•ด์ฃผ๊ณ  ์ฃผ์„์„ ํ’€์–ด์ค๋‹ˆ๋‹ค.
  1. Redis๋ฅผ ์žฌ์‹œ์ž‘ํ•ด์ฃผ๊ณ  ํฌํŠธ๋ฅผ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.
  • $ sudo systemctl restart redis : Redis๋ฅผ ์žฌ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค.
  • $ ss -an | grep 6379 : ๊ธฐ๋ณธ์ ์œผ๋กœ Redis๋Š” 6379ํฌํŠธ๋ฅผ ์‚ฌ์šฉ, 6379ํฌํŠธ์˜ ์ƒํƒœ๋ฅผ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.
  1. Redis์˜ ์ƒํƒœ๋ฅผ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.
    $ sudo systemctl status redis

๐Ÿ’ก ์ด๋ ‡๊ฒŒํ•˜๋ฉด ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค 3๊ฐœ๋ฅผ ์„ค์น˜๋ฅผ ๋งˆ์น˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.
๊ทธ๋ฆฌ๊ณ  ์ œ์ผ ์ฒ˜์Œ ์ค‘์š”ํ•˜๋‹ค๊ณ  ์–ธ๊ธ‰ํ–ˆ๋˜ AWS๋Š” ์ธ๋ฐ”์šด๋“œ๊ทธ๋ฃน, GCE๋Š” ๋ฐฉํ™”๋ฒฝ์„ค์ •์—์„œ
๊ฐ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์˜ ํ•ด๋‹นํฌํŠธ๋“ค์„ ์—ด์–ด์ฃผ๊ณ  ๋“ค์–ด์˜ค๋Š” IP๋„ ํ—ˆ์šฉํ•ด์ฃผ์–ด์•ผ ๋กœ์ปฌ์—์„œ ํˆด๋“ค๋กœ ๋ณผ์ˆ˜๊ฐ€ ์žˆ๊ณ 
์›๊ฒฉ์œผ๋กœ ์ ‘๊ทผ์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

0๊ฐœ์˜ ๋Œ“๊ธ€