我們注意到,我們的一些 GCE 實例在 /home/deploy/.config/gcloud/logs
(「deploy」是我們的應用程式進程運行的使用者)下累積了大量日誌檔案(1.6GB)。看來保存了一個月的日誌檔。每隔幾秒左右就會建立一個檔案。
每個文件如下所示:
2020-12-11 20:52:02,105 DEBUG root Loaded Command Group: ['gcloud', 'config', 'config_helper']
2020-12-11 20:52:02,107 DEBUG root Running [gcloud.config.config-helper] with arguments: [--format: "json", --verbosity: "none"]
2020-12-11 20:52:02,130 DEBUG google_auth_httplib2 Making request: GET http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/xxx/?recursive=true
2020-12-11 20:52:02,137 DEBUG google_auth_httplib2 Making request: GET http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/xxx/token
2020-12-11 20:52:02,157 INFO root Display format: "default json"
2020-12-11 20:52:02,159 INFO ___FILE_ONLY___ {
"configuration": {
"active_configuration": "default",
"properties": {
"core": {
"account": "xxx",
"disable_usage_reporting": "True",
"project": "xxx",
"verbosity": "none"
}
}
},
"credential": {
"access_token": "xxx",
"id_token": "xxx",
"token_expiry": "2020-12-11T21:36:39Z"
},
"sentinels": {
"config_sentinel": "/home/deploy/.config/gcloud/config_sentinel"
}
}
2020-12-11 20:52:02,159 INFO ___FILE_ONLY___
2020-12-11 20:52:02,160 DEBUG root SDK update checks are disabled.
(我刪除了潛在的敏感資訊。)
我試圖找出這些文件的來源,更重要的是,如何防止它們被創建。這些文件佔用了大量的磁碟空間。
這些是ubuntu系統。我們的應用程式主要是用 Go 編寫的,並帶有一些 Ruby 和 Node.js。
答案1
這些日誌由 gcloud 自動生成,並在 30 天內自動清除。您可以在雲端 shell 上使用以下命令來停用它。
gcloud 設定集 core/disable_file_logging True
您可以在以下位置了解有關該命令的更多信息官方 GCP 文件。