首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >JClouds:在谷歌计算引擎中定义防火墙规则

JClouds:在谷歌计算引擎中定义防火墙规则
EN

Stack Overflow用户
提问于 2015-02-04 12:00:25
回答 3查看 274关注 0票数 1

我正在尝试使用JClouds在Google Compute Engine中创建实例。我无法正确设置防火墙规则,唯一打开的端口是22 (默认端口)。

我在文档和示例中找不到任何东西。下面的代码只打开端口22。

如何打开其他一些端口,比如80、5432等?有没有办法打开所有的口岸?

代码语言:javascript
复制
    final String POLL_PERIOD_TWENTY_SECONDS = String.valueOf(SECONDS.toMillis(20));

    Properties overrides = new Properties();
    overrides.setProperty(ComputeServiceProperties.POLL_INITIAL_PERIOD, POLL_PERIOD_TWENTY_SECONDS);
    overrides.setProperty(ComputeServiceProperties.POLL_MAX_PERIOD, POLL_PERIOD_TWENTY_SECONDS);

    Iterable<Module> modules = ImmutableSet.<Module> of(new SshjSshClientModule(), new SLF4JLoggingModule());
    //Iterable<Module> modules = ImmutableSet.<Module> of(new SshjSshClientModule());

    ComputeServiceContext context = ContextBuilder.newBuilder("google-compute-engine")
            .credentials("valid email", "valid cert")
            .modules(modules)
            .overrides(overrides)
            .buildView(ComputeServiceContext.class);
    ComputeService computeService = context.getComputeService();

    Template template = computeService.templateBuilder()
            .locationId("asia-east1-a")
            .imageId("https://www.googleapis.com/compute/v1/projects/ubuntu-os-cloud/global/images/ubuntu-1404-trusty-v20150128")
            .hardwareId("https://www.googleapis.com/compute/v1/projects/MY-PROJECT/zones/asia-east1-a/machineTypes/f1-micro")
            .build();

// Those options are not working as expected
    // List<String> networks = new ArrayList<>();
    // networks.add("default");
    // template.getOptions().as(GoogleComputeEngineTemplateOptions.class).networks(networks);
    // template.getOptions().as(GoogleComputeEngineTemplateOptions.class).inboundPorts(5432,1,2,3);

    Set<? extends NodeMetadata> nodes = computeService.createNodesInGroup("m456", 1, template);

    for (NodeMetadata nodeMetadata : nodes) {
        String publicAddress = nodeMetadata.getPublicAddresses().iterator().next();
        //String privateAddress = nodeMetadata.getPrivateAddresses().iterator().next();
        String username = nodeMetadata.getCredentials().getUser();
        String password = nodeMetadata.getCredentials().getPassword();
        System.out.println(publicAddress);
        System.out.println(username);
        System.out.println(password);
    }

提前谢谢。

EN

回答 3

Stack Overflow用户

发布于 2015-08-14 16:13:10

尝试使用完整的URI来“默认”网络。例如:"https://www.googleapis.com/compute/v1/projects/xxx-project/global/networks/default

票数 1
EN

Stack Overflow用户

发布于 2015-02-08 16:03:51

根据JClouds主页上的available providers list,对GCE的支持是here。将其添加到项目中后,您将拥有以下类:

  • org.jclouds.googlecomputeengine.domain.Firewall.Rule
  • org.jclouds.googlecomputeengine.domain.Firewall.Rule.Builder
  • org.jclouds.googlecomputeengine.domain.Network
  • org.jclouds.googlecomputeengine.domain.Instance.Tags

尽管我自己不是Java开发人员,但我打赌这就是您所要求的。使用目标和实例标签,您可以将规则限制为仅适用于某些实例。如果未使用目标targ,则规则中的端口将对应用规则的网络中的所有实例开放。希望这能有所帮助。

票数 0
EN

Stack Overflow用户

发布于 2015-02-04 19:26:12

Google Compute Engine项目具有两个默认防火墙规则(在默认网络上),它们允许端口80和/或443上的入站连接(从互联网)到具有http-server和/或https-server标签的任何实例。所述标签可以在VM实例化时或之后定义。

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28313264

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档