Bỏ qua tới nội dung
CloudDojo
Phần 5/6 · 5 phút

Vá EC2 instance bằng Patch Manager và Maintenance Windows

0/5
Từ khóa của phần nàyChọn một từ để xem nghĩa trước khi đọc

Với hàng trăm EC2 instance, việc vá và chạy lệnh thủ công trên từng instance không còn khả thi; cần thực hiện đồng loạt trên các managed node, theo lịch và có kiểm soát.

MFTECH có hơn 200 EC2 instance; mỗi tháng đều có bản vá bảo mật cho hệ điều hành. Systems Manager thực hiện việc này thông qua SSM Agent chạy trên instance: Patch Manager vá theo lịch, Run Command thực thi lệnh trên cả nhóm instance, Automation thực thi runbook nhiều bước. Bước đầu tiên là cấp quyền để agent giao tiếp với Systems Manager. Các instance đã có IAM role riêng để truy cập RDS và Secrets Manager:

Phương án
Systems ManagerPatch Manager200 EC2role ứng dụng: RDS, Secretskhông tập trung
Cài agent, cron trên từng instance · Nhiều thao tác hoặc gây gián đoạn ứng dụngMỗi instance tự vá theo lịch riêng, 200 lịch cron phải được theo dõi thủ công. Không xác định được instance nào đã được vá và instance nào chưa.

Cách cấp quyền theo từng instance vẫn được hỗ trợ: gắn managed policy AmazonSSMManagedInstanceCore vào role mà instance profile đang dùng (có thể thêm vào role hiện có, không cần thay role). Systems Manager khuyến nghị cấp quyền ở cấp account bằng Default Host Management Configuration khi điều kiện cho phép, vì không phải sửa từng role. Sau khi bật, instance có thể mất tới 30 phút để dùng thông tin xác thực của role mặc định, và cấu hình phải được bật riêng ở từng Region.

Trong đợt vá trước, mọi bản vá đều báo thành công nhưng người dùng vẫn gặp lỗi và timeout, do instance reboot trong khi ALB vẫn tiếp tục định tuyến request tới. So sánh hai phương án vá trong cùng một Maintenance Window:

Phương án vá
Maintenance Window · CN 02:00 · 1 instance/lượt01:59AWS-RunPatchBaselineNgười dùngALBtarget group webi-web1đang phục vụ requesti-web2đang phục vụ requesti-web3đang phục vụ request

Chọn phương án vá, sau đó chọn Mở Maintenance Window. Người dùng vẫn mua hàng lúc 2h sáng.

Xem Systems Manager nhận quyền quản lý 200 nhà máy, rồi vá từng nhà máy trong khung bảo trì mà khách không gặp lỗi.
Ghi nhớ:
  • Quản lý mọi EC2 instance bằng Systems Manager mà không cần tạo instance profile: Default Host Management Configuration (yêu cầu IMDSv2, SSM Agent 3.2.582.0 trở lên).
  • Cấp quyền theo từng instance: thêm AmazonSSMManagedInstanceCore vào role hiện có (mỗi instance profile chỉ chứa một role).
  • Hybrid activation chỉ dành cho máy không phải EC2.
  • Vá instance phía sau load balancer: Automation runbook AWSEC2-PatchLoadBalancerInstance (gỡ khỏi load balancer hoặc target group, chờ connection draining, chạy AWS-RunPatchBaseline, gắn lại), thực thi trong Maintenance Window.
Part 5/6 · 5 phút

Patching EC2 instances with Patch Manager and Maintenance Windows

0/5
Từ khóa của phần nàyChọn một từ để xem nghĩa trước khi đọc

With hundreds of EC2 instances, patching and running commands by hand on each instance is no longer feasible; the work must run in bulk across managed nodes, on a schedule and under control.

MFTECH has more than 200 EC2 instances; every month brings security patches for the operating system. Systems Manager does this through the SSM Agent running on the instances: Patch Manager patches on a schedule, Run Command runs commands on a whole group of instances, Automation runs multi-step runbooks. The first step is to grant the agent permission to communicate with Systems Manager. The instances already have their own IAM role to access RDS and Secrets Manager:

Phương án
Systems ManagerPatch Manager200 EC2app role: RDS, Secretsnot centralized
Install the agent, cron on each instance · Many steps or application disruptionEach instance patches itself on its own schedule, and 200 cron schedules must be tracked manually. There is no way to tell which instances have been patched and which have not.

Granting permissions per instance is still supported: attach the AmazonSSMManagedInstanceCore managed policy to the role that the instance profile uses (it can be added to the existing role; the role does not need to be replaced). Systems Manager recommends granting access at the account level with Default Host Management Configuration when the use case allows, because no role has to be edited. After it is turned on, instances can take up to 30 minutes to use the credentials of the default role, and the setting must be turned on in each Region.

In the previous patch cycle, every patch reported success but users still saw errors and timeouts, because instances rebooted while the ALB kept routing requests to them. Compare two patching approaches in the same Maintenance Window:

Phương án vá
Maintenance Window · CN 02:00 · 1 instance/lượt01:59AWS-RunPatchBaselineNgười dùngALBtarget group webi-web1đang phục vụ requesti-web2đang phục vụ requesti-web3đang phục vụ request

Chọn phương án vá, sau đó chọn Mở Maintenance Window. Người dùng vẫn mua hàng lúc 2h sáng.

Xem Systems Manager nhận quyền quản lý 200 nhà máy, rồi vá từng nhà máy trong khung bảo trì mà khách không gặp lỗi.
Ghi nhớ:
  • Manage every EC2 instance with Systems Manager without creating instance profiles: Default Host Management Configuration (requires IMDSv2, SSM Agent 3.2.582.0 or later).
  • Per-instance permissions: add AmazonSSMManagedInstanceCore to the existing role (an instance profile contains only one role).
  • Hybrid activations are only for non-EC2 machines.
  • Patch instances behind a load balancer: the Automation runbook AWSEC2-PatchLoadBalancerInstance (removes the instance from the load balancer or target group, waits for connection draining, runs AWS-RunPatchBaseline, reattaches it), run in a Maintenance Window.

Kiểm tra nhanh

Trả lời để ghi nhận đã đọc phần này. Câu trả lời sai sẽ được nhắc ôn lại vào những ngày sau.

200 EC2 instance đã có IAM role riêng để truy cập RDS và Secrets Manager. MFTECH muốn Systems Manager quản lý và vá chúng mà không phải tạo hay thay instance profile. Chọn gì?
Trong đợt vá trước, instance reboot trong khi ALB vẫn định tuyến request tới nên người dùng gặp lỗi. Cách vá nào phù hợp?

Đã trả lời 0/2 câu