[AWS] AWS Beanstalk๋ฅผ ์ด์ฉํ ์น ์ดํ๋ฆฌ์ผ์ด์ ๋ฐฐํฌ ๋ฐ beans-maven-plugin ์๊ฐ
Automating Maven Project Deployments on AWS Beantalk
์ฐธ๊ณ ๊ธ http://www.newvem.com/automating-maven-project-deployments-on-aws-elastic-beanstalk/
๊ฐ๋ ์ฑ ์ธก๋ฉด์์ ๋ evernote๊ฐ ๋ซ๋ค๋ ์๊ฐ์...
https://www.evernote.com/shard/s216/sh/729d1c3c-a639-4464-8af3-1b5d95bc0798/811867530a317d57432dd7c5512bfd91
AWS Beanstalk ๋ฅผ ์ฌ์ฉํ์ฌ ์น ์ดํ๋ฆฌ์ผ์ด์ ๋ฐฐํฌ
1. Beanstalk ๋ ๋ฌด์์ธ๊ฐ?
- AWS Elastic Beanstalk๋ PaaS๋ก์, ์น ์ดํ๋ฆฌ์ผ์ด์ ์ ๋น๋/๋ฐฐํฌํ๋๋ฐ ํ์ํ ํ๊ฒฝ์ ์ ๊ณตํด์ฃผ๋ PaaS ์ด๋ค. ์ด ๋ฟ๋ง ์๋๋ผ, ๋ชจ๋ํฐ๋ง(CloudWatch), ํ์ฅ์ฑ(Auto Scaling)๋ ์๋์ผ๋ก ์ง์ํ๋ค.
- ํ์ฌ Tomcat, IIS, Node.js, Ruby, Python ๋ฑ ์ฌ๋ฌ ์ธ์ด ๋ฐ ํ๊ฒฝ์ผ๋ก ์ ๊ณตํ๊ณ ์๋ค.
2. Beantalk ๋ฅผ ์ด๋ป๊ฒ ์ฌ์ฉํ ์ ์์๊น?
- ์ํ ํ๋ก์ ํธ๋ก์ ์ฌ๊ธฐ์์๋ Java ํ๋ก์ ํธ๋ฅผ ์ฌ์ฉํ์๋ค.
- tomcat ์์ war ํ์ผ์ ๋ฐฐํฌํ ์ ์๋๋ก ๋ชจ๋ ํ๋ซํผ์ ์ ๊ณตํด์ค๋ค๊ณ ๋ณด๋ฉด ๋๋ค.
- ์ค์ ๋ฐฐํฌ๋ ์์ผ๋ก ํด์ผ ํจ!
- maven ์ ์ฌ์ฉํ๊ณ ์์ผ๋ฏ๋ก maven์ war package ์ฌ์ฉ
- maven ์ beanstalk-maven-plugin ์ฌ์ฉํ๋ฉด ์ง์ ๋ฐฐํฌ โ์ค๋นโ ๊ฐ๋ฅ.
2-1. beanstalk ์ค์ ์ ํด๋ณผ๊น?
1) Amazon Command Line Tool ์ฌ์ฉ
2) https://console.aws.amazon.com/elasticbeanstalk/ ์์ ์ฒ๋ฆฌ
์ฌ๊ธฐ์์ ์๊ณ ๊ฐ์ผ ํ ์ฉ์ด ๋ ๊ฐ์ง๋ฅผ ์ง๊ณ ๋์ด๊ฐ๋ค.ย
Application๊ณผ Environment
1. Application์ ๊ฐ๋
- Applicaton์ ๋ชจ๋ ๊ฒ์ ํฌํจํ๋ ๊ฐ๋ ์ด๋ค. ํ๊ฒฝ, ๋ฒ์ , ์ ์ฅ๋ ์ค์ ๋ฑ.
2. Environment
- ๋ฐฐํฌ ๋ฐ ์๋ฒ ๊ตฌ๋์ ์ํด ํ์ํ AWS ์์๋ค์ ํ ๋ฐ ๊ฐ์ผ ๊ฒ(wrapping) ์ด๋ค.
3. Application์ ์ฌ๋ฌ ๊ฐ์ Environment๋ฅผ ๊ฐ์ง ์ ์๋ค.
elastic beanstalk๋ฅผ ์ค์ ํ์์ ๋ ๊ตฌ์กฐ๋.ย
2-2) ์ค์ ๋ฐฉ๋ฒ
- ์ฌ์ค ๋งค๋ด์ผ์ด ๋์ด์ด์ด์ด๋ฌด ์ ๋์ ์์ด์ ๊ตณ์ด ๋ฃ์ ํ์ ์์ง๋ง, ๊ทธ๋๋ ํ๊ตญ๋ง๋ก ์จ๋๋๊ฒ ํจ์ฌ ์ข์ผ๋.
์ฌ๊ธฐ์ ๊ฐ๋จํ ์ค์ ๋ง์ผ๋ก application์ ์์ฑํ ์ ์๋ค. ๋ ์์ธํ ์ต์ ์ ์ ํํ ์๋ ์๋ค.
์ ํ ํ Get Started ๋ฒํผ์ ํด๋ฆญํ๋ฉด ์๋์ ๊ฐ์ด ๋ํ๋๋ค.
์ด๋ฒ ์์ ๋ Tomcat์ ์ ํํ์๋ค. Default๋ก ์ค์น๋๋ ๋ฒ์ ์ Tomcat 7, Java 7์ด๋ค.
์ ํํ๋ฉด ์๋์ ๊ฐ์ ๋์๋ณด๋๊ฐ ๋ํ๋๊ณ , Application์์ ํ์ํ Environment๊ฐ ์์๋๋ก ์์ฑ๋๋ ๊ฑธ ๋ฐ๋ก ํ์ธํ ์ ์๋ค.
์์๋ ์๋์ ๊ฐ๋ค.
1. CloudWatch Alarm ์์ฑ (High/Low)
2. EC2 instance ์์ฑ (default๋ t1.micro)
Load Balancing, auto scaling ๋ฐ 80 port forwarding๋ ์๋์ผ๋ก ์์ฑํด์ฃผ๊ณ ,
applicaiton-name.elasticbeanstalk.com ์ด๋ผ๋ ๋๋ฉ์ธ๋ ์๋ ์์ฑํด์ค์ ์น ์ดํ๋ฆฌ์ผ์ด์ ์ ๋ฐฐํฌํ๋ฉด ๋ฐ๋ก URL๋ก ์ ๊ทผํ ์ ์๋ค.
CloudWatch ์ค์ ๋ฐ EC2 ์ค์ ์ ๊ฐ์ ์๋น์ค console web ์์ ํ๋ฉด ๋๋ค.
Load Balancing, Auto Scaleing ์ค์ ํ์ด์ง๋ beanstalk ์ค์ ํ์ด์ง์ ํฌํจ๋์ด ์๋ค.
3. ๋ฐฐํฌ๋ ์ด๋ป๊ฒ ํ๋ฉด ๋๋๊ฐ?
๋ช ๊ฐ์ง ๋ฐฉ๋ฒ์ด ์๋ค.
1) Amazon Command Line Tool ์ด์ฉ
- http://aws.amazon.com/code/6752709412171743
- PATH์ ๋ฃ๊ณ eb ์ปค๋งจ๋๋ฅผ ์คํํ์ฌ ์ค์ ํ ์ ์๋ค.
2) Console ์น์์ ์ง์ ์ ๋ก๋
- war ํ์ผ ์ง์ ์ ๋ก๋๊ฐ ๊ฐ๋ฅํ๋ค.
3) maven plugin ์ฌ์ฉ
- beanstalk-maven-plugin ์ ์ค์ ํ๋ฉด ๊ฐ๋ฅํ๋ค.
- Amazon Beanstalk API ๋ฅผ wrappingํ maven plugin ์ด๋ค. http://beanstalker.ingenieux.com.br/beanstalk-maven-plugin/
์, ๋ฌผ๋ก ant/grails์์๋ ์ฌ์ฉ ๊ฐ๋ฅํ๋ค.
http://beanstalker.ingenieux.com.br/beanstalk-maven-plugin/dependency-info.html
4. beanstalk-maven-plugin ์ด ์ด๋๊น์ง ์ง์ํด์ฃผ๋๊ฐ?
- ์ฌ์ฉ ๊ฐ๋ฅํ dns ์ด๋ฆ ์ฒดํฌ
- application ์์ฑ/์ ๋ฐ์ดํธ/์ญ์
- environment ์ ๋ฐ์ดํธ
๋ฑ ์ค์ ๋ฟ๋ง ์๋๋ผ ์ค์ ๋ก web application ํ์ผ์ ๋ฐฐํฌํ๋ ๋ฐ ์ฌ์ฉํ๋ ๋ช ๋ น์ด๋ฅผ ์ ๊ณตํ๊ณ ์๋ค.
- upload resource : S3 bucket ์ผ๋ก war ํ์ผ ์ ๋ก๋
- application version ์ ๋ณด ์์ฑ
- environment ์ ๋ฐ์ดํธ
[์ฃผ์] ์ ๋ฐ์ดํธ ๋ ํ๊ฒฝ์ deployํ์ง๋ ์๋๋ค. deploy๋ console์์ ํ๊ฑฐ๋ CLI ๋ฅผ ์ด์ฉํด์ ๋ฐ๋ก ํด์ผํ๋ค.
5. beanstalk-maven-plugin ์ค์ ์์
~/.m2/settings.xml
pom.xml์์ ํด๋ ๋์ง๋ง ๊ถ์ฅํ์ง ์๋๋ค.ย
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
http://maven.apache.org/xsd/settings-1.0.0.xsd">
<profiles>
<profile>
<id>default</id>
<properties>
<aws.accessKey>YOUR_AWS_ACCESS_KEY</aws.accessKey>
<aws.secretKey>YOUR_AWS_SECRET_KEY</aws.secretKey>
</properties>
</profile>
</profiles>
<activeProfiles>
<activeProfile>default</activeProfile>
</activeProfiles>
</settings>
pom.xml
global ์ค์ ๊ณผ plugin ์ค์ ์ด ์๋ค.ย
<properties>
<maven.build.timestamp.format>yyyyMMddHHmmss</maven.build.timestamp.format>
<beanstalk.versionLabel>${maven.build.timestamp}</beanstalk.versionLabel>
</properties>
<plugin>
<groupId>br.com.ingenieux</groupId>
<artifactId>beanstalk-maven-plugin</artifactId>
<version>1.1.1</version>
<configuration>
<applicationName>glance-was-20140113</applicationName>
<cnamePrefix>glance-was-20140113</cnamePrefix><!-- cnamePrefix.elasticbeanstalk.com -->
<environmentName>glanceWas20140113-env</environmentName>
<region>us-west-1</region>
<s3Bucket>elasticbeanstalk-glance-was-20140113</s3Bucket>
<s3Key>${project.artifactId}/${project.build.finalName}-${maven.build.timestamp}.war</s3Key>
</configuration>
</plugin>
6. ์ฌ์ฉ ๋ฐฉ๋ฒ
- mvn beanstalk:upload-source-bundle beanstalk:create-application-version beanstalk:update-environment
- ์ด๋ ๊ฒ ํ๋ฉด ์๋์ ๊ฐ์ด ๋์ํ๋ค.
beanstalk:upload-source-bundle : war upload
beanstalk:create-application-version : ๋ฒ์ ์ ๋ณด ๊ธฐ๋ก
beanstalk:update-environment : ๊ธฐ์กด์ ๋ง๋ค์ด๋์ ํ๊ฒฝ ์ค์
[INFO] [beanstalk:upload-source-bundle {execution: default-cli}]
[INFO] Target Path: s3://elasticbeanstalk-glance-was-20140113/glance/glance-was-snapshot-20140114144704.war
[INFO] Uploading artifact file: /Users/neigie/Dev/works/glance_was/target/glance-was-snapshot.war
100.00% 33 MiB/33 MiB Done
[INFO] Artifact Uploaded
[INFO] [beanstalk:create-application-version {execution: default-cli}]
[INFO] SUCCESS
[INFO] * sourceBundle: {S3Bucket: elasticbeanstalk-glance-was-20140113, S3Key: glance/glance-was-snapshot-20140114144704.war, } [class: S3Location]
[INFO] * versionLabel: 20140114144704 [class: String]
[INFO] * description: Update from beanstalk-maven-plugin [class: String]
[INFO] * applicationName: glance-was-20140113 [class: String]
[INFO] * dateCreated: Tue Jan 14 14:47:32 KST 2014 [class: Date]
[INFO] * dateUpdated: Tue Jan 14 14:47:32 KST 2014 [class: Date]
[INFO] [beanstalk:update-environment {execution: default-cli}]
[INFO] Looking up for glance-was-20140113.elasticbeanstalk.com
[INFO] Will wait until Tue Jan 14 14:49:33 KST 2014 for environment e-3amtfsmdxp to get into !Updating
[INFO] ... as well as having domain glance-was-20140113.elasticbeanstalk.com
[INFO] Environment Detail:com.amazonaws.services.elasticbeanstalk.model.EnvironmentDescription@73c2a0d9[environmentName=glanceWas20140113-env,environmentId=e-3amtfsmdxp,applicationName=glance-was-20140113,versionLabel=20140113125505,solutionStackName=64bit Amazon Linux 2013.09 running Tomcat 7 Java 7,templateName=<null>,description=glanceWas20140113-env,endpointURL=awseb-e-3-AWSEBLoa-1CLLKCE71CTNA-2019779659.us-west-1.elb.amazonaws.com,cNAME=glance-was-20140113.elasticbeanstalk.com,dateCreated=Mon Jan 13 11:47:39 KST 2014,dateUpdated=Tue Jan 14 14:43:08 KST 2014,status=Ready,health=Green,resources=<null>]
[INFO] SUCCESS
์์ฝ
[INFO] * versionLabel: 20140113125505 [class: String]
[INFO] * status: Updating [class: String]
[INFO] * applicationName: glance-was-20140113 [class: String]
[INFO] * endpointURL: awseb-e-3-AWSEBLoa-1CLLKCE71CTNA-2019779659.us-west-1.elb.amazonaws.com [class: String]
[INFO] * health: Grey [class: String]
[INFO] * dateUpdated: Tue Jan 14 14:47:34 KST 2014 [class: Date]
[INFO] * environmentId: e-3amtfsmdxp [class: String]
[INFO] * solutionStackName: 64bit Amazon Linux 2013.09 running Tomcat 7 Java 7 [class: String]
[INFO] * CNAME: glance-was-20140113.elasticbeanstalk.com [class: String]
[INFO] * description: glanceWas20140113-env [class: String]
[INFO] * dateCreated: Mon Jan 13 11:47:39 KST 2014 [class: Date]
[INFO] * environmentName: glanceWas20140113-env [class: String]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๋ฐ์๋ ํ๋ฉด
- ํ๋ฉด์ ๋ณด๋ฉด ์์ ์๋ฏ์ด ํน์ ๋ฒ์ ์ ์ฐ์ด์ deploy ๋ฒํผ์ ๋๋ฅด๋ฉด ๋ฐ์๋๋ค.
- ๋ฐ์๋๋๋ฐ ๋๋ต 5~10๋ถ ์ ๋ ๊ฑธ๋ฆฌ๋ ๋ฏ ํ๋ค.
7. ์ถ๊ฐ๋ก ํ ๊ฒ์ ๋ฌด์์ธ๊ฐ?
- DB๊ฐ ํ์ํ๋ค๋ฉด RDS ๋ฅผ ์์ฑํ๋ฉด ๋๋ค.
- DB์ ๊ฒฝ์ฐ๋ ํ๋ก์ ํธ ๋ณ๋ก ์๋ ์์ดํ์ฌ defaultํ๊ฒฝ์๋ ํฌํจํ์ง ์์๋ค๊ณ ๊ธฐ์ ๋์ด ์๋ค.
- ์ค์ ๋ก auto scaling์ด ๋๋์ง, CloudWatch๋ ๋์ํ๋ ์ง ์๋น์ค๋ฅผ ๊ณ์ ์จ๋ด์ผ ์ ๋ฏ ํ๋ค.
8. ๋๋ฉ์ธ์ ๋น์ฐํ ๋ฐ๊ฟ์ผ ํ ํ ๋ฐ?
- AWS Route 53์ ์จ์ forwarding ๊ฐ๋ฅ.
- http://aws.amazon.com/ko/route53/
http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customdomains.html ์ ๋ ์ ๋์ ์์. ์ด์ฐจํผ ๋๋ ์จ์ผ ํ๋ ๋ ์ฌ๋ฆฌ๊ฒ ์ง๋ง, ์ค์ ์์ ๊ฐ ํ์ํ๋ค๊ณ ํ๋ ์ฌ๋ ๋ง์ผ๋ฉด ๋ ์ฌ๋ฆฌ๋ ๊ฑธ๋ก!










