以下の内容はhttps://htn20190109.hatenablog.com/entry/2024/11/10/220453より取得しました。


{GCP Cloud Logging}サポートされている宛先にログをルーティングする

 

 

https://cloud.google.com/logging/docs/export/configure_export_v2?hl=ja

 


シンクを作成するときは、シンクのサービス アカウントに適切なエクスポート先の権限が付与されている必要があります。

 


-- 1. 前作業

gcloud init
gcloud auth list

gcloud --version

gcloud projects create project01-9999999 \
--name="project01"

gcloud config list
gcloud config set project project01-9999999
gcloud config set compute/region asia-northeast1 --quiet
gcloud config set compute/zone asia-northeast1-a --quiet

 

gcloud beta billing accounts list
gcloud beta billing projects link project01-9999999 --billing-account=111111-111111-111111

gcloud services enable compute.googleapis.com --project project01-9999999

 

-- 2. Cloud Logging API を有効化

gcloud services list --enabled


gcloud services enable logging.googleapis.com \
--project project01-9999999


-- 3. BigQueryデータセットを作成する

bq mk ds01

bq ls

 

 

-- 4. シンクを作成


gcloud logging sinks create sink01 \
bigquery.googleapis.com/projects/project01-9999999/datasets/ds01 \
--description="sink01" \
--use-partitioned-tables 

 

gcloud logging sinks list 

gcloud logging sinks describe sink01

 


-- 5. サービス アカウントへの権限付与


Please remember to grant `serviceAccount:service-111111111111@gcp-sa-logging.iam.gserviceaccount.com` the BigQuery Data Editor role on the dataset.


gcloud projects add-iam-policy-binding project01-9999999 \
--member="serviceAccount:service-111111111111@gcp-sa-logging.iam.gserviceaccount.com" \
--role="roles/bigquery.dataEditor"

gcloud projects get-iam-policy project01-9999999

 


-- 6. BigQuery にルーティングされたログを表示する

gcloud logging write my-test-log "A simple entry." --severity=ALERT

gcloud logging write my-test-log "A simple entry." 


ルーティング開始されるまでしばらく時間がかかる

 

-- 7. クリーンアップ

gcloud logging sinks delete sink01 -q
gcloud logging sinks list 

bq rm --recursive=true --force ds01
bq ls

 

gcloud projects list

gcloud projects delete project01-9999999 -q


gcloud beta billing projects unlink project01-9999999

 

 




以上の内容はhttps://htn20190109.hatenablog.com/entry/2024/11/10/220453より取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14