![GCE - 启动脚本 - 无法再使用元数据](https://linux22.com/image/773177/GCE%20-%20%E5%90%AF%E5%8A%A8%E8%84%9A%E6%9C%AC%20-%20%E6%97%A0%E6%B3%95%E5%86%8D%E4%BD%BF%E7%94%A8%E5%85%83%E6%95%B0%E6%8D%AE.png)
晚上好,我一直在尝试修改 Google Compute Engine 中的实例启动脚本,但随着 GCE 的新版本(可能是 2021 年 12 月或 2021 年 11 月),显示发生了变化。此外,似乎我们不能再使用“启动脚本”元数据了,而需要改用“启动脚本部分”。但这一部分无处可寻。至少对我来说是这样。有人有更多关于它的信息吗?我遗漏了什么吗?GCE 截图(抱歉,是法语的)
答案1
这是您正在寻找的链接:https://cloud.google.com/compute/docs/instances/startup-scripts
通过控制台:
对于启动磁盘,选择更改,然后选择 Linux 操作系统。
展开网络、磁盘、安全、管理、单独租用部分,然后执行以下操作:
展开管理部分。在自动化部分中,添加您的启动脚本:
如果你愿意的话,我始终建议使用 gcloud CLI 或 Terraform 之类的工具
gcloud compute instances create VM_NAME \
--image-project=debian-cloud \
--image-family=debian-10 \
--metadata=startup-script='#! /bin/bash
apt update
apt -y install apache2
cat <<EOF > /var/www/html/index.html
<html><body><p>Linux startup script added directly.</p></body></html>'
gcloud compute instances create VM_NAME \
--image-project=debian-cloud \
--image-family=debian-10 \
--metadata-from-file=startup-script=FILE_PATH