Zuul 服务器 运行 应用程序

Zuul Server run application

启动服务器时提示无法连接。我想知道为什么它试图寻找 192.168.100.16 而不是使用 localhost.

我尝试 运行 使用 -Djava.net.preferIPv4Stack = true 的应用程序,但这也不起作用。

application.yml

server:
  port: 9090

# remove that settings in production
management.security.enabled: false

eureka:
  client:
    serviceUrl:
      defaultZone: http://127.0.0.1:8761/eureka/

zuul:
  #Service will be mapped under the /api URI
  prefix: /api
#  Uncomment to disable auto-registering all services read from Eureka
#  ignoredServices: '*'
  routes:
    test:
      path: /redirect/**
      url: http://google.com
    customer-by-address:
      path: /customer-by-address/**
      url: http://localhost:9098
    customer-by-service:
      path: /customer-by-service/**
      serviceId: CUSTOMER-SERVICE
    static:
      path: /static/**

spring:
  application:
    name: zuul-server

netstat -tulpn

lesharb@LeshaRB ~ $ netstat -tulpn
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 127.0.0.1:44907         0.0.0.0:*               LISTEN      1969/java       
tcp        0      0 127.0.0.1:63342         0.0.0.0:*               LISTEN      1969/java       
tcp        0      0 0.0.0.0:49841           0.0.0.0:*               LISTEN      1969/java       
tcp        0      0 127.0.1.1:53            0.0.0.0:*               LISTEN      -               
tcp        0      0 0.0.0.0:43927           0.0.0.0:*               LISTEN      1969/java       
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      -               
tcp        0      0 127.0.0.1:46137         0.0.0.0:*               LISTEN      1969/java       
tcp        0      0 127.0.0.1:6942          0.0.0.0:*               LISTEN      1969/java       
tcp6       0      0 :::44811                :::*                    LISTEN      2210/java       
tcp6       0      0 :::36911                :::*                    LISTEN      3671/java       
tcp6       0      0 :::46165                :::*                    LISTEN      3671/java       
tcp6       0      0 :::41591                :::*                    LISTEN      3671/java       
tcp6       0      0 ::1:631                 :::*                    LISTEN      -               
tcp6       0      0 :::65336                :::*                    LISTEN      2210/java       
tcp6       0      0 :::9090                 :::*                    LISTEN      3671/java       
udp        0      0 0.0.0.0:38293           0.0.0.0:*                           -               
udp        0      0 127.0.1.1:53            0.0.0.0:*                           -               
udp        0      0 0.0.0.0:68              0.0.0.0:*                           -               
udp        0      0 192.168.100.12:123      0.0.0.0:*                           -               
udp        0      0 127.0.0.1:123           0.0.0.0:*                           -               
udp        0      0 0.0.0.0:123             0.0.0.0:*                           -               
udp        0      0 0.0.0.0:631             0.0.0.0:*                           -               
udp        0      0 0.0.0.0:50096           0.0.0.0:*                           -               
udp        0      0 0.0.0.0:5353            0.0.0.0:*                           -               
udp6       0      0 fe80::3468:6113:b62:123 :::*                                -               
udp6       0      0 ::1:123                 :::*                                -               
udp6       0      0 :::123                  :::*                                -               
udp6       0      0 :::44987                :::*                                -               
udp6       0      0 :::5353                 :::*                                -   

我有这样的错误

2017-09-05 10:49:35.310  WARN 3671 --- [nfoReplicator-0] c.n.d.s.t.d.RetryableEurekaHttpClient    : Request execution failed with message: java.net.ConnectException: Connection refused (Connection refused)
2017-09-05 10:49:35.310  WARN 3671 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient    : DiscoveryClient_ZUUL-SERVER/192.168.100.12:zuul-server:9090 - registration failed Cannot execute request on any known server

Zuul 正在尝试与 Eureka 通信以获取路由请求时要使用的服务列表。但是,您的 netstat 输出没有显示任何侦听端口 8761 的进程,而您的配置表明 Eureka 应该位于该端口。

正如 Faron 所说,您的 Zuul 实例正在尝试连接到 eureka 服务器。 您可以从 application.yml

中删除它
 eureka:
   client:
     serviceUrl:
       defaultZone: http://127.0.0.1:8761/eureka/

或启动尤里卡(特别是因为你有一些带有 serviceId 的路线)

如果你想有一个 zuul 和 eureka 的例子,这是一个很好的资源。 Creating microservice using Spring Cloud, Eureka and Zuul