Skip to content

Latest commit

ย 

History

History
155 lines (88 loc) ยท 3.39 KB

HEROKU_GCP.md

File metadata and controls

155 lines (88 loc) ยท 3.39 KB

Heroku + GCP


3-1. GCP Compute Engine + MySQL

STEP 1. ec2-micro ์ธ์Šคํ„ด์Šค์— MySQL ์„ค์น˜
        ์„ค์น˜ ์ปค๋ฉ˜๋“œ ๊ธฐ๋ก

STEP 2. ec2-micro ์ธ์Šคํ„ด์Šค ๋น„์šฉ ์ •์ฑ… ๊ธฐ๋ก

STEP 1.

  1. ์„ค์น˜ ์Šคํฌ๋ฆฝํŠธ ์ƒ์„ฑ

    mysql.sh

    sudo apt-get -y update # ์šฐ๋ถ„ํˆฌ ์„œ๋ฒ„ ์—…๋ฐ์ดํŠธ
    sudo apt-get -y install mysql-server # mysql-server ์„ค์น˜ (ํ˜น์€ mariadb-server)
    sudo ufw allow mysql # ์™ธ๋ถ€ ์ ‘์† ๊ธฐ๋Šฅ ์„ค์ • (ํฌํŠธ 3306 ์˜คํ”ˆ)
    sudo systemctl start mysql # MySQL ์‹คํ–‰
    sudo systemctl enable mysql # Ubuntu ์„œ๋ฒ„ ์žฌ์‹œ์ž‘์‹œ MySQL ์ž๋™ ์žฌ์‹œ์ž‘
    
    
    query="CREATE DATABASE [DB๋ช…] default CHARACTER SET UTF8; # DB์ƒ์„ฑ
    
    CREATE USER '[์‚ฌ์šฉ์ž๋ช…]'@'[Spring์„œ๋ฒ„ IP]' IDENTIFIED BY '[๋น„๋ฐ€๋ฒˆํ˜ธ]'; # ์‚ฌ์šฉ์ž ์ƒ์„ฑ
    FLUSH PRIVILEGES;
    
    GRANT ALL PRIVILEGES ON [DB๋ช…].* TO '[์‚ฌ์šฉ์ž๋ช…]'@'[Spring์„œ๋ฒ„ IP]';
    FLUSH PRIVILEGES;
    SHOW GRANTS FOR'[์‚ฌ์šฉ์ž๋ช…]'@'[Spring์„œ๋ฒ„ IP]';"
    
    sudo /usr/bin/mysql -u root -D mysql -e "${query}"  # DB ์ฟผ๋ฆฌ ์‹คํ–‰
  2. ์Šคํฌ๋ฆฝํŠธ ์‹คํ–‰

    ./mysql.sh

STEP 2.

GCP ๋ฌด๋ฃŒ ํ”„๋กœ๊ทธ๋žจ ์„ ์ฐธ๊ณ ํ•˜๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์•ˆ๋‚ด๊ธ€์„ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

image

  • ํŠน์ • ๋ฆฌ์ „ (์˜ค๋ฆฌ๊ฑด: us-west1, ์•„์ด์˜ค์™€: us-central1, ์‚ฌ์šฐ์Šค์บ๋กค๋ผ์ด๋‚˜: us-east1)
  • ์Šคํ† ๋ฆฌ์ง€ 30GB

๊นŒ์ง€๋Š” ์›” 720์‹œ๊ฐ„๊นŒ์ง€ ๋ฌด๋ฃŒ๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.


๊ทธ๋ž˜์„œ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์„ค์ •ํ•˜์˜€์Šต๋‹ˆ๋‹ค.

image

(์›”๋ณ„ ์˜ˆ์ƒ ๊ฐ€๊ฒฉ์€ 720์‹œ๊ฐ„ ์ดˆ๊ณผ ํ›„์˜ ๊ฐ€๊ฒฉ์ด์ง€ ์•Š์„๊นŒ ์ƒ๊ฐ๋ฉ๋‹ˆ๋‹ค.)



3-2. ํ—ค๋กœ์ฟ  ์—ฐ๋™ ํ…Œ์ŠคํŠธ

STEP 1.  GCP ์ธ์Šคํ„ด์Šค์— ์„ค์น˜ํ•œ MySQL์— ํ—ค๋กœ์ฟ  ์—ฐ๋™
          MySQL ์ •๋ณด๋Š”application-real.yml ์„ค์ •์ •๋ณด ์ถ”๊ฐ€

STEP 2. DEV GROUP real data๋กœ insert

STEP 3. API ๋ช‡๋ฒˆ ํ˜ธ์ถœํ•ด๋ณด๊ณ  ํ‰๊ท  ์‘๋‹ต ms ๊ธฐ๋ก

STEP 1.

  1. GCP MySQL ์„œ๋ฒ„ IP ํ™•์ธ ํ›„ ํ”„๋กœ์ ํŠธ ์„ค์ • ๊ฐ’ ๋ณ€๊ฒฝ

    • MySQL IP : xx.xxx.xx.xxx

    • appliction-real.yml

      spring:
        datasource:
          driver-class-name: com.mysql.cj.jdbc.Driver
          url: jdbc:mysql://xx.xxx.xx.xxx:3306/dev_event?characterEncoding=UTF-8&serverTimezone=UTC
          username: [์‚ฌ์šฉ์ž๋ช…]
          password: [๋น„๋ฐ€๋ฒˆํ˜ธ]

    โ›ฑ ์ฃผ์˜ํ•  ์ 

    • mysql ์„œ๋ฒ„์˜ ์‚ฌ์šฉ์ž๋ฅผ ๋งŒ๋“ค๋•Œ ์Šคํ”„๋ง ์„œ๋ฒ„ ip ๋งŒ ํ—ˆ์šฉํ•ด์„œ ๋งŒ๋“ค๊ฒƒ
    • db์„œ๋ฒ„ ip์˜คํ”ˆ์€ ์Šคํ”„๋ง ์„œ๋ฒ„ ip ๋งŒ ํ—ˆ์šฉํ•  ๊ฒƒ
  2. MySQL ์„œ๋ฒ„ ์˜คํ”ˆ

    vi /etc/mysql/mariadb.conf.d/50-server.cnf

    50-server.cnf

    bind-address = [์Šคํ”„๋ง ์„œ๋ฒ„ ip]
    
    service mysql restart
    netstat -lntp  # 3306๋ฒˆ ํฌํŠธ ์—ด๋ฆฐ ip ํ™•์ธ  
  3. ์ด๋ ‡๊ฒŒ ํ•˜๋ฉด ๋ฐฐํฌ๋Š” ์™„๋ฃŒ~!

    image

cf) heroku ์ฐธ๊ณ 

$ heroku login

$ heroku git:remote -a sangjin-test

$ git add .
$ git commit -am "make it better"
$ git push heroku master