简体   繁体   English

在 GCP 中运行修改后的启动脚本时出现问题

[英]Problem running a modified startup-script in GCP

I am trying to set up an Instance using an Instance Template in the GCP Deployment Manager.我正在尝试使用 GCP 部署管理器中的实例模板设置实例。 It works fine but upon adding startup-script in metadata, it doesn't.它工作正常但在元数据中添加启动脚本后,它没有。

This is the code (and script) I am trying to run:这是我要运行的代码(和脚本):

gcloud compute instances create my-instance --source-instance-template my-it --zone=northamerica-northeast1-a -.network=my.network --su.net=my-su.net --no-address --metadata=startup-script='sudo /opt/scripts/startup.sh #. gcloud 计算实例创建我的实例 --source-instance-template my-it --zone=northamerica-northeast1-a -.network=my.network --su.net=my-su.net --no-address - -metadata=startup-script='sudo /opt/scripts/startup.sh #. /bin/bash sudo htpasswd -c -B -b /etc/nginx/.htpasswd test test' /bin/bash sudo htpasswd -c -B -b /etc/nginx/.htpasswd 测试测试'

Here, the following part comes from the instance template itself and I am trying to add in the latter.在这里,以下部分来自实例模板本身,我试图在后者中添加。

sudo /opt/scripts/startup.sh sudo /opt/scripts/startup.sh

Any help appreciated, thanks!任何帮助表示赞赏,谢谢!

GCP documentation says that when creating a VM from an instance template, the default behavior is to create a VM instance precisely as described in the instance template except for the instance name and zone; GCP 文档说,当从实例模板创建 VM 时,默认行为是完全按照实例模板中的描述创建 VM 实例,但实例名称和区域除外; if you want to override an attribute, you only need to pass the new value.如果你想覆盖一个属性,你只需要传递新的值。 Create a vm instance from an instance template with overrides 从具有覆盖的实例模板创建虚拟机实例

You can see from the documentation that gcloud compute instance-templates has the same --metadata and --metadata-from-file flags as gcloud compute instances gcloud compute instance-templates , gcloud compute instance create您可以从文档中看到gcloud compute instance-templatesgcloud compute instances gcloud compute instance-templatesgcloud compute instance create具有相同的--metadata--metadata-from-file标志

So any new value to --metadata when creating a new instance with --source-instance-template=my_template will only override the value from the instance template (no adding).因此,在使用--source-instance-template=my_template创建新实例时,--metadata 的任何新值都只会覆盖实例模板中的值(不添加)。 The --metadata-from-file flag maybe me more suitable for your use case( new.sh with the startup-script form instance template + extra steps) --metadata-from-file标志可能更适合您的用例(带有启动脚本表单实例模板的 new.sh + 额外步骤)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM