• EUREKA Client 无法连接注册中心问题解决方案【连接被拒绝、不支持SSL协议消息、不能向任意已知的服务器发送请求】


    EUREKA Client 无法连接注册中心问题解决方案【连接被拒绝、不支持SSL协议消息、不能向任意已知的服务器发送请求】

    版本:HOXTON.SR8

    主要报错信息如下:

    1. //无法连接注册中心
    2. DiscoveryClient_CLIENT1/host.docker.internal:client1:8089 - registration failed Cannot execute request on any known server
    3. com.netflix.discovery.DiscoveryClient : DiscoveryClient_CLIENT1/host.docker.internal:client1:8089 - was unable to send heartbeat!
    4. com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server
    5. //使用了https协议
    6. Caused by: javax.net.ssl.SSLException: Unsupported or unrecognized SSL message

    我的方法也许不能帮你解决问题,但是一定能帮你排除掉一部分问题!

    解决方法如下:

            1. application.yml文件或者properties文件中的service-url替换为serviceUrl,default-zone替换为defaultZone,亲测有用,能解决一部分问题,重点检查拼写!!!

            2. 服务端关闭验证:

                    

    1. security:
    2. basic:
    3. enabled: false

            感觉没啥效果

            3. client端 fetch-registry未开启,在配置文件中把  eureka.client.fetch-registry设置为true,亲测有用,不过注册中心就别开这个配置了

            4. 使用了安全验证之后,服务端需要关闭CSRF验证,关闭方法在后面 

            5. 注册地址注意使用http协议而不要使用https协议,亲测有用,IDE有时候会自动帮你修改为https协议

            6. 服务端server.port端口就是你的注册中心注册服务的端口,如果你的server.port端口就是8761,那么你的注册地址中端口也是8761!

            7. 注册地址拼写错误,例如http://root:root@localhost:8761/eurake,看出了错误的地方了吗?注意 eurake 这个地方,正确的拼写是 eureka !一定要详细检查,我就是这个地方弄错了!

            8. application.yml 文件要放在resources文件夹中,注意检查,很多朋友都是这个问题

            9. server端的启动一定要在client端之前!!! 

      

    附上我的配置,实在不行可以用我的试试:

    server端:application.yml

    1. server:
    2. port: 8761
    3. address: localhost
    4. spring:
    5. security:
    6. user:
    7. name: root
    8. password: root
    9. security:
    10. basic:
    11. enabled: false
    12. eureka:
    13. instance:
    14. hostname: localhost
    15. client:
    16. fetch-registry: false
    17. register-with-eureka: false
    18. serviceUrl:
    19. defaultZone: http://root:root@localhost:8761/eureka

    server端pom.xml

    1. <?xml version="1.0" encoding="UTF-8"?>
    2. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    3. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    4. <modelVersion>4.0.0</modelVersion>
    5. <groupId>org.example</groupId>
    6. <artifactId>servicecenter1</artifactId>
    7. <version>2.0.9-SNAPSHOT</version>
    8. <name>servicecenter1</name>
    9. <!-- FIXME change it to the project's website -->
    10. <url>http://www.example.com</url>
    11. <properties>
    12. <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    13. <maven.compiler.source>1.8</maven.compiler.source>
    14. <maven.compiler.target>1.8</maven.compiler.target>
    15. <spring.cloud-version>Hoxton.SR8</spring.cloud-version>
    16. </properties>
    17. <parent>
    18. <groupId>org.springframework.boot</groupId>
    19. <artifactId>spring-boot-starter-parent</artifactId>
    20. <version>2.3.4.RELEASE</version>
    21. <relativePath/> <!-- lookup parent from repository -->
    22. </parent>
    23. <dependencyManagement>
    24. <dependencies>
    25. <dependency>
    26. <groupId>org.springframework.cloud</groupId>
    27. <artifactId>spring-cloud-dependencies</artifactId>
    28. <version>${spring.cloud-version}</version>
    29. <type>pom</type>
    30. <scope>import</scope>
    31. </dependency>
    32. </dependencies>
    33. </dependencyManagement>
    34. <dependencies>
    35. <dependency>
    36. <groupId>org.springframework.cloud</groupId>
    37. <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
    38. </dependency>
    39. <dependency>
    40. <groupId>org.springframework.boot</groupId>
    41. <artifactId>spring-boot-starter-security</artifactId>
    42. </dependency>
    43. <dependency>
    44. <groupId>junit</groupId>
    45. <artifactId>junit</artifactId>
    46. <version>4.11</version>
    47. <scope>test</scope>
    48. </dependency>
    49. </dependencies>
    50. <build>
    51. <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
    52. <plugins>
    53. <!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
    54. <plugin>
    55. <artifactId>maven-clean-plugin</artifactId>
    56. <version>3.1.0</version>
    57. </plugin>
    58. <!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
    59. <plugin>
    60. <artifactId>maven-resources-plugin</artifactId>
    61. <version>3.0.2</version>
    62. </plugin>
    63. <plugin>
    64. <artifactId>maven-compiler-plugin</artifactId>
    65. <version>3.8.0</version>
    66. </plugin>
    67. <plugin>
    68. <artifactId>maven-surefire-plugin</artifactId>
    69. <version>2.22.1</version>
    70. </plugin>
    71. <plugin>
    72. <artifactId>maven-jar-plugin</artifactId>
    73. <version>3.0.2</version>
    74. </plugin>
    75. <plugin>
    76. <artifactId>maven-install-plugin</artifactId>
    77. <version>2.5.2</version>
    78. </plugin>
    79. <plugin>
    80. <artifactId>maven-deploy-plugin</artifactId>
    81. <version>2.8.2</version>
    82. </plugin>
    83. <!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
    84. <plugin>
    85. <artifactId>maven-site-plugin</artifactId>
    86. <version>3.7.1</version>
    87. </plugin>
    88. <plugin>
    89. <artifactId>maven-project-info-reports-plugin</artifactId>
    90. <version>3.0.0</version>
    91. </plugin>
    92. </plugins>
    93. </pluginManagement>
    94. </build>
    95. </project>

    server端关闭csrf验证:

    1. package org.example.securityfonfig;
    2. import org.springframework.context.annotation.Configuration;
    3. import org.springframework.security.config.annotation.web.builders.HttpSecurity;
    4. import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
    5. import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
    6. /**
    7. * @author hello 师姐
    8. */
    9. @EnableWebSecurity
    10. @Configuration
    11. public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
    12. @Override
    13. protected void configure(HttpSecurity http) throws Exception {
    14. http.csrf().disable();
    15. super.configure(http);
    16. }
    17. }

    server端启动验证:

    1. package org.example;
    2. import org.springframework.boot.SpringApplication;
    3. import org.springframework.boot.WebApplicationType;
    4. import org.springframework.boot.autoconfigure.SpringBootApplication;
    5. import org.springframework.boot.builder.SpringApplicationBuilder;
    6. import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
    7. /**
    8. * Hello world!
    9. *
    10. * @author 17715
    11. */
    12. @SpringBootApplication
    13. @EnableEurekaServer
    14. public class App {
    15. public static void main(String[] args) {
    16. new SpringApplicationBuilder(App.class).web(WebApplicationType.SERVLET).run(args);
    17. }
    18. }

    client端application.yml

    1. server:
    2. port: 8089
    3. spring:
    4. application:
    5. name: client1
    6. security:
    7. user:
    8. name: root
    9. password: root
    10. eureka:
    11. client:
    12. serviceUrl:
    13. defaultZone: http://root:root@localhost:8761/eureka
    14. fetch-registry: true
    15. register-with-eureka: true

    client 端 pom.xml:

    1. <?xml version="1.0" encoding="UTF-8"?>
    2. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    3. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    4. <modelVersion>4.0.0</modelVersion>
    5. <groupId>org.example</groupId>
    6. <artifactId>eurakeclient</artifactId>
    7. <version>1.0-SNAPSHOT</version>
    8. <name>eurakeclient</name>
    9. <!-- FIXME change it to the project's website -->
    10. <url>http://www.example.com</url>
    11. <parent>
    12. <groupId>org.springframework.boot</groupId>
    13. <artifactId>spring-boot-starter-parent</artifactId>
    14. <version>2.3.4.RELEASE</version>
    15. <relativePath/> <!-- lookup parent from repository -->
    16. </parent>
    17. <properties>
    18. <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    19. <maven.compiler.source>1.8</maven.compiler.source>
    20. <maven.compiler.target>1.8</maven.compiler.target>
    21. <spring.cloud-version>Hoxton.SR8</spring.cloud-version>
    22. </properties>
    23. <dependencyManagement>
    24. <dependencies>
    25. <dependency>
    26. <groupId>org.springframework.cloud</groupId>
    27. <artifactId>spring-cloud-dependencies</artifactId>
    28. <version>${spring.cloud-version}</version>
    29. <type>pom</type>
    30. <scope>import</scope>
    31. </dependency>
    32. </dependencies>
    33. </dependencyManagement>
    34. <dependencies>
    35. <dependency>
    36. <groupId>org.springframework.boot</groupId>
    37. <artifactId>spring-boot-starter-web</artifactId>
    38. </dependency>
    39. <dependency>
    40. <groupId>org.springframework.cloud</groupId>
    41. <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
    42. </dependency>
    43. <dependency>
    44. <groupId>org.springframework.boot</groupId>
    45. <artifactId>spring-boot-starter-security</artifactId>
    46. </dependency>
    47. <dependency>
    48. <groupId>junit</groupId>
    49. <artifactId>junit</artifactId>
    50. <version>4.11</version>
    51. <scope>test</scope>
    52. </dependency>
    53. </dependencies>
    54. <build>
    55. <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
    56. <plugins>
    57. <!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
    58. <plugin>
    59. <artifactId>maven-clean-plugin</artifactId>
    60. <version>3.1.0</version>
    61. </plugin>
    62. <!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
    63. <plugin>
    64. <artifactId>maven-resources-plugin</artifactId>
    65. <version>3.0.2</version>
    66. </plugin>
    67. <plugin>
    68. <artifactId>maven-compiler-plugin</artifactId>
    69. <version>3.8.0</version>
    70. </plugin>
    71. <plugin>
    72. <artifactId>maven-surefire-plugin</artifactId>
    73. <version>2.22.1</version>
    74. </plugin>
    75. <plugin>
    76. <artifactId>maven-jar-plugin</artifactId>
    77. <version>3.0.2</version>
    78. </plugin>
    79. <plugin>
    80. <artifactId>maven-install-plugin</artifactId>
    81. <version>2.5.2</version>
    82. </plugin>
    83. <plugin>
    84. <artifactId>maven-deploy-plugin</artifactId>
    85. <version>2.8.2</version>
    86. </plugin>
    87. <!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
    88. <plugin>
    89. <artifactId>maven-site-plugin</artifactId>
    90. <version>3.7.1</version>
    91. </plugin>
    92. <plugin>
    93. <artifactId>maven-project-info-reports-plugin</artifactId>
    94. <version>3.0.0</version>
    95. </plugin>
    96. </plugins>
    97. </pluginManagement>
    98. </build>
    99. </project>

     client端启动文件:

    1. package org.example;
    2. import org.springframework.boot.SpringApplication;
    3. import org.springframework.boot.autoconfigure.SpringBootApplication;
    4. import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
    5. /**
    6. * Hello world!
    7. *
    8. * @author 17715
    9. */
    10. @SpringBootApplication
    11. @EnableEurekaClient
    12. public class App {
    13. public static void main(String[] args) {
    14. SpringApplication.run(App.class, args);
    15. }
    16. }

    附上我的成功截图

     最后希望各位都能尽快跑起来

    https://blog.csdn.net/namefailed/article/details/119712101
  • 相关阅读:
    2020-05-12 Linux基本操作
    SpringBoot项目设置能访问静态资源,resource/static目录下文件
    2020-04-25 Hadoop框架学习
    2020-05-24 vue简单语法
    2020-04-25 elasticsearch
    2020-04-25 kafka
    2020-04-11 函数式数据处理(Java8)
    2020-03-29 分布式事务解决方案(RocketMQ)
    配置文件示例
    Spring-data-redis实现消息队列的demo(附源码)
  • 原文地址:https://www.cnblogs.com/sunny3158/p/16636528.html
Copyright © 2020-2023  润新知