我正在尝试为我的4项微服务实现方式。首先是从git获取配置的配置服务器,其次是Eureka服务器。当我运行docker时,我的配置服务器无法向eureka注册。我有:
请求执行错误。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: truebootstrap.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/Eureca类
@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: falsedocker-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。如果您正在使用映像,则必须使用服务名称,而不是uri和uri中的本地主机.我的工作配置
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发布于 2019-03-25 12:03:17
配置服务器和Eureka服务器都在Docker中运行。这样他们就可以在Docker而不是localhost上使用自己的名字相互联系。
所以尤里卡服务网址应该是:http://eurekaserver:8761/。
您应该将下面的代码添加到configserver配置中的docker-compose.yml中。
links:
- eurekaserver发布于 2021-05-07 21:37:00
在应用程序中添加以下属性文件:
注册-与-eureka=false eureka.client.FETCH-注册表=false
这使得您的eureka服务器在默认端口8080上运行,这些属性还帮助您不将eurekaServer注册到自己。
(EurekaServer本身也是一个客户。)
如果要在端口8761上运行此服务器,请在application.properties文件中添加以下内容:
server.port=8761
PS-当你不使用码头时,它会有所帮助。
发布于 2022-10-09 07:57:34
我没有使用docker,但是我也收到了同样的错误,我在网上搜索了很多,但是没有发现任何东西。
然后,我只需停止服务器,只更新一次maven依赖项,然后尝试启动它的服务发现。成功了!!
我希望这能帮到一个人,他没有使用和停靠,得到了同样的。
也要确保在application.properties或application.yml中有这些配置
server.port=8761
spring.application.name=eureka-discovery
eureka.instance.hostname=localhost
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
eureka.client.service-url.defaultZone: http://localhost:8761/eurekahttps://stackoverflow.com/questions/55336558
复制相似问题