跳至主要内容

EC2 Over View

Elastic Compute Cloud,是一個 Infrastructure as a Service 服務。
主要的功能:

  • 租一台虛擬機 (EC2)
  • 在虛擬裝置中儲存資料 (EBS)
  • 分散 Loading (ELB)
  • 用 auto-scaling group 擴大服務 (ASG)

EC2 可選配置​

  • OS: Linux、MacOS、Windows
  • CPU
  • RAM
  • 儲存空間:
    • 網路依存 (EBS & EFS)
    • 硬體 (EC2 Instance Store)
  • 網路卡: 速度(speed)、Public IP 位址
  • 防火牆規則: 安全組(security group)

EC2 User Data Script​

EC2 User Data Script 會在機器啟動時運行,而且只會在這個 instance 第一次被啟動時運行。通常會被用來進行安裝更新、安裝軟體、從網路上下載一些檔案等等。

EC2 User Data Script 會由 root user 運行

EC2 InstanceTypes​

針對不同用途,AWS有提供不同的 Instance type:https://aws.amazon.com/ec2/instance-types/

命名規則會是

m5.2xlarge
• m: instance class
• 5: generation (AWS improves them over time)
• 2xlarge: size within the instance class

選用 Instance Type 時,要在運算、Memory 以及 Networking 中取得最合適的平衡

  • 運算優先,適用於對於運算的要求較高的場景

    • Batch processing workloads
    • Media transcoding
    • High performance web servers
    • High performance computing (HPC)
    • Scientific modeling & machine learning
    • Dedicated gaming servers
  • Memory 優先,在大的 Data Set 中可以有比較快的 performance

    • High performance, relational/non-relational databases
    • Distributed web scale cache stores
    • In-memory databases optimized for BI (business intelligence)
    • Applications performing real-time processing of big unstructured data
  • Storage 優先,適用於需要對本地儲存上的大型資料集進行高、順序讀寫訪問的儲存密集型任務

    • High frequency online transaction processing (OLTP) systems
    • Relational & NoSQL databases
    • Cache for in-memory databases (for example, Redis)
    • Data warehousing applications
    • Distributed file systems

EC2 中的共享職責​

AWS 負責​

  • Infrastructure (global network security)
  • 物理主機的獨立性
  • 硬體設備更換
  • 驗證 Compliance

使用者 負責​

  • 訂定 Security Groups
  • 在 EC2 instance 中管理 Operating-system 補丁及安裝軟體和 utilies
  • 設定 IAM Roles 給和 IAM user 來管理連線
  • instance 中的資料安全

Security Group​

安全組(Security Groups)是 AWS 網路安全的基礎,我們可以透過設定安全組限制可以連到我們的 EC2 instance 的連線。 安全組只包含允許(Allow),規則中可以選擇參照 IP 或者參照其他安全組。

安全組篩選方式​

安全組是一個在 EC2 之外的工具,也就是說,如果在一個連線被安全組攔阻了,那麼中 EC2 就不會看到這個連線。

被安全組擋下的連線會顯示 time out,相對於這個狀況,如果是 application error 或者 Server 沒有運行,則會顯示為 connection refused。

預設情況下,所有進站連線(inbound traffic)都會被設定為拒絕,必須透過安全組允許。

安全組可以選擇允許:

  • 可連線的 Ports
  • 允許的 IP 範圍 – 如 IPv4 或者 IPv6
  • 限制進入 instance 的連線
  • 限制從 instance 出去的連線

預設情況下,所有出站連線(inbound traffic)都會被設定為允許。 同一個安全組可被設定給不同的 instance,安全組會被鎖定到區域/VPC組合。另外,為 SSH 連線設定一個單獨的安全組是件好事。

Classic Ports​

  • 22 = SSH (Secure Shell) - 用來 log In 到 Linux Instance 中
  • 21 = FTP (File Transfer Protocol) 上傳檔案
  • 22 = SFTP (Secure File Transfer Protocol) – 使用 SSH 上傳檔案
  • 80 = HTTP
  • 443 = HTTPS
  • 3389 = RDP (Remote Desktop Protocol) – 用來 log In 到 Windows Instance 中