容器多机部署eureka及相关集群服务出现 Request execution failed with message: AuthScheme is null

预期部署方案:两个eureka+三个相关应用

注册时应用出现:Request execution failed with message: Cannot invoke "Object.getClass()" because "authScheme" is null,一开始认为未正确传递eureka配置的账户+密码,例:defaultZone: http://username:password@dev.bab.cn:8761/eureka/,检查后发现一切正常,`后续排查后得出结论容器内部署hostname不能是127.0.0.1,必须为容器内ip(本次直接配置的是外部转发域名),调整为hostname: ${POD_IP},当然也可能是受多个因素影响,如集群网络不通、端口或eureka启动端口配置不正确等:`

yml 复制代码
spring:
  security:
    basic:
      enabled: true
    user:
      name: eureka
      password: abc123456

eureka:
  datacenter: user-server
  environment: prod
  instance:
    hostname: ${POD_IP}  # 容器部署必须填写docker容器的ip
    instance-id: ${random.uuid}
  client:
    #    For stand-alone deployment, the following is false 单机部署的话以下为false
    register-with-eureka: ${IS_CLUSTERED:false}
    fetch-registry: ${IS_CLUSTERED:false}
    service-url:
      defaultZone: http://eureka:abc123456@bab.com/eureka/

网上其他说法总结:

  • 降级jdk到8(本次是openjdk17)

  • 升级spring core(本次spring boot3.0,core已经达到6.0)

  • 添加禁用csrf:

    java 复制代码
    @Bean
    public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception 			{
        http.csrf().disable().httpBasic();
        return http.build();
    }
  • 禁用csrf方案2(来自stack overflow):

    java 复制代码
    @Bean
    public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
        http
            .csrf(AbstractHttpConfigurer::disable)
            .authorizeHttpRequests(authConfig -> authConfig.anyRequest().authenticated())
            .httpBasic(httpBasic -> {
            })
            .logout(logout -> {
                logout.logoutUrl("/logout");
                logout.addLogoutHandler((request, response, authentication) -> authentication.setAuthenticated(false));
            });
        return http.build();
    }
  • 禁用csrf方案3:

    java 复制代码
    @Bean
    public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
        http
            .csrf().disable()
            .authorizeHttpRequests()
            .anyRequest().authenticated() // 任何请求都不需要认证:.anyRequest().permitAll()
            .and()
            .httpBasic();
        return http.build();
    }

以上办法都没有成功,而且还导致额外出现Root name 'timestamp' does not match expected错误。

遇到的其他问题:eureka存在两个实例时相关服务注册完成后自动断开,排查后因为两个eureka没有将register-with-eureka和etch-registry同时设置为true,且defaultZone的地址不是相互注册状态eureka1填写eureka2的ip、eureka2填写eureka1的ip,可减少为1台或重新配置defaultZone的ip

相关推荐
雨辰AI3 小时前
信创数仓分层建模|国产数据库 ODS/DWD/DWS 分层落地规范(金仓 / 达梦 / 高斯适配)
数据库·云原生·政务
阿里云云原生4 小时前
实验:回测、离线实验平台与题目级 Rubric丨AgentLoop 数据飞轮实践(四)
云原生·agent
LlmCraft|大模型工程实践6 小时前
08. Docker Compose 一键编排:多容器应用的指挥家
java·spring cloud·eureka
雾隐隐o7 小时前
Docker 镜像归档与容器管理
java·docker·eureka
Ningcode_cloud8 小时前
什么是CICD? GitLab + Jenkins 持续集成实战部署手册
运维·ci/cd·云原生·容器·gitlab·jenkins
瞬间&永恒~9 小时前
【Kubernetes】(十五)维护与升级、ETCD 备份和恢复
linux·运维·docker·云原生·kubernetes
小小程序员.¥10 小时前
docker基础
云原生·eureka
harmony&20 小时前
Docker 容器技术从入门到实战:容器、网络、存储与监控全解析
docker·云原生
分布式存储与RustFS21 小时前
RustFS 生命周期与分层:让冷数据自动搬家、热数据自己回家
云原生·开源·对象存储·分布式存储·s3·rustfs·性能基准
阿里云云原生1 天前
从 Inform 到 Operate:构建可持续运行的云成本巡检机制与 Mission 调度
云原生