云配置出现请求执行错误。 endpoint=DefaultEndpoint{ serviceUrl='http://localhost:8761/} 来自 Eureka 服务器
Cloud config got Request execution error. endpoint=DefaultEndpoint{ serviceUrl='http://localhost:8761/} from Eureka server
我正在尝试为我的 4 个微服务实施 Discovery First Bootstrap 方式。第一个是从 git 获取配置的配置服务器,第二个是 Eureka 服务器。当我 运行 docker-撰写时,我的配置服务器无法向尤里卡注册。我有:
请求执行错误。 endpoint=DefaultEndpoint{ serviceUrl='http://localhost:8761/} 连接被拒绝
我的配置服务器
@EnableConfigServer
@EnableEurekaClient
@SpringBootApplication
public class ConfigServerApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigServerApplication.class, args);
}
application.yml
server:
port: 8888
spring:
cloud:
config:
server:
encrypt.enabled: false
git:
uri: https://github.com/Artuwok/artbook-config-repo/
searchPaths: userservice
username: Artuwok
password: Civilization1986
timeout: 10
force-pull: true
bootstrap.yml
spring:
application:
name: configserver
cloud:
config:
fail-fast: true
discovery.enabled: true
eureka:
client:
registerWithEureka: true
fetchRegistry: true
serviceUrl.defaultZone: http://localhost:8761/eureka/
尤里卡class
@SpringBootApplication
@EnableEurekaServer
public class EurekaServerApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaServerApplication.class, args);
}
尤里卡bootstrap.yml
server:
port: 8761
eureka:
client:
registerWithEureka: false
fetchRegistry: false
docker-compose.yml 完整配置
version: '3'
services:
configserver:
image: configserver:1.0
ports:
- "8888:8888"
depends_on:
- eurekaserver
restart: on-failure
eurekaserver:
image: eurekasvr:1.0
ports:
- "8761:8761"
users_db:
image: mysql:5.7
container_name: users_db
restart: always
environment:
- MYSQL_DATABASE=artbook
- MYSQL_ROOT_PASSWORD=password
- MYSQL_USER=user
- MYSQL_PASSWORD=password
volumes:
- users_db:/var/lib/mysql
ports:
- "3306:3306"
depends_on:
- eurekaserver
user-service:
image: userservice:1.0
ports:
- "8080:8080"
depends_on:
- eurekaserver
- configserver
restart: on-failure
volumes:
users_db:
所以最后我能够启动服务。非常注意 URL 您在其中发现服务。 如果您使用 docker 图片,您必须在 uri 和 url 中使用服务名称,而不是本地主机。 我的工作配置
spring:
application:
name: configserver
cloud:
config:
fail-fast: false
discovery.enabled: false
uri: http://configserver:8888
eureka:
client:
registerWithEureka: true
fetchRegistry: true
serviceUrl.defaultZone: http://eurekaserver:8761/eureka
您在 Docker 中同时配置服务器和 Eureka 服务器 运行。因此他们可以使用 Docker 中的名字相互联系,而不是 localhost
.
所以 Eureka 服务 URL 应该是:http://eurekaserver:8761/
.
您应该将下面的代码添加到 docker-compose.yml
中的 configserver
配置中:
links:
- eurekaserver
在您的应用程序属性文件中添加以下内容:
eureka.client.register-with-eureka=false
eureka.client.fetch-注册表=假
这使您的 eureka 服务器在默认端口 8080 上启动,这些属性还可以帮助您不将 eurekaServer 注册到它自己。
(EurekaServer 本身也是一个客户端。)
如果您想 运行 此服务器在端口 8761 上,请在您的 application.properties 文件中添加以下内容:
server.port=8761
PS- 当您不使用 docker 时它会有所帮助。
我正在尝试为我的 4 个微服务实施 Discovery First Bootstrap 方式。第一个是从 git 获取配置的配置服务器,第二个是 Eureka 服务器。当我 运行 docker-撰写时,我的配置服务器无法向尤里卡注册。我有:
请求执行错误。 endpoint=DefaultEndpoint{ serviceUrl='http://localhost:8761/} 连接被拒绝
我的配置服务器
@EnableConfigServer
@EnableEurekaClient
@SpringBootApplication
public class ConfigServerApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigServerApplication.class, args);
}
application.yml
server:
port: 8888
spring:
cloud:
config:
server:
encrypt.enabled: false
git:
uri: https://github.com/Artuwok/artbook-config-repo/
searchPaths: userservice
username: Artuwok
password: Civilization1986
timeout: 10
force-pull: true
bootstrap.yml
spring:
application:
name: configserver
cloud:
config:
fail-fast: true
discovery.enabled: true
eureka:
client:
registerWithEureka: true
fetchRegistry: true
serviceUrl.defaultZone: http://localhost:8761/eureka/
尤里卡class
@SpringBootApplication
@EnableEurekaServer
public class EurekaServerApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaServerApplication.class, args);
}
尤里卡bootstrap.yml
server:
port: 8761
eureka:
client:
registerWithEureka: false
fetchRegistry: false
docker-compose.yml 完整配置
version: '3'
services:
configserver:
image: configserver:1.0
ports:
- "8888:8888"
depends_on:
- eurekaserver
restart: on-failure
eurekaserver:
image: eurekasvr:1.0
ports:
- "8761:8761"
users_db:
image: mysql:5.7
container_name: users_db
restart: always
environment:
- MYSQL_DATABASE=artbook
- MYSQL_ROOT_PASSWORD=password
- MYSQL_USER=user
- MYSQL_PASSWORD=password
volumes:
- users_db:/var/lib/mysql
ports:
- "3306:3306"
depends_on:
- eurekaserver
user-service:
image: userservice:1.0
ports:
- "8080:8080"
depends_on:
- eurekaserver
- configserver
restart: on-failure
volumes:
users_db:
所以最后我能够启动服务。非常注意 URL 您在其中发现服务。 如果您使用 docker 图片,您必须在 uri 和 url 中使用服务名称,而不是本地主机。 我的工作配置
spring:
application:
name: configserver
cloud:
config:
fail-fast: false
discovery.enabled: false
uri: http://configserver:8888
eureka:
client:
registerWithEureka: true
fetchRegistry: true
serviceUrl.defaultZone: http://eurekaserver:8761/eureka
您在 Docker 中同时配置服务器和 Eureka 服务器 运行。因此他们可以使用 Docker 中的名字相互联系,而不是 localhost
.
所以 Eureka 服务 URL 应该是:http://eurekaserver:8761/
.
您应该将下面的代码添加到 docker-compose.yml
中的 configserver
配置中:
links:
- eurekaserver
在您的应用程序属性文件中添加以下内容:
eureka.client.register-with-eureka=false
eureka.client.fetch-注册表=假
这使您的 eureka 服务器在默认端口 8080 上启动,这些属性还可以帮助您不将 eurekaServer 注册到它自己。
(EurekaServer 本身也是一个客户端。)
如果您想 运行 此服务器在端口 8761 上,请在您的 application.properties 文件中添加以下内容:
server.port=8761
PS- 当您不使用 docker 时它会有所帮助。