0

我正在尝试部署带有标签“http”的 Linux VM,并创建防火墙以允许 HTTP 端口 80 访问作为标签防火墙“http”。正在部署 VM,但没有外部访问对 VM 起作用。还提供了 VM 的启动脚本,但它不起作用

resources:
- type: compute.v1.instance
  name: vm-test
  properties:
    metadata:
      items:
      - key: startup-script-url
        value: https://storage.googleapis.com/cf405bucket/install-web.sh
    zone: {{ properties["zone"] }}
    machineType: https://www.googleapis.com/compute/v1/projects/{{ env["project"] }}/zones/{{ properties["zone"] }}/machineTypes/n1-standard-2
    # For examples on how to use startup scripts on an instance, see:
    #   https://cloud.google.com/compute/docs/startupscript
    tags:
      items: ["http"]
    disks:
    - deviceName: boot
      type: PERSISTENT
      boot: true
      autoDelete: true
      initializeParams:
        diskName: disk-{{ env["deployment"] }}
        sourceImage: https://www.googleapis.com/compute/v1/projects/debian-cloud/global/images/family/debian-9
    networkInterfaces:
    - network: https://www.googleapis.com/compute/v1/projects/{{ env["project"] }}/global/networks/default
      # Access Config required to give the instance a public IP address
      accessConfigs:
      - name: External NAT
        type: ONE_TO_ONE_NAT
- type: compute.v1.firewall
  name: default-allow-http
  properties:
    sourceRanges: ["0.0.0.0/0"]
    network: https://www.googleapis.com/compute/v1/projects/{{ env["project"] }}/global/networks/default 
    targetTags: ["http"]
    allowed:
    - IPProtocol: TCP
      ports: ["80"]
4

1 回答 1

0

尝试通过 SSH 连接到部署创建的 VM 实例并运行命令apache2 --version

怎么了?我假设你会被告知它不是一个可识别的命令或其他东西......鉴于看起来由于某种原因尚未安装 Web 服务器。如果是这样,也许尝试更新install-web.sh以包含sudo命令之前,即

#!/bin/bash
sudo apt-get update
sudo apt-get install -y apache2

如果做不到这一点,为什么不完全放弃install-web.sh文件,直接将脚本包含在配置文件中(因为它没有太多内容),例如:

    metadata:
     items:
     - key: startup-script
       value: |
          #!/bin/bash
          apt-get update
          apt-get install -y apache2
于 2019-06-04T16:03:47.897 回答