我目前正在尝试在我使用 bash 脚本创建的某个 ubuntu 18.04 gcloud VM 实例上安装 ops 代理,该实例基于可访问的 gcloud 指南(此处)。 脚本如下:
echo "Installing components for agent policies"
gcloud components install beta
echo "Enabling API and setting proper permissions for monitoring"
sh set-permissions.sh --project=XXX
gcloud beta compute instances ops-agents policies create ops-agents-policy-safe-rollout \
--agent-rules="type=logging,version=current-major,package-state=installed,enable-autoupgrade=true;type=metrics,version=current-major,package-state=installed,enable-autoupgrade=true" \
--os-types=short-name=ubuntu,version=18.04 \
--project=XXX \
--instances=zones/us-central1-a/instances/instance-XXX
...
gcloud compute instances create instance-XXX --boot-disk-size=100GB \
--boot-disk-type=pd-ssd --metadata=enable-oslogin=TRUE \
--image-family=ubuntu-minimal-1804-lts --image-project=ubuntu-os-cloud \
--no-service-account --no-scopes --project=XXX --zone=us-central-1 \
--network-interface "" --network-interface subnet=.../regions/us-central1/subnetworks/XXX,no-address
执行此脚本时,我没有收到任何错误,但当我转到 GCP 并尝试查找我的实例的指标时,内存利用率和磁盘空间利用率图表显示需要 Ops Agent,我应该安装它。按照指南,并验证操作系统配置代理是否已安装后,我按照“操作系统配置代理已安装,但不安装 Ops 代理”中的步骤操作。当我这样做时,我收到两个错误。指南中没有提及这些问题:
Dec 14 15:34:34 bastion OSConfigAgent[600]: 2021-12-14T15:34:34.1627Z OSConfigAgent Error policies.go:49: Error running LookupEffectiveGuestPolicies: error getting token from metadata: metadata: GCE metadata "instance/service-accounts/default/identity?audience=osconfig.googleapis.com&format=full" not defined
Dec 14 15:34:36 bastion OSConfigAgent[600]: 2021-12-14T15:34:36.9551Z OSConfigAgent Error inventory.go:76: Error reporting inventory checksum: error getting token from metadata: metadata: GCE metadata "instance/service-accounts/default/identity?audience=osconfig.googleapis.com&format=full" not defined
如何修复这些错误以有效安装 Ops Agent?
您提供的日志信息很少,这可能有很多原因。
确保例如。所有
/etc/apt/sources.list.d/
都是有效的存储库。
还要确保元数据 a) 设置正确并且 b) 可以访问:
enable-guest-attributes TRUE
enable-osconfig TRUE
这很可能与您正在传递的
--agent-rules
论点有关。
有没有想过一个启动脚本,它可以简单地安装代理?
另请参阅:管理代理策略 - 故障排除。