如何無痛上雲端?
以Elastic Beanstalk Java Container為例
!

Study Hsueh <ph.study@gmail.com>
2013-11-07

!1
上雲端
Deploy application to VPS (Virtual Private Server)
or

Cloud Web Application
!2
Cloud Web Application
Web Application is powered by cloud computing

Elasticity: 能隨時主動增加或刪減資源
Scalability: 資源的增減直接反應到負載上
R...
Cloud Web Application
Architecture for Web Application Hosting

!4

http://media.amazonwebservices.com/architecturecenter/...
Cloud Web Application
Build a cloud web application in AWS, you may need to know…

}

Elastic Load Balancing (ELB)
Auto Sc...
有沒有簡單⼀一點的⽅方法上雲端?

!6
有!
⽤用PaaS吧!

PaaS: Platform as a Service
!7
可是聽說PaaS....
White List
Black Box
Platform Dependent Services/Libraries
Software Versions
…etc
!8
試試Elastic Beanstalk吧:)

!9
Elastic Beanstalk (EB)
Elastic Beanstalk是架構在AWS infrastructure
上的PaaS服務, 使⽤用Elastic Beanstalk可以同
時具備控制底層IaaS的能⼒力與PaaS的便利
E...
Elastic Beanstalk

!11
Concept(1)
Elastic Beanstalk
Application
Environment

URL(CNAME)

!12
Concept(2)
Applications
Environments
URL

!13
Supported Platforms

!14
Java Container
OS: x32/x64 Amazon Linux (2012.09)
Java: OpenJdk 1.6.0_24
Web Container: T
omcat 6.0.35 & 7.0.27

!15
Customization

!16
Elastic Beanstalk可以裝第三⽅方的程式嗎?
像是phantomjs, imagemagick…之類
或把T
omcat換成T
omEE?

