zoukankan      html  css  js  c++  java
  • 解决eureka集群报错Root name 'timestamp' does not match expected ('instance')

    最近搭建eureka集群注册中心时,单机版的没有问题,但是在搭建集群版时,项目启动后报错:

    Root name 'timestamp' does not match expected ('instance')

    因为我给eureka添加了登录认证,所以每个节点在相互注册时需要加上用户名和密码,配置如下:
    server.port=7902
    spring.application.name=eureka
    
    #安全中心配置登录用户名密码
    spring.security.user.name=root
    spring.security.user.password=root
    
    #注册中心配置
    #禁止自己当做服务注册  禁止自己注册自己 集群模式时需要允许互相注册
    #eureka.client.register-with-eureka = false
    #屏蔽注册信息   集群模式时不能屏蔽
    #eureka.client.fetch-registry = false
    
    eureka.instance.hostname= eureka-7902
    eureka.client.service-url.defaultZone = http://root:root@eureka-7901:7901/eureka/,http://root:root@eureka-7903:7903/eureka/
    

      

      配置中的 http://root:root@eureka-7901:7901/eureka/
      这种路径,是eureka所支持的认证地址url,添加了安全认证后,集群的注册地址就需要按照这格式写:http://username:password@hostname:port/eureka/
      但是添加了认证后,集群在相互注册时,就会出现这个错误:Root name 'timestamp' does not match expected ('instance')
    查了好久才知道,集群方式需要关闭spring的csrf认证才行,单独写一个配置类,将csrf认证设置为关闭即可,代码如下:
    /**
     * csrf配置类
     *
     * @author Zhangzhiyong
     * @date 2021/7/23 16:29
     */
    @EnableWebSecurity
    @Configuration
    public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
        
        @Override
        public void configure(HttpSecurity http) throws Exception {
            http.csrf().disable();//关闭csrf认证,否则会报错Root name 'timestamp' does not match expected ('instance')
            super.configure(http);
        }
    }
    

      然后eureka集群就可以正常运行了。

  • 相关阅读:
    tar解压包的时候出现错误 gzip: stdin: not in gzip format
    解决Ubuntu刚装好的时候su命令密码错误的问题
    如何将Ubuntu左边的面板放到底部
    解决VMware安装Ubuntu的过程中窗口过小无法看到按钮的问题
    无法对视图创建索引,因为该视图未绑定到架构
    Matlab当中size() length()等函数讲解
    解决Matlab当中for循环运行慢的问题
    SqlServer如何获取存储过程的返回值
    Linux的五个查找命令
    linux安装redis官方教程
  • 原文地址:https://www.cnblogs.com/zhangzhiyong-/p/15062375.html
Copyright © 2011-2022 走看看