如何在 Ubuntu 21.10 上安裝 Google Cloud Ops Agent?

如何在 Ubuntu 21.10 上安裝 Google Cloud Ops Agent?

我嘗試透過 Docker 在 Ubuntu 上安裝 Google Cloud Ops Agent,但遇到了幾個問題。

首先,執行以下命令會傳回錯誤,指出某些 GPG 簽章無法驗證:

FROM ubuntu:impish

RUN apt update
RUN apt -y install curl

RUN curl -sSO https://dl.google.com/cloudagents/add-google-cloud-ops-agent-repo.sh && bash add-google-cloud-ops-agent-repo.sh --also-install --verbose

CMD ["tail", "/dev/null"]

錯誤:

#6 20.71 Hit:1 http://ports.ubuntu.com/ubuntu-ports impish InRelease
#6 21.00 Hit:2 http://ports.ubuntu.com/ubuntu-ports impish-updates InRelease
#6 21.00 Get:3 https://packages.cloud.google.com/apt google-cloud-ops-agent-impish-all InRelease [5474 B]
#6 21.09 Err:3 https://packages.cloud.google.com/apt google-cloud-ops-agent-impish-all InRelease
#6 21.09   The following signatures couldn't be verified because the public key is not available: NO_PUBKEY FEEA9169307EA071 NO_PUBKEY 8B57C5C2836F4BEB
#6 21.33 Hit:4 http://ports.ubuntu.com/ubuntu-ports impish-backports InRelease
#6 21.64 Hit:5 http://ports.ubuntu.com/ubuntu-ports impish-security InRelease
#6 21.72 Reading package lists...
#6 22.12 W: GPG error: https://packages.cloud.google.com/apt google-cloud-ops-agent-impish-all InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY FEEA9169307EA071 NO_PUBKEY 8B57C5C2836F4BEB
#6 22.12 E: The repository 'https://packages.cloud.google.com/apt google-cloud-ops-agent-impish-all InRelease' is not signed.

為了解決這個問題,根據我在網路上找到的一些建議,我添加了:

RUN apt -y install software-properties-common
RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys FEEA9169307EA071 8B57C5C2836F4BEB

給我以下 Dockerfile:

FROM ubuntu:impish

RUN apt update
RUN apt -y install software-properties-common curl

RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys FEEA9169307EA071 8B57C5C2836F4BEB
RUN curl -sSO https://dl.google.com/cloudagents/add-google-cloud-ops-agent-repo.sh && bash add-google-cloud-ops-agent-repo.sh --also-install --verbose

CMD ["tail", "/dev/null"]

這會導致 Ops Agent 出現已棄用的警告apt-key和「安裝失敗」錯誤:

#7 7.659 E: Unable to locate package google-cloud-ops-agent
#7 7.659 + fail 'google-cloud-ops-agent  installation failed.'
#7 7.660 ++ date +%Y-%m-%dT%H:%M:%S%z
#7 7.661 + echo '[2022-05-02T20:40:14+0000] google-cloud-ops-agent  installation failed.'
#7 7.661 [2022-05-02T20:40:14+0000] google-cloud-ops-agent  installation failed.

根據Ops Agent Google 文件支援 Ubuntu Impish。將 Ubuntu 從版本 21.10(頑皮)更改為 20.04(焦點)似乎也沒有幫助。

任何有關解決 GPG 問題以及在 Ubuntu 上安裝 Google Ops Agent 的更好方法的建議將不勝感激。

答案1

您缺少匯入 gpg 金鑰所需的套件,因此您會收到初始錯誤,因為匯入失敗。

將軟體包安裝行替換為以下內容:

RUN apt-get -y install curl gnupg

提示:在腳本中使用apt-get而不是apt,因為 apt 的目的是讓最終用戶易於使用,所以「真正」的工作是由 apt-get 完成的。

此外,apt-key您在第二次嘗試中新增的命令嘗試從 Ubuntu 伺服器取得金鑰,但該軟體套件是從 Google 伺服器下載的,因此應該從那裡完成金鑰匯入。

您可以在 ops-agent 的安裝腳本中看到apt-key執行了類似的命令,但它的目標是https://packages.cloud.google.com/apt/doc/apt-key.gpg

因此,您不需要自己匯入金鑰,因為安裝腳本會為您完成此操作,前提是您擁有所需的套件(在本例中為 )gnupg

相關內容