!17
Customizing Environment
Elastic Beanstalk provides two mechanisms to
customize environment
Custom AMI
Configuration File (O...
Configuration File(1)
Configuration File in WAR file

!19
Configuration File(2)
Configuration File Example
YAML format

!20
Deployment

!21
AWS Management Console
Upload WAR file

!22
AWS T
oolkit for Eclipse

!23
Command-line interface
$ git init

# init git repository


$ eb init

# init EB Application Configuration


$ eb start

# s...
Deploying with Zero Downtime
Swap Environments URLs (CNAMEs)
It usually takes 2-3 minutes to swap

!25
Management

!26
Application versions

!27
Monitoring

!28
Health Check
EC2 Instance
TCP:80 for nonlegacy containers
HTTP:80 for legacy containers
Application health check URL
HTTP ...
Usage

!30
Processes
Use Monit to monitor processes
Apache HTTP Server
Apache T
omcat

!31
Pricing

!32
Pricing
Elastic Beanstalk is free, you only pay for the underlying
AWS resources
Single-instance T
ype
EC2 instance
Load-b...
準備好上雲端了嗎?
Cloud Ready?

!34
如果程式有⽤用到下列其中⼀一個...
HTTP Session
File System
User Data Storage
File Cache

!35
對不起!還不能上雲端:-(

!36
HTTP Session Problem

!37
HTTP Session Problem(1)
Server#1

Server#2

Session

Session

ABAB

CDCD

table

table

User#1

User#2

JSESSIONID: CDCD

...
HTTP Session Problem(2)
Server#1

Server#2

Session

Session

table

table

ABAB

CDCD

Load Balancer 


Invalid Session

...
Solutions for HTTP Session
改程式的做法
Keep Stateless (use access token)
不改程式的做法
Session Persistence
Sticky Sessions (Not worki...
Sticky Sessions Problem(1)
Server#1

Server#2

Session

Session

ABAB

CDCD

table

table

Load Balancer 


Server

Sessio...
Sticky Sessions Problem(2)
Server#1

Server#2

Session

Scale in or

Server Failure

table

ABAB

Invalid Session

Server
...
Session Persistence
Shared Session
table

Server#1

ABAB
CDCD

User#1

Server#2

User#2

JSESSIONID: CDCD

JSESSIONID: ABA...
Session Managers for T
omcat
PersistentManager (JDBC Based Store)
http://tomcat.apache.org/tomcat-7.0-doc/config/manager.ht...
Session Managers for T
omcat
Q. 為什麼不使⽤用DeltaManager或
BackupManager呢? (in-memory-replication)
A. EC2不⽀支援multicast與boardcast...
File System Problem

!46
User Data Storage Problem(1)
Server#1

Server#2

File#2

File#1

User#1

User#2

Upload File#1

Upload File#2
!47
Solutions for User Data Storage(1)
Use FS for User Data Storage
改程式的做法
透過AWS SDK把檔案的存取改到S3
不改程式的做法
⽤用S3FS或NFS

!48
使⽤用S3FS需注意的地⽅方
流量
上傳: 檔案會先上傳⾄至Server, 在由Server寫⼊入S3
下載: 檔案需先由S3取出到Server, 在回傳給User
負載
無法降低Server負載
安全性
敏感的資料: 避免直接對外
⼀一般資料...
Solutions for File Cache
Use FS for File Cache
改程式的做法
將file cache改存⾄至DB或Cache Clusters
不改程式的做法
?

!50
可以⽤用S3FS做File Cache嗎?
S3不適合儲存File Cache
Latency
Read-After-Write Consistency
Eventually Consistency (US Standard
Region)
!...
Summary
Elastic Beanstalk is PaaS, but you retain full
control over the underlying infrastructure
Elastic Beanstalk is Fre...
Thanks for your attention:)

!53
Upcoming SlideShare
Loading in...5
×

如何無痛上雲端? 以Elastic Beanstalk Java Container為例

1,784

Published on

Published in: Technology
0 Comments
10 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,784
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
20
Comments
0
Likes
10
Embeds 0
No embeds

No notes for slide

如何無痛上雲端? 以Elastic Beanstalk Java Container為例

  1. 1. 如何無痛上雲端? 以Elastic Beanstalk Java Container為例 ! Study Hsueh <ph.study@gmail.com> 2013-11-07 !1
  2. 2. 上雲端 Deploy application to VPS (Virtual Private Server) or Cloud Web Application !2
  3. 3. Cloud Web Application Web Application is powered by cloud computing Elasticity: 能隨時主動增加或刪減資源 Scalability: 資源的增減直接反應到負載上 Reliability: 應⽤用程式不會因為部分故障, 就無 法提供服務 !3
  4. 4. Cloud Web Application Architecture for Web Application Hosting !4 http://media.amazonwebservices.com/architecturecenter/AWS_ac_ra_web_01.pdf
  5. 5. Cloud Web Application Build a cloud web application in AWS, you may need to know… } Elastic Load Balancing (ELB) Auto Scaling Cloud Watch Elastic Compute Cloud (EC2) Deployment Management Monitoring !5 Infrastructure
  6. 6. 有沒有簡單⼀一點的⽅方法上雲端? !6
  7. 7. 有! ⽤用PaaS吧! PaaS: Platform as a Service !7
  8. 8. 可是聽說PaaS.... White List Black Box Platform Dependent Services/Libraries Software Versions …etc !8
  9. 9. 試試Elastic Beanstalk吧:) !9
  10. 10. Elastic Beanstalk (EB) Elastic Beanstalk是架構在AWS infrastructure 上的PaaS服務, 使⽤用Elastic Beanstalk可以同 時具備控制底層IaaS的能⼒力與PaaS的便利 Elastic Beanstalk的縮寫是EB (不是EBS, EBS是Elastic Block Store的縮寫) !10
  11. 11. Elastic Beanstalk !11
  12. 12. Concept(1) Elastic Beanstalk Application Environment URL(CNAME) !12
  13. 13. Concept(2) Applications Environments URL !13
  14. 14. Supported Platforms !14
  15. 15. Java Container OS: x32/x64 Amazon Linux (2012.09) Java: OpenJdk 1.6.0_24 Web Container: T omcat 6.0.35 & 7.0.27 !15
  16. 16. Customization !16
  17. 17. Elastic Beanstalk可以裝第三⽅方的程式嗎? 像是phantomjs, imagemagick…之類 或把T omcat換成T omEE? !17
  18. 18. Customizing Environment Elastic Beanstalk provides two mechanisms to customize environment Custom AMI Configuration File (Oct 2. 2012) including AWS resources (e.g. ElastiCache) !18
  19. 19. Configuration File(1) Configuration File in WAR file !19
  20. 20. Configuration File(2) Configuration File Example YAML format !20
  21. 21. Deployment !21
  22. 22. AWS Management Console Upload WAR file !22
  23. 23. AWS T oolkit for Eclipse !23
  24. 24. Command-line interface $ git init # init git repository
 $ eb init # init EB Application Configuration
 $ eb start # start EB Environment
 $ git add . # track all files
 $ git commit -m “Initial Commit” # commit
 $ git aws.push # push to EB !24
  25. 25. Deploying with Zero Downtime Swap Environments URLs (CNAMEs) It usually takes 2-3 minutes to swap !25
  26. 26. Management !26
  27. 27. Application versions !27
  28. 28. Monitoring !28
  29. 29. Health Check EC2 Instance TCP:80 for nonlegacy containers HTTP:80 for legacy containers Application health check URL HTTP 200 OK= Health !29
  30. 30. Usage !30
  31. 31. Processes Use Monit to monitor processes Apache HTTP Server Apache T omcat !31
  32. 32. Pricing !32
  33. 33. Pricing Elastic Beanstalk is free, you only pay for the underlying AWS resources Single-instance T ype EC2 instance Load-balancing, Autoscaling T ype EC2 instance(s) Elastic Load Balancing !33
  34. 34. 準備好上雲端了嗎? Cloud Ready? !34
  35. 35. 如果程式有⽤用到下列其中⼀一個... HTTP Session File System User Data Storage File Cache !35
  36. 36. 對不起!還不能上雲端:-( !36
  37. 37. HTTP Session Problem !37
  38. 38. HTTP Session Problem(1) Server#1 Server#2 Session Session ABAB CDCD table table User#1 User#2 JSESSIONID: CDCD JSESSIONID: ABAB !38
  39. 39. HTTP Session Problem(2) Server#1 Server#2 Session Session table table ABAB CDCD Load Balancer 
 Invalid Session uses Round Robin for Server#2 redirect User#1 User#2 JSESSIONID: CDCD JSESSIONID: ABAB !39
  40. 40. Solutions for HTTP Session 改程式的做法 Keep Stateless (use access token) 不改程式的做法 Session Persistence Sticky Sessions (Not working for Auto Scaling) !40
  41. 41. Sticky Sessions Problem(1) Server#1 Server#2 Session Session ABAB CDCD table table Load Balancer 
 Server Session enables Sticky Sessions Server#1 ABAB Server#2 CDCD User#1 User#2 JSESSIONID: CDCD JSESSIONID: ABAB !41
  42. 42. Sticky Sessions Problem(2) Server#1 Server#2 Session Scale in or
 Server Failure table ABAB Invalid Session Server Session for Server#1 Server#1 ABAB Server#2 CDCD User#1 User#2 JSESSIONID: CDCD JSESSIONID: ABAB !42
  43. 43. Session Persistence Shared Session table Server#1 ABAB CDCD User#1 Server#2 User#2 JSESSIONID: CDCD JSESSIONID: ABAB !43
  44. 44. Session Managers for T omcat PersistentManager (JDBC Based Store) http://tomcat.apache.org/tomcat-7.0-doc/config/manager.html#Nested_Components Memcached Session Manager http://code.google.com/p/memcached-session-manager Redis Session Manager https://github.com/jcoleman/tomcat-redis-session-manager Amazon DynamoDB Session Manager https://github.com/aws/aws-dynamodb-session-tomcat/ !44
  45. 45. Session Managers for T omcat Q. 為什麼不使⽤用DeltaManager或 BackupManager呢? (in-memory-replication) A. EC2不⽀支援multicast與boardcast (不完全⽀支 援) !45
  46. 46. File System Problem !46
  47. 47. User Data Storage Problem(1) Server#1 Server#2 File#2 File#1 User#1 User#2 Upload File#1 Upload File#2 !47
  48. 48. Solutions for User Data Storage(1) Use FS for User Data Storage 改程式的做法 透過AWS SDK把檔案的存取改到S3 不改程式的做法 ⽤用S3FS或NFS !48
  49. 49. 使⽤用S3FS需注意的地⽅方 流量 上傳: 檔案會先上傳⾄至Server, 在由Server寫⼊入S3 下載: 檔案需先由S3取出到Server, 在回傳給User 負載 無法降低Server負載 安全性 敏感的資料: 避免直接對外 ⼀一般資料: 直接把網址對外, 可降低負載與下載流量 !49
  50. 50. Solutions for File Cache Use FS for File Cache 改程式的做法 將file cache改存⾄至DB或Cache Clusters 不改程式的做法 ? !50
  51. 51. 可以⽤用S3FS做File Cache嗎? S3不適合儲存File Cache Latency Read-After-Write Consistency Eventually Consistency (US Standard Region) !51
  52. 52. Summary Elastic Beanstalk is PaaS, but you retain full control over the underlying infrastructure Elastic Beanstalk is Free For Scalability, you should pay attention to HTTP Session File System !52
  53. 53. Thanks for your attention:) !53
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×