在本地部署了一个Eureka Server的服务,端口为9199,相关yaml配置文件如下:
server:
port: 9199
spring:
application:
name: eureka-server
eureka:
instance:
hostname: localhost
client:
register-with-eureka: false
fetch-registry: false
server:
enable-self-preservation: true
renewal-percent-threshold: 0.85
另外再启动一个Eureka Client的客户端服务,并且注册到上面的Eureka Server,名为User-Service。然后发现,启动这个服务后就会马上停止,并且日志如下
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.4.3)
2021-02-19 15:55:11.273 INFO 10924 --- [ main] com.spd.lern.UserServiceApplication : Starting UserServiceApplication using Java 1.8.0_231 on DESKTOP-XXXXXXX with PID 10924 (D:\workspace\workspace_for_java\SPB-LERN\User-Service\target\classes started by xxx in D:\workspace\workspace_for_java\SPB-LERN\User-Service)
2021-02-19 15:55:11.277 INFO 10924 --- [ main] com.spd.lern.UserServiceApplication : No active profile set, falling back to default profiles: default
2021-02-19 15:55:11.906 INFO 10924 --- [ main] o.s.cloud.context.scope.GenericScope : BeanFactory id=b433b9db-5c1d-3137-978a-248d09aea5a9
2021-02-19 15:55:13.288 INFO 10924 --- [ main] o.s.cloud.commons.util.InetUtils : Cannot determine local hostname
2021-02-19 15:55:13.327 INFO 10924 --- [ main] DiscoveryClientOptionalArgsConfiguration : Eureka HTTP Client uses RestTemplate.
2021-02-19 15:55:14.474 INFO 10924 --- [ main] o.s.cloud.commons.util.InetUtils : Cannot determine local hostname
2021-02-19 15:55:14.528 WARN 10924 --- [ main] iguration$LoadBalancerCaffeineWarnLogger : Spring Cloud LoadBalancer is currently working with the default cache. You can switch to using Caffeine cache, by adding it and org.springframework.cache.caffeine.CaffeineCacheManager to the classpath.
2021-02-19 15:55:14.605 INFO 10924 --- [ main] o.s.c.n.eureka.InstanceInfoFactory : Setting initial instance status as: STARTING
2021-02-19 15:55:14.648 INFO 10924 --- [ main] com.netflix.discovery.DiscoveryClient : Initializing Eureka in region us-east-1
2021-02-19 15:55:14.653 INFO 10924 --- [ main] c.n.d.s.r.aws.ConfigClusterResolver : Resolving eureka endpoints via configuration
2021-02-19 15:55:14.747 INFO 10924 --- [ main] com.netflix.discovery.DiscoveryClient : Disable delta property : false
2021-02-19 15:55:14.747 INFO 10924 --- [ main] com.netflix.discovery.DiscoveryClient : Single vip registry refresh property : null
2021-02-19 15:55:14.747 INFO 10924 --- [ main] com.netflix.discovery.DiscoveryClient : Force full registry fetch : false
2021-02-19 15:55:14.748 INFO 10924 --- [ main] com.netflix.discovery.DiscoveryClient : Application is null : false
2021-02-19 15:55:14.748 INFO 10924 --- [ main] com.netflix.discovery.DiscoveryClient : Registered Applications size is zero : true
2021-02-19 15:55:14.748 INFO 10924 --- [ main] com.netflix.discovery.DiscoveryClient : Application version is -1: true
2021-02-19 15:55:14.748 INFO 10924 --- [ main] com.netflix.discovery.DiscoveryClient : Getting all instance registry info from the eureka server
2021-02-19 15:55:14.908 INFO 10924 --- [ main] com.netflix.discovery.DiscoveryClient : The response status is 200
2021-02-19 15:55:14.911 INFO 10924 --- [ main] com.netflix.discovery.DiscoveryClient : Starting heartbeat executor: renew interval is: 30
2021-02-19 15:55:14.913 INFO 10924 --- [ main] c.n.discovery.InstanceInfoReplicator : InstanceInfoReplicator onDemand update allowed rate per min is 4
2021-02-19 15:55:14.919 INFO 10924 --- [ main] com.netflix.discovery.DiscoveryClient : Discovery Client initialized at timestamp 1613721314918 with initial instances count: 1
2021-02-19 15:55:14.920 INFO 10924 --- [ main] o.s.c.n.e.s.EurekaServiceRegistry : Registering application USER-SERVICE with eureka with status UP
2021-02-19 15:55:14.920 INFO 10924 --- [ main] com.netflix.discovery.DiscoveryClient : Saw local status change event StatusChangeEvent [timestamp=1613721314920, current=UP, previous=STARTING]
2021-02-19 15:55:14.922 INFO 10924 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_USER-SERVICE/localhost:user-service:9023: registering service...
2021-02-19 15:55:14.938 INFO 10924 --- [ main] com.spd.lern.UserServiceApplication : Started UserServiceApplication in 5.304 seconds (JVM running for 6.087)
2021-02-19 15:55:14.944 INFO 10924 --- [extShutdownHook] o.s.c.n.e.s.EurekaServiceRegistry : Unregistering application USER-SERVICE with eureka with status DOWN
2021-02-19 15:55:14.944 INFO 10924 --- [extShutdownHook] com.netflix.discovery.DiscoveryClient : Saw local status change event StatusChangeEvent [timestamp=1613721314944, current=DOWN, previous=UP]
2021-02-19 15:55:14.949 INFO 10924 --- [extShutdownHook] com.netflix.discovery.DiscoveryClient : Shutting down DiscoveryClient ...
2021-02-19 15:55:14.981 INFO 10924 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_USER-SERVICE/localhost:user-service:9023 - registration status: 204
2021-02-19 15:55:14.982 INFO 10924 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_USER-SERVICE/localhost:user-service:9023: registering service...
2021-02-19 15:55:14.996 INFO 10924 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_USER-SERVICE/localhost:user-service:9023 - registration status: 204
2021-02-19 15:55:14.998 INFO 10924 --- [extShutdownHook] com.netflix.discovery.DiscoveryClient : Unregistering ...
2021-02-19 15:55:15.001 INFO 10924 --- [extShutdownHook] com.netflix.discovery.DiscoveryClient : DiscoveryClient_USER-SERVICE/localhost:user-service:9023 - deregister status: 200
2021-02-19 15:55:15.006 INFO 10924 --- [extShutdownHook] com.netflix.discovery.DiscoveryClient : Completed shut down of DiscoveryClient
Disconnected from the target VM, address: '127.0.0.1:55666', transport: 'socket'
Process finished with exit code 0
经过一番排查(baidu)后,发现是由于缺少了web的相关依赖导致。后再在pom.xml中添加web相关依赖:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
之后便能正常启动User-Service,启动日志如下:
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.4.3)
2021-02-19 16:00:59.839 INFO 8704 --- [ main] com.spd.lern.UserServiceApplication : Starting UserServiceApplication using Java 1.8.0_231 on DESKTOP-XXXXXXX with PID 8704 (D:\workspace\workspace_for_java\SPB-LERN\User-Service\target\classes started by xxx in D:\workspace\workspace_for_java\SPB-LERN\User-Service)
2021-02-19 16:00:59.842 INFO 8704 --- [ main] com.spd.lern.UserServiceApplication : No active profile set, falling back to default profiles: default
2021-02-19 16:01:00.662 INFO 8704 --- [ main] o.s.cloud.context.scope.GenericScope : BeanFactory id=4ff32662-75df-35cb-86dd-6dff8742a425
2021-02-19 16:01:00.968 INFO 8704 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 9023 (http)
2021-02-19 16:01:00.977 INFO 8704 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2021-02-19 16:01:00.978 INFO 8704 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.43]
2021-02-19 16:01:01.081 INFO 8704 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2021-02-19 16:01:01.081 INFO 8704 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1176 ms
2021-02-19 16:01:01.258 INFO 8704 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2021-02-19 16:01:02.555 INFO 8704 --- [ main] o.s.cloud.commons.util.InetUtils : Cannot determine local hostname
2021-02-19 16:01:02.598 INFO 8704 --- [ main] DiscoveryClientOptionalArgsConfiguration : Eureka HTTP Client uses RestTemplate.
2021-02-19 16:01:03.862 INFO 8704 --- [ main] o.s.cloud.commons.util.InetUtils : Cannot determine local hostname
2021-02-19 16:01:03.907 WARN 8704 --- [ main] iguration$LoadBalancerCaffeineWarnLogger : Spring Cloud LoadBalancer is currently working with the default cache. You can switch to using Caffeine cache, by adding it and org.springframework.cache.caffeine.CaffeineCacheManager to the classpath.
2021-02-19 16:01:03.984 INFO 8704 --- [ main] o.s.c.n.eureka.InstanceInfoFactory : Setting initial instance status as: STARTING
2021-02-19 16:01:04.017 INFO 8704 --- [ main] com.netflix.discovery.DiscoveryClient : Initializing Eureka in region us-east-1
2021-02-19 16:01:04.022 INFO 8704 --- [ main] c.n.d.s.r.aws.ConfigClusterResolver : Resolving eureka endpoints via configuration
2021-02-19 16:01:04.113 INFO 8704 --- [ main] com.netflix.discovery.DiscoveryClient : Disable delta property : false
2021-02-19 16:01:04.113 INFO 8704 --- [ main] com.netflix.discovery.DiscoveryClient : Single vip registry refresh property : null
2021-02-19 16:01:04.113 INFO 8704 --- [ main] com.netflix.discovery.DiscoveryClient : Force full registry fetch : false
2021-02-19 16:01:04.113 INFO 8704 --- [ main] com.netflix.discovery.DiscoveryClient : Application is null : false
2021-02-19 16:01:04.113 INFO 8704 --- [ main] com.netflix.discovery.DiscoveryClient : Registered Applications size is zero : true
2021-02-19 16:01:04.113 INFO 8704 --- [ main] com.netflix.discovery.DiscoveryClient : Application version is -1: true
2021-02-19 16:01:04.114 INFO 8704 --- [ main] com.netflix.discovery.DiscoveryClient : Getting all instance registry info from the eureka server
2021-02-19 16:01:04.272 INFO 8704 --- [ main] com.netflix.discovery.DiscoveryClient : The response status is 200
2021-02-19 16:01:04.274 INFO 8704 --- [ main] com.netflix.discovery.DiscoveryClient : Starting heartbeat executor: renew interval is: 30
2021-02-19 16:01:04.277 INFO 8704 --- [ main] c.n.discovery.InstanceInfoReplicator : InstanceInfoReplicator onDemand update allowed rate per min is 4
2021-02-19 16:01:04.282 INFO 8704 --- [ main] com.netflix.discovery.DiscoveryClient : Discovery Client initialized at timestamp 1613721664281 with initial instances count: 0
2021-02-19 16:01:04.283 INFO 8704 --- [ main] o.s.c.n.e.s.EurekaServiceRegistry : Registering application USER-SERVICE with eureka with status UP
2021-02-19 16:01:04.283 INFO 8704 --- [ main] com.netflix.discovery.DiscoveryClient : Saw local status change event StatusChangeEvent [timestamp=1613721664283, current=UP, previous=STARTING]
2021-02-19 16:01:04.285 INFO 8704 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_USER-SERVICE/localhost:user-service:9023: registering service...
2021-02-19 16:01:04.311 INFO 8704 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 9023 (http) with context path ''
2021-02-19 16:01:04.312 INFO 8704 --- [ main] .s.c.n.e.s.EurekaAutoServiceRegistration : Updating port to 9023
2021-02-19 16:01:04.337 INFO 8704 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_USER-SERVICE/localhost:user-service:9023 - registration status: 204
2021-02-19 16:01:05.427 INFO 8704 --- [ main] o.s.cloud.commons.util.InetUtils : Cannot determine local hostname
2021-02-19 16:01:05.452 INFO 8704 --- [ main] com.spd.lern.UserServiceApplication : Started UserServiceApplication in 7.27 seconds (JVM running for 8.04)
并且在Eureka中成功注册,如下图:
Eureka注册中心