EC2 与最小网络安全组合
High Contrast
Dark Mode
Light Mode
Sepia
Forest
2 min read446 words

EC2 与最小网络安全组合

你在本地或其他平台已经熟悉的那套 Ubuntu 运维方式,迁到 AWS 后只需要找到对应的服务名。最小落地组合是:EC2 + Security Group + EBS + IAM Role

最小组合图

graph LR A[Internet] --> B[Security Group] B --> C[EC2 Ubuntu] C --> D[EBS 数据盘] C --> E[IAM Role] E --> F[S3 / CloudWatch 等 AWS 服务]

组件对应关系

你熟悉的概念 AWS 服务 说明
虚拟机 EC2 可选 t3.micro(免费套餐)起步
防火墙规则 Security Group 无状态但默认拒绝,须显式开放
持久化磁盘 EBS 实例停止后数据保留,可独立快照
实例角色身份 IAM Role 避免把 Access Key 直接放进机器

用 AWS CLI 创建基础环境

# 启动一台 Ubuntu 22.04 EC2(先在控制台找到 AMI ID,如 ami-0c02fb55956c7d316)
aws ec2 run-instances \
--image-id ami-0c02fb55956c7d316 \
--instance-type t3.micro \
--key-name my-keypair \
--security-group-ids sg-xxxxxxxx \
--iam-instance-profile Name=my-ec2-role \
--count 1
# 创建最小 Security Group
aws ec2 create-security-group \
--group-name myapp-sg \
--description "myapp minimal sg"
# 仅开放 SSH 给可信 IP,80/443 对外开放
aws ec2 authorize-security-group-ingress \
--group-id sg-xxxxxxxx \
--protocol tcp --port 22 --cidr 203.0.113.0/32
aws ec2 authorize-security-group-ingress \
--group-id sg-xxxxxxxx \
--protocol tcp --port 80 --cidr 0.0.0.0/0
aws ec2 authorize-security-group-ingress \
--group-id sg-xxxxxxxx \
--protocol tcp --port 443 --cidr 0.0.0.0/0

最小安全原则

常见误区

本节执行清单

下一节ALB、Route 53、S3、CloudWatch 落地——继续补齐入口、存储和观测。