我正在尝试使用JClouds在Google Compute Engine中创建实例。我无法正确设置防火墙规则,唯一打开的端口是22 (默认端口)。
我在文档和示例中找不到任何东西。下面的代码只打开端口22。
如何打开其他一些端口,比如80、5432等?有没有办法打开所有的口岸?
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);
}提前谢谢。
发布于 2015-08-14 16:13:10
尝试使用完整的URI来“默认”网络。例如:"https://www.googleapis.com/compute/v1/projects/xxx-project/global/networks/default“
发布于 2015-02-08 16:03:51
根据JClouds主页上的available providers list,对GCE的支持是here。将其添加到项目中后,您将拥有以下类:
尽管我自己不是Java开发人员,但我打赌这就是您所要求的。使用目标和实例标签,您可以将规则限制为仅适用于某些实例。如果未使用目标targ,则规则中的端口将对应用规则的网络中的所有实例开放。希望这能有所帮助。
发布于 2015-02-04 19:26:12
Google Compute Engine项目具有两个默认防火墙规则(在默认网络上),它们允许端口80和/或443上的入站连接(从互联网)到具有http-server和/或https-server标签的任何实例。所述标签可以在VM实例化时或之后定义。
https://stackoverflow.com/questions/28313264
复制相似问题