簡體   English   中英

如何在一個命令中為整個 vpc 或所有區域啟用 GCP 流日志?

[英]How to enable GCP flow logs for entire vpc or all regions in one command?

Bash 命令為整個 VPC 或具有 VPC 的所有區域啟用流日志記錄

簡單的 bash 腳本,用於查詢具有 VPC 的所有區域並循環以啟用流日志記錄

a=( $(gcloud compute networks subnets list --filter="<VPC NAME>" --format="csv(region)")); a=("${a[@]:1}"); for i in "${a[@]}"; do gcloud compute networks subnets update <VPC NAME> --region=$i --enable-flow-logs; done

在大多數情況下,請記住將上面的“VPC NAME”的 2 個實例更改為默認的 VPC 示例名稱

可用於關閉整個 vpc 的流日志記錄以及使用 --no-enable-flow-logging

a=( $(gcloud compute networks subnets list --filter="<VPC NAME>" --format="csv(region)")); a=("${a[@]:1}"); for i in "${a[@]}"; do gcloud compute networks subnets update <VPC NAME> --region=$i --no-enable-flow-logs; done

這是我的嘗試,使用默認 VPC:

gcloud compute networks subnets list | awk '/default/{print$2}' | xargs -I{} gcloud compute networks subnets update default --region={} --enable-flow-logs

我認為您可以將default替換為您的 VPC 名稱。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM