google-cloud-platform - 如何为 Google Cloud Compute Engine 打开一个或所有端口

标签 google-cloud-platform google-compute-engine

我有一个在 GCP 计算引擎中的虚拟机上运行的 IOTA IRI 实例。
该实例使用端口 14265 进行通信,并通过执行类似 curl http://localhost:14265 的操作在本地检查它确实响应。

我想把这个端口开放到虚拟机之外,所以我设置了一个静态IP,和一个防火墙规则来允许tcp:14265; udp:14265并且端口仍然没有响应。

我什至尝试通过以下方式允许所有人:
enter image description here

但没有运气。除了 ssh 的 22 端口外,没有打开端口(在 port scanner 中查看)

我知道这感觉像是 How to open a specific port such as 9090 in Google Compute Engine 的副本,但我确实尝试了这些答案,但他们并没有为我解决。

编辑:

运行我被要求在答案中运行的两个命令:

D:\Downloads> gcloud compute networks list
NAME     MODE  IPV4_RANGE  GATEWAY_IPV4
default  auto

D:\Downloads>gcloud compute instances describe instance-1 --zone europe-west1-b
canIpForward: false
cpuPlatform: Intel Sandy Bridge
creationTimestamp: '2017-08-22T09:33:12.240-07:00'
description: ''
disks:
- autoDelete: true
  boot: true
  deviceName: instance-1
  index: 0
  interface: SCSI
  kind: compute#attachedDisk
  licenses:
  - https://www.googleapis.com/compute/v1/projects/ubuntu-os-cloud/global/licenses/ubuntu-1604-xenial
  mode: READ_WRITE
  source: https://www.googleapis.com/compute/v1/projects/iota-177616/zones/europe-west1-b/disks/instance-1
  type: PERSISTENT
id: '8895209582493819432'
kind: compute#instance
labelFingerprint: 42WmSpB8rSM=
machineType: https://www.googleapis.com/compute/v1/projects/iota-177616/zones/europe-west1-b/machineTypes/f1-micro
metadata:
  fingerprint: -pkE3KaIzLU=
  kind: compute#metadata
name: instance-1
networkInterfaces:
- accessConfigs:
  - kind: compute#accessConfig
    name: External NAT
    natIP: 35.187.9.204
    type: ONE_TO_ONE_NAT
  kind: compute#networkInterface
  name: nic0
  network: https://www.googleapis.com/compute/v1/projects/iota-177616/global/networks/default
  networkIP: 10.132.0.2
  subnetwork: https://www.googleapis.com/compute/v1/projects/iota-177616/regions/europe-west1/subnetworks/default
scheduling:
  automaticRestart: true
  onHostMaintenance: MIGRATE
  preemptible: false
selfLink: https://www.googleapis.com/compute/v1/projects/iota-177616/zones/europe-west1-b/instances/instance-1
serviceAccounts:
- email: 59105716861-compute@developer.gserviceaccount.com
  scopes:
  - https://www.googleapis.com/auth/devstorage.read_only
  - https://www.googleapis.com/auth/logging.write
  - https://www.googleapis.com/auth/monitoring.write
  - https://www.googleapis.com/auth/servicecontrol
  - https://www.googleapis.com/auth/service.management.readonly
  - https://www.googleapis.com/auth/trace.append
startRestricted: false
status: RUNNING
tags:
  fingerprint: 6smc4R4d39I=
  items:
  - http-server
  - https-server
zone: https://www.googleapis.com/compute/v1/projects/iota-177616/zones/europe-west1-b

最佳答案

如果没有一些诊断,很难给出准确的答案。

可能是正在为网络创建规则,而您的实例位于不同的网络中。

因此,首先,检查项目中可用的网络:

gcloud compute networks list

其次,检查您的实例所在的网络:
gcloud compute instances describe [Instance Name] --zone [Zone]

检查应用于您的实例使用的网络的防火墙规则:
gcloud compute firewall-rules list

还要检查目标标签是否合适。

正如您所看到的,没有将标签应用于虚拟机,但如果您将其定位到所有虚拟机,则应该应用规则,这是一个很好的做法。
  • 编辑您的虚拟机并添加标签(例如前端服务器)
    gcloud compute instances add-tags [INSTANCE NAME] --zone [ZONE] --tags frontserver
  • 现在创建防火墙规则并将其应用于创建的标签
    gcloud beta compute firewall-rules create [NAME_OF_THE_RULE] --direction=INGRESS --priority=1000 --network=default --allow=all --source-ranges=0.0.0.0/0 --target-tags=frontserver

  • 检查它是否有效,您可以运行更新以将其限制为所需的端口和协议(protocol)以及您的源 IP
    gcloud beta compute firewall-rules update [NAME_OF_THE_RULE] --direction=INGRESS --priority=1000 --network=default --allow=tcp:--source-ranges=[your_source_IP] --target-tags=frontserver
    

    希望这会有所帮助,可以找到更多信息 here举例

    关于google-cloud-platform - 如何为 Google Cloud Compute Engine 打开一个或所有端口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45825121/

    相关文章:

    amazon-web-services - 使用 Terraform 在新创建的虚拟机上创建 Docker 容器

    docker - 当您将服务帐户分配给 Cloud Run 服务时,究竟会发生什么?

    google-cloud-platform - Google Cloud Spanner 是否支持索引交集/组合/合并?

    kubernetes - 如何使用Kubernetes端点对象?

    python - 如何检查 TPU 设备类型是 v2 还是 v3?

    docker - 谷歌云计算实例更新

    python - 用于科学 Web 应用程序的谷歌云平台架构

    python-3.x - 为什么我们使用hadoop mapreduce进行数据处理?为什么不在本地计算机上呢?

    java - 如何使用 java 从 gcp 存储桶下载文件夹?

    deployment - Google云计算,使用环境变量