Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Force the name / ipaddress with which Eureka client registers at the server #788

Closed
mrumpf opened this issue Jan 23, 2016 · 9 comments
Closed

Comments

@mrumpf
Copy link

mrumpf commented Jan 23, 2016

The issue I have is described here:
Netflix/eureka#737

In Spring Cloud I see several properties where I was hoping to be able to override the hostname or the IP address with which the Spring Cloud Eureka Client registers with the server:

spring: 
  cloud: 
    client:
      hostname: localhost
      ipAddress: 127.0.0.1

When I set this in the application.yml it still gets overridden by the springCloudClientHostInfo config bean which takes precedence.

The following props do not seem to influence the name/ip being registered.

eureka:
  instance:
    hostname: localhost
    ipAddress: 127.0.0.1

And the third one was with the metadataMap:

eureka:
  instance:
    metadataMap:
      hostname: localhost

Also without effect.

Is this feature missing from the code or from the documentation only?

@pcornelissen
Copy link
Contributor

I think this may be related to #573

@mrumpf
Copy link
Author

mrumpf commented Jan 24, 2016

I think that this is a similar issue and the fix, done by @spencergibb might lead to a workaround, but in my case I have a VPN connection via network interface "ppp2" (ppp[0-9]*) with an IP 10.0.0.0/8 and a local area network with IPs 192.168.0.0/24. The home network is not reachable because the VPN client cuts all routes so that the machine is in the corporate LAN only. In this case I would need a property to specify a NIC name or an order of nic names, something like this:

preferredNics=ppp,eth,lo

  1. When a ppp interface is active, try to use the IP, assigned to the ppp interface
  2. If not, try any ethX interface, starting with eth0
  3. As a last resort, try to use localhost/127.0.0.1

I'm not sure whether this works for all cases (see the list of interfaces in the ticket Netflix/eureka#737). But setting an IP address or a hostname explicitly works for 127.0.0.1/localhost, i.e. local development only. It does not work if you want yout services to be on the company network, to which you connected via the PPP adapter.

@pcornelissen
Copy link
Contributor

I had a similar problem where I needed a non-local IP because of port bindiung problems on our teamcity server. I solved that by determining the IP on the outside of the component tests with this groovy script in the pom:

<plugin>
                <groupId>org.codehaus.groovy.maven</groupId>
                <artifactId>gmaven-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>initialize</phase>
                        <goals>
                            <goal>execute</goal>
                        </goals>
                        <configuration>
                            <source>
                                List interfaces = ["eth0", "en0", "eth1", "en1", "eth2", "en2", "eth3", "en3", "wlan0"]
                                Enumeration nets = NetworkInterface.getNetworkInterfaces();
                                for (NetworkInterface netint : Collections.list(nets)) {
                                    println netint;
                                    if (interfaces.contains(netint.getName())) {
                                        Enumeration inetAddresses = netint.getInetAddresses();
                                        for (InetAddress inetAddress : Collections.list(inetAddresses)) {
                                            if (!inetAddress.isAnyLocalAddress()) {
                                                println("InetAddress: " + inetAddress);
                                                project.properties["hostname"] = inetAddress.getHostAddress().replace("/","")
                                            }
                                        }
                                    }
                                }
                                println "Using the IP: "+project.properties["hostname"];
                            </source>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

This sets a property which is then passed to the service startscript and the component tests. (In this project, we don't use eureka, so setting the IP works without intereference)

You could easily backport this to java code and place it in your main(...) method and set the IP there as soon as the override works.

@dsyer
Copy link
Contributor

dsyer commented Jan 25, 2016

AFAIK if you set either the eureka.instance.hostname or the eureka.instance.ipAddress those will always be used in the EurekaInstanceConfigBean so if those are not making it to the server in the registration we need to look at how it is used to build the InstanceInfo. I can't see anything obviously wrong there either (look at InstanceInfoFactory), so can you be a bit more specific about what actually happens at runtime that doesn't work for you? Maybe you have an old version of the library because #573 was fixed some time ago?

N.B. there is no bean called "springCloudClientHostInfo" (as far as I know), but there is a low-priority PropertySource in the Environment with that name. It shouldn't affect anything that you explicitly set in a higher priority source, and those properties are only ever used, I believe, to construct a unique identifier, not to construct a URL, so I think there is still some confusion about that.

@pcornelissen
Copy link
Contributor

well #573 was fixed 5 days ago. So this is not released yet, I guess

@dsyer
Copy link
Contributor

dsyer commented Jan 25, 2016

OK, let's assume if it works for me that this is a duplicate of #573.

@cforce
Copy link

cforce commented Jan 28, 2016

The solution somehow worked out for me is to use hostname instead of ip fixed to localhost.

eureka:
  instance:
    hostname: localhost
    preferIpAddress: false    

.. and ignore network interfaces of the "problematic" uplinks is the cfg like described here at all clients
http://projects.spring.io/spring-cloud/spring-cloud.html#ignore-network-interfaces

@pcornelissen
Copy link
Contributor

You can still use the IP Address, but you need a recent Brixton version for it.
I am not sure if it is already in M4 but when you use M5 (as soon as it is released) or the current snapshot, then you're fine.

For example I had problems with the VPN IP breaking my setup, now I can ignore its interface by:

spring:
  cloud:
    inetutils:
      ignoredInterfaces:
        - tun.*

@cforce
Copy link

cforce commented Feb 4, 2016

Yes, i have tested with M4. In my case i get it working with (depends on your interfaces names)

spring:
  cloud:
      ignoredInterfaces:
        - eno.*
        - virbr.*

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants