AWS
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Note Insights Sharing URL Help
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # AWS EC2 運算資源 (觀念講解篇) ###### tags: `概論介紹` ## EC2 重點架構 EC2 Instance (EC2 虛擬機) 由許多重要元件組成,我們分成三大部分介紹。 ### ◆ AMI 在一個 EC2 Instance 裡,有一個重要元件叫做 ==**AMI** (Amazon Machine Image)==。 什麼是 AMI: - 最主要的功用為++決定我們的 OS (Operating System) 作業系統++。 - AMI 如同一個模板,當每次在建立 EC2 Instance 時,就要選擇使用何種 AMI。 - 包含許多細部設定,之後會再來討論,這裡先用 TBD (To Be Defined) 標記起來。 ![](https://i.imgur.com/rdwhieq.png =400x) ### ◆ Instance Metadata 當我們啟動一台 Instance 時,會有一些 Instance 層面的資料,裡面包含:Instance ID、Hostname 等。 ![](https://i.imgur.com/Irg0ZfH.png =400x) ### ◆ Instance Type 在 Instance Type 中,我們會去決定 Instance 本身要使用多少資源,包含我們要使用 vCPU、記憶體、儲存空間的多寡。 :::danger Instance Storage 是一個本地的儲存空間,會隨著 EC2 Instance 的更動而改變。 換句話說,若 EC2 Instance 消失,Instance Storage 就會不見,因此不適合放置永久資訊。 ::: 不過 Instance Storage 的好處是: - 它就在 EC2 Instance 上,所以能讓我們進行非常高效率的 I/O 工作。 - 可以決定 Network speed,Network speed 能決定 EC2 Instance 能負荷多少網路流量。 EC2 中還有許多細部設定,一樣先標 TBD。 ![](https://i.imgur.com/MSOw28p.png =400x) ### ◆ EC2 連接的子服務 當我們在 AWS Consol 建立一台 EC2 時,我們會連接許多子服務。 - **Network 網路** 我們會配給 EC2 一個或多個虛擬網卡 (ENI),而 EC2 Instance 在 AWS 網路架構中的角色是由 ENI 來決定。 如下圖,我們必須看 ENI 在哪個 SG (Security Group) 、哪個 Subnet,以及被哪個 NACL 所管控。 > [NACL 及 SC 相關介紹](https://hackmd.io/ZP5kM8BgSr-se5JNBp1UtQ#%E2%97%86-NACL-vs-SG-%E7%9A%84%E5%AE%89%E5%85%A8%E8%A8%AD%E5%AE%9A%E4%BB%8B%E7%B4%B9) ![](https://i.imgur.com/gcZtaNg.png =500x) - **Permission 權限** 在 AWS 中,管理權限有個重要元件 ==**IAM Role**==。 IAM Role 並不能直接被 EC2 Instance 給使用,因此需要一個銜接角色來串接,也就是 ==**Instance Profile**==,如下圖: Instance Profile 會將 IAM Role 轉換為 EC2 Instance 可以使用的形式,來管控 EC2 Instance 可以使用哪種權限及 AWS 服務。 ![](https://i.imgur.com/SJKaWSK.png =500x) - **External Storage** ==External Storage== 是一個外接的儲存空間。 服務名稱叫做 ==**EBS Volume** (Elastic Block Storage Volume)==。 有別於 Instance Storage,EBS Volume 並不會隨者 EC2 Instance 的消失而不見,因此適合放置永久資料。 ![](https://i.imgur.com/3sQLjz2.png =500x) :::info <h2>小結</h2> EC2 主體實際上只有下圖紅框圈起來的部分,右側都是可以連結的子系統們。 EC2 必須透過與這些服務的連結才能建出一個完整的虛擬機功能。 ::: ![](https://i.imgur.com/3VT3Hin.png =500x) --- ## EC2 儲存資源 Instance Store vs Elastic Block Storage (EBS) ### ◆ EC2 Instance 與 EBS Volume 的關係介紹 在 EC2 Instance 中,有個 Instance Storage,他們會在同一個 Host 主機上。 我們可以透過網路連結到另外的外部硬碟空間 EBS Volume (Elastic Block Storage)。 EC2 Instance 與 EBS Volume 會在同一個 AZ 中,如下圖: ![](https://i.imgur.com/HTZk6ID.png =500x) EBS Volume 可以備份,而 AWS 提供的備份功能叫做 ==EBS Snapshot==。 EBS Snapshot 有個特點,它會進行漸進式的備份 (==backup==),也就是說,已備份的部分不會重複備份,只會針對新的部分備份,這種漸進式的方法稱作 ==Incremental==。 另外, EBS Snapshot 會與 EC2 Instance 在同一個 Region 中。 EC2 Instance、EBS Volume、EBS Snapshot 三者的關係如下圖: ![](https://i.imgur.com/P7MLZp0.png =500x) ### ◆ EBS 與 Instance Storage 的優缺點比較 - Instance Storage - 優點: - High I/O 由於 Instance Storage 跟 EC2 Instance 在同一個 Host 中,因此具有很好的 I/O 處理能力。 - 缺點: - Ephemeral,短暫存在 當 EC2 Instance 被刪除時,Instance Storage 的資料也會全部消失。 - No Backup 當主機儲存硬碟故障時,資料因為沒有備份,所以也會跟著消失。 換句話說,它的耐久性非常低,不適合存放長久資料。 - EBS - 優點 - Persistent EBS Volume 的生命週期與 EC2 的出現消失無關,即使 EC2 被砍掉,EBS Volume 的資料也不會消失 - Backup 當創造 EBS Volume 時,在背後的 AZ 中,AWS 會幫忙建立多台儲存設備,簡稱 ==Nodes==,來組成 EBS Volume,就算一個硬碟故障,資料仍完整保存,提供較高的耐久性。 另外,還有 EBS Snapshot 來保護資料,就算 AZ 所有資料中心都無法使用,資料仍會保存在同一個 Region 下的 EBS Snapshot。 - 缺點 - Lower I/O 由於 EBS 和 EC2 之間連通內部網路會造成時間消耗,因此 I/O 處理能力較低 Instance Storage 與 EBS 優缺點比較圖: ![](https://i.imgur.com/qCZOjkn.png =700x) :::info <h2>小結</h2> 相較於 Instance Storage,更常使用 EBS 儲存,因為 EBS 提供較高的 Durability。 雖然 EBS 存在 lower I/O 的問題,但 AWS 提供我們許多不同的 EBS Type 來解決這個問題,之後會再詳細說明。 ::: ## EC2 儲存資源 EBS Types 方案比較 AWS 提供以下四種 EBS Types,讓我們根據 I/O 需求來做選擇,改善 lower I/O 的問題: 1. io1 2. gp2 3. st1 4. sc1 ### ◆ SSD 與 HDD 與四種 EBS Types ![](https://i.imgur.com/EweHWaF.png =500x) - SSD 下含有 io1 與 gp2 兩種類別 - HDD 下含有 st1 與 sc1 兩種類別 各類別的數據比較: ![](https://i.imgur.com/4YEO2w8.png =500x) - Max Storage:最大容量都是 16TB - I/O:Input / Output 的簡寫,用來評量檔案讀寫的速度效能 - IOPS:I/O Per Second,每秒可處理的 I/O 請求次數 - IO Packet Size:指的是每次處理一個 I/O 請求時,一個 Package 的大小。 - Throughput:「*每秒可以處理的 I/O 資料總量*」,Throughput = IOPS * I/O Packet Size - Cost:這邊以相對的數值來建立數字級距的概念,以處理一單位資料的花費,以 $ 當作比較符號 > 關於 IO Packet Size: > > SSD 底下兩個 Type 的 Packet Size 只有 16 KB,HDD 底下兩個 Type 的則有 1MB > > 主要是因為在 SSD 底下,是針對「*次數高但量小的使用情境*」 > 而 HDD 則是處理「*次數少但量大的狀況*」 ### ◆ 比較數值意義 <h3>HDD</h3> 最重要的數值是 Throughput,st1 處理 500MB/s,sc1 處理 250MB/s,勝過 gp2。 雖然 io1 可以達到 1000MB/s,但是花費成本也是最高的,因此並非最佳選擇。 sc1 的花費最低,又可以達到 250MB/s,算是較經濟實惠的選擇。 gp2 需花 4 倍的花費才能達到 sc1 的 Throughput,因此也不划算。 :::success 因此當我們要使用 HDD 底下的 Type 時,必須特別注意 Throughput 和 Cost 兩個數值。 ::: ![](https://i.imgur.com/YK4JUsB.png =500x) <h3>SSD</h3> 底下兩個 Type 都是以 IOPS 為主要數值,雖然比 HDD 貴很多,但是相對它的 IOPS 也高出非常多。 :::success 所以當我們使用 SSD 底下的 Type 時,就是願意花大錢買很高的 IOPS。 ::: <h3>四個 Type 適用情境</h3> - ==io1== - 建議使用於 EC2 上有建立「***資料庫***」的情況,因為在資料庫處理中的 CRUD,可能都是資料小但請求次數多的狀況。 - ==gp2== - 建議使用於「***開機硬碟***」,AWS 建議大家使用的預設硬碟選擇,可使開機速度快,費用也不像 io1 那麼貴。 - ==st1== - 建議使用於「***影音串流***」,影音串流的請求頻率不高,但每次都是幾 GB 的容量。 - ==sc1== - 建議使用於「***資料封存***」的情況,因為使用資料的頻率非常低,保存成本也不高。 ![](https://i.imgur.com/rUO7vkj.png =500x) <h3>EBS 效能</h3> SSD 最強的效能是 IOPS,HDD 則是 Throughput。 決定最後 EBS 可以得到的效能是由兩種要件組成的: 1. EBS Type 之間不同的效能 2. EBS Volume 被 attach 到一台 EC2 Instance 上時,那台 Instance 的 EC2 Type 也會影響最後 EBS Volume 的效能 參考下圖,儘管左邊 EBS type 效能高,但終究還是會被右邊 EC2 Type 最高效能給拉下來,最後取得兩者的交集。 ![](https://i.imgur.com/3h6C98c.png =500x) :::info <h2>小結</h2> 1. HDD 底下的 st1 和 sc1 是「**便宜大流量**」 2. SSD 底下的 io1 和 gp2 是「**高貴快手速**」 ::: ![](https://i.imgur.com/WrcvwaP.png =500x) > 參考網站: > [Day 9 運算寶石:EC2 重點架構](https://ithelp.ithome.com.tw/articles/10263305) > [Day 10 運算寶石:EC2 儲存資源 Instance Store vs Elastic Block Storage (EBS)](https://ithelp.ithome.com.tw/articles/10264261) > [Day 11 運算寶石:EC2 儲存資源 EBS Types 方案比較](https://ithelp.ithome.com.tw/articles/10264904)

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully