在GCP中添加到实例的startup-script似乎不能在第一次启动时运行(但是在后续的启动过程中)
我正在使用https://www.googleapis.com/compute/v1/projects/centos-cloud/global/images/centos-7-v20160921基本映像,但在较旧版本的centos- 7图像了。
无论我使用API创build实例还是Web控制台,都会发生这种情况。
根据文档( https://cloud.google.com/compute/docs/startupscript )添加元数据与关键startup-script和startup-script值应该导致脚本在每次启动运行。
(关于将脚本添加到正在运行的实例中有一节,它提到需要重新启动才能运行脚本,但是这(显然)不适用于新实例。)
可以强制脚本使用sudo google_metadata_script_runner --script-type startup ( https://cloud.google.com/compute/docs/startupscript#rerunthescript )这意味着该脚本已加载,但只是没有运行,所以我不知道发生了什么事。
我做错了什么,或者我在GCP中发现了一个错误? 🙂
这实际上对我来说没有问题,使用Centos 7映像。 我从控制台创build了VM,并添加了这个小脚本
#! /bin/bash yum update yum install -y httpd cat <<EOF > /var/www/html/index.html <html><body><h1>Hello World</h1> <p>This page was created from a simple startup script!</p> </body></html> EOF
在创build虚拟机之后,我能够validationApache是否已经安装在串行控制台中 。
… Feb 3 20:36:17 instance-3 startup-script: INFO startup-script: ---> Package httpd.x86_64 0:2.4.6-45.el7.centos will be installed Feb 3 20:36:17 instance-3 startup-script: INFO startup-script: --> Processing Dependency: httpd-tools = 2.4.6-45.el7.centos for package: httpd-2.4.6-45.el7.centos.x86_64 Feb 3 20:36:17 instance-3 startup-script: INFO startup-script: --> Processing Dependency: /etc/mime.types for package: httpd-2.4.6-45.el7.centos.x86_64 …. Feb 3 20:36:20 instance-3 startup-script: INFO startup-script: Installed: Feb 3 20:36:20 instance-3 startup-script: INFO startup-script: httpd.x86_64 0:2.4.6-45.el7.centos Feb 3 20:36:20 instance-3 startup-script: INFO startup-script: Dependency Installed: Feb 3 20:36:20 instance-3 startup-script: INFO startup-script: apr.x86_64 0:1.4.8-3.el7 apr-util.x86_64 0:1.5.2-6.el7 Feb 3 20:36:20 instance-3 startup-script: INFO startup-script: httpd-tools.x86_64 0:2.4.6-45.el7.centos mailcap.noarch 0:2.1.41-2.el7 Feb 3 20:36:20 instance-3 startup-script: INFO startup-script: Complete!
该脚本没有安装Apache,但虚拟机中的服务未启动。 我只需要在虚拟机的SSH启动服务。