通过阅读 cloud-init 文档(https://cloudinit.readthedocs.io/en/latest/topics/modules.html#apt-configure),看来这个用户数据应该添加Nodesource源和apt的密钥,并安装Node v18:
apt:
sources:
nodejs:
source: deb https://deb.nodesource.com/node_18.x $RELEASE main
keyserver: https://deb.nodesource.com/gpgkey/nodesource.gpg.key
packages:
- nodejs
URL 确实似乎引用了包和密钥。但是,cloud-init 在 /etc/apt/sources.list.d/ 中添加了一个 .list 文件,但没有在 /usr/share/keyrings/ 中添加密钥文件,并且抱怨
W: GPG error: https://deb.nodesource.com/node_18.x jammy InRelease: The following signatures couldn't be verified because the public
key is not available: NO_PUBKEY 1655A0AB68576280
E: The repository 'https://deb.nodesource.com/node_18.x jammy InRelease' is not signed.
并且不安装 Node。
通过编写 apt 列表文件安装 Node 时,包引用如下所示:
deb [signed-by=/usr/share/keyrings/nodejs.gpg] https://deb.nodesource.com/node_18.x jammy main
我可以把类似的内容放在一行上source:
,但是我应该引用什么密钥文件名呢?
答案1
事实证明你需要密钥 ID。你可以使用以下方法提取它:
wget -qO- https://deb.nodesource.com/gpgkey/nodesource.gpg.key | gpg --with-fingerprint --with-colons | awk -F: '/^fpr/ { print $10 }'
或者从日志中查看之前发生的故障。
nodesource 密钥位于 Ubuntu 密钥服务器中,因此apt
实际上不需要您指定密钥服务器:
# gpg --keyserver=keyserver.ubuntu.com --recv-keys 9FD3B784BC1C6FC31A8A0A1C1655A0AB68576280
gpg: key 1655A0AB68576280: public key "NodeSource <[email protected]>" imported
apt:
sources:
nodejs:
source: deb [signed-by=$KEY_FILE] https://deb.nodesource.com/node_18.x $RELEASE main
# keyserver: https://deb.nodesource.com/gpgkey/nodesource.gpg.key
keyid: 9FD3B784BC1C6FC31A8A0A1C1655A0AB68576280
packages:
- nodejs