์ฐ์ EC2 ์ ๋ฐฐํฌ ํ ์คํธ๋ถํฐ ํ์ธํ ํ์๊ฐ ์๋ค.
์๊ธ์
-
์จ๋๋งจ๋
-
์์์(์์ธ)
-
Linux
์ ๊ธฐ์ค์ผ๋ก ๋ค์๊ณผ ๊ฐ๋ค.
https://aws.amazon.com/ko/ec2/pricing/on-demand/
์ต์ ์ฌ์์ t3.micro๋ก ์ก์ผ๋ฉด ํ ๋ฌ์ 11232์ ์ ๋ (ํ์จ : 1200์ ๊ธฐ์ค)๊ฐ ์์๋๋ค.
EC2์๋ jar ๋ฐฐํฌ ํ์ผ๊ณผ MySQL DB์๋ฒ๋ง ์์ ์์ ์ด๋ฉฐ,
ํ์ฌ develop๋ธ๋์น ๊ธฐ์ค์ผ๋ก ๋ชจ๋ API ์ ๋ํ์ฌ tps 1์ ๋๋ฆฌ๊ณ ๋ชจ๋ํฐ๋ง ์์ ์ด๋ค.
์ฐ์ jar๋ฅผ ๋ง๋ ๋ค
./gradlew build
๊ทธ๋ฆฌ๊ณ AWS EC2๋ก ์ฌ๋ฆฐ๋ค.
scp -i [ํค์ด๋ฆ].pem dev-event-server-0.0.1-SNAPSHOT.jar ubuntu@[์๋ฒIP]:~/
jvm๋ถํฐ ์ค์นํ๋ค.
https://davelogs.tistory.com/71
$ sudo apt-get update
$ sudo apt-get upgrade
# JAVA11 ์ค์น
$ sudo apt-get install openjdk-11-jdk
mysql ์ค์นํ๋ค.
sudo apt-get update # ์ฐ๋ถํฌ ์๋ฒ ์
๋ฐ์ดํธ
sudo apt-get install mysql-server # mysql-server ์ค์น
sudo ufw allow mysql # ์ธ๋ถ ์ ์ ๊ธฐ๋ฅ ์ค์ (ํฌํธ 3306 ์คํ)
sudo systemctl start mysql # MySQL ์คํ
sudo systemctl enable mysql # Ubuntu ์๋ฒ ์ฌ์์์ MySQL ์๋ ์ฌ์์
sudo /usr/bin/mysql -u root -p # MySQL ์ ์
CREATE DATABASE dev_event default CHARACTER SET UTF8; # DB์์ฑ
์ฐธ๊ณ ๋ก ํ์ฌ port 9000์ผ๋ก ํฝ์ค ํด๋์์ผ๋ฏ๋ก, ec2์์ ๋ฐฉํ๋ฒฝ(์ธ๋ฐ์ด๋ ๊ท์น) 9000 ์ด์ด์ผ ๋๋ค.
http://[์๋ฒIP]:9000/admin/v1/events/2021/7 ๋ก
ํด๋ณด๋ฉด ๊ธฐ๋ณธ์ ์ธ API ์๋ต ๊ฐ๋ฅํ ๊ฒ ํ์ธ๋์๊ณ ,
์ด์ postman์ผ๋ก ๋ชจ๋ํฐ๋ง ์ค์ ์ ์ค๋นํ๋ค.
< ์ฌ์ฉ๋ฒ >
JaeYoung ๋ ๋ธ๋ก๊ทธ ๋ฅผ ์ฐธ๊ณ ํ์ฌ ์์ฑํ์์ต๋๋ค.
-
EC2์ ruby์ค์น ํ code-deploy agent๋ฅผ ์ค์น
sudo apt-get update sudo apt-get install ruby sudo apt-get install wget cd /home/ubuntu wget https://`bucket-name`.s3.`region-identifier`.amazonaws.com/latest/install chmod +x ./install sudo ./install auto
bucket-name๊ณผ region-identifier์
AWS ๊ณต์ ๋ฌธ์๋ฅผ ๊ธฐ์ค์ผ๋ก ์ค์ ํ๋ ์ ๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
wget https://aws-codedeploy-ap-northeast-2.s3.ap-northeast-2.amazonaws.com/latest/install
(์ฐธ๊ณ ๋ก, ํ์ฌ EC2์๋ jvm๊ณผ mysql์ด ์ค์น๋์ด ์์ด์ ์๋ฐ ์ดํ๋ฆฌ์ผ์ด์ ์ด ์คํ๊ฐ๋ฅํ ์ํ์์ ์์ํ์์ต๋๋ค.)
-
AWS ์ธํ
- EC2 IAM ์ค์
- CodeDeploy ์ดํ๋ฆฌ์ผ์ด์ ์์ฑ ๋ฐ IAM ์ค์
- S3 ์์ฑ
- ์ฌ์ฉ์ ์์ฑ (accessKey, secretKey ํ์)
-
EC2 ๋ฐฐํฌ์คํฌ๋ฆฝํธ ์์ฑ
ํ๋ก์ ํธ ๋ฃจํธ ๊ฒฝ๋ก์
-
appspec.yml
version: 0.0 os: linux files: - source: / destination: /home/ubuntu/sangjin-deploy permissions: - object: /home/ubuntu/sangjin-deploy/ owner: ubuntu group: ubuntu hooks: AfterInstall: - location: scripts/deploy.sh timeout: 60 runas: ubuntu
-
deploy.sh
#!/usr/bin/env bash REPOSITORY=/home/ubuntu/sangjin-deploy cd $REPOSITORY APP_NAME=actions JAR_NAME=$(ls $REPOSITORY/build/libs/ | grep 'SNAPSHOT.jar' | tail -n 1) JAR_PATH=$REPOSITORY/build/libs/$JAR_NAME CURRENT_PID=$(pgrep -f $APP_NAME) if [ -z $CURRENT_PID ] then echo "> ์ข ๋ฃํ ๊ฒ ์์." else echo "> kill -9 $CURRENT_PID" kill -15 $CURRENT_PID sleep 5 fi echo "> $JAR_PATH ๋ฐฐํฌ" nohup java -jar $JAR_PATH > /dev/null 2> /dev/null < /dev/null &
-
-
.github/workflows์์ yml ์์ฑ
# This is a basic workflow to help you get started with Actions name: github actions + heroku on: push: branches: [ main ] # Allows you to run this workflow manually from the Actions tab workflow_dispatch: env: PROJECT_NAME: CDapp # A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: # This workflow contains a single job called "build" build: # The type of runner that the job will run on runs-on: ubuntu-latest # Steps represent a sequence of tasks that will be executed as part of the job steps: # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - uses: actions/checkout@v2 - name: Make zip file run: zip -qq -r ./$GITHUB_SHA.zip . # GITHUB_SHA๋ ์์ฝ๋ณ์๋ก, ์ปค๋ฐ ํด์๊ฐ shell: bash - name: Configure AWS credentials uses: aws-actions/configure-aws-credentials@v1 with: aws-access-key-id: ${{ secrets.accessKey }} aws-secret-access-key: ${{ secrets.secretKey }} aws-region: ${{ secrets.region }} - name: Upload to S3 run: aws s3 cp --region ap-northeast-2 ./$GITHUB_SHA.zip s3://sangjin-deploy/$PROJECT_NAME/$GITHUB_SHA.zip - name: Code Deploy run: aws deploy create-deployment --application-name CDapp --deployment-config-name CodeDeployDefault.OneAtATime --deployment-group-name CDapp --s3-location bucket=sangjin-deploy,bundleType=zip,key=$PROJECT_NAME/$GITHUB_SHA.zip
-
์ฑ๊ณต โญ๏ธ