Openshift V2 - Custom Cartridge Permission denied

2019-09-11 04:23发布

问题:

I'm trying to listen on a port in open shift, but I'm getting Permission denied. I am using a fork of the Wildfly 8.2.1 Cartridge:

2016-12-31 13:24:06,016 INFO  [com.hazelcast.instance.DefaultAddressPicker] (MSC service thread 1-8) [LOCAL] [name] [3.5.4] Interfaces is disabled, trying to pick one address from TCP-IP config addresses: [127.0.0.1]
2016-12-31 13:24:06,074 SEVERE [com.hazelcast.instance.DefaultAddressPicker] (MSC service thread 1-8) [LOCAL] [name] [3.5.4] ServerSocket bind has failed. Hazelcast cannot start! config-port: 5701, latest-port: 5801: com.hazelcast.core.HazelcastException: ServerSocket bind has failed. Hazelcast cannot start! config-port: 5701, latest-port: 5801
        at com.hazelcast.instance.DefaultAddressPicker.pickAddress(DefaultAddressPicker.java:117) [hazelcast-3.5.4.jar:3.5.4]
        at com.hazelcast.instance.Node.<init>(Node.java:143) [hazelcast-3.5.4.jar:3.5.4]
        at com.hazelcast.instance.HazelcastInstanceImpl.<init>(HazelcastInstanceImpl.java:120) [hazelcast-3.5.4.jar:3.5.4]
        at com.hazelcast.instance.HazelcastInstanceFactory.constructHazelcastInstance(HazelcastInstanceFactory.java:152) [hazelcast-3.5.4.jar:3.5.4]
        at com.hazelcast.instance.HazelcastInstanceFactory.getOrCreateHazelcastInstance(HazelcastInstanceFactory.java:98) [hazelcast-3.5.4.jar:3.5.4]
        at com.hazelcast.core.Hazelcast.getOrCreateHazelcastInstance(Hazelcast.java:116) [hazelcast-3.5.4.jar:3.5.4]
        at org.springframework.boot.autoconfigure.hazelcast.HazelcastInstanceFactory.getHazelcastInstance(HazelcastInstanceFactory.java:80) [spring-boot-autoconfigure-1.3.2.RELEASE.jar:1.3.2.RELEASE]
.
.
.
Caused by: java.net.SocketException: Permission denied
        at sun.nio.ch.Net.bind0(Native Method) [rt.jar:1.8.0_111]
        at sun.nio.ch.Net.bind(Net.java:433) [rt.jar:1.8.0_111]
        at sun.nio.ch.Net.bind(Net.java:425) [rt.jar:1.8.0_111]
        at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223) [rt.jar:1.8.0_111]
        at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74) [rt.jar:1.8.0_111]
        at com.hazelcast.instance.DefaultAddressPicker.pickAddress(DefaultAddressPicker.java:98) [hazelcast-3.5.4.jar:3.5.4]
        ... 69 more

I forked an existing Wildfly Cartridge for Openshift: https://github.com/openshift-cartridges/openshift-wildfly-cartridge

And I added the extra new ports to the manifest.yml file:

- Private-IP-Name:   IP
    Private-Port-Name: HAZELCAST_PORT
    Private-Port:      5701
    Public-Port-Name:  HAZELCAST_PROXY_PORT

The full manifest can be found here: https://github.com/mrj365/openshift-wildfly-cartridge/blob/master/metadata/manifest.yml

I'm not sure what I'm missing. I just want to be able to listen locally on that port.

回答1:

I figured out the issue. Hazelcast was binding to the wrong IP address. I had to add the following configurations to the hazelcast config to get it to work:

Config config = new Config();

config.setProperty("hazelcast.local.localAddress", System.getenv("OPENSHIFT_DIY_IP "));

I'm using wildfly, so for me it was:

config.setProperty("hazelcast.local.localAddress", System.getenv("OPENSHIFT_WILDFLY_IP"));

I also had to add these 2 additional configurations:

config.setProperty("hazelcast.socket.client.bind.any", "false");
config.setProperty("hazelcast.socket.bind.any", "false");