zoukankan      html  css  js  c++  java
  • Eureka实现高可用及为Eureka设置登录账号和密码

    本文通过两个eureka相互注册实现注册中心的高可用,同时为注册中心配置认证登录。

    • 需要用到的maven配置
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
            </dependency>
    
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-security</artifactId>
            </dependency>
    • 第一个服务配置:myEureka
    server:
      port: 9998 #服务注册中心端口号
    eureka:
      instance:
        hostname: localhost #服务注册中心IP地址
      client:
        registerWithEureka: true #是否向服务注册中心注册自己
        fetchRegistry: true #是否检索服务
        serviceUrl: #服务注册中心的配置内容,指定服务注册中心的位置
          defaultZone:  http://wangzhzh:wzz123@localhost:9999/eureka/
    
    spring:
      application:
        name: eureka-server
      # 安全认证的配置
      security:
        user:
          name: wangzhzh  # 用户名
          password: wzz123   # 用户密码
    • 第二个服务配置:myEureka2
    server:
      port: 9999 #服务注册中心端口号
    eureka:
      instance:
        hostname: localhost #服务注册中心IP地址
      client:
        registerWithEureka: true #是否向服务注册中心注册自己
        fetchRegistry: true #是否检索服务
        serviceUrl: #服务注册中心的配置内容,指定服务注册中心的位置
          defaultZone: http://wangzhzh:wzz123@localhost:9998/eureka/
    
    spring:
      application:
        name: eureka-server2
      # 安全认证的配置
      security:
        user:
          name: wangzhzh  # 用户名
          password: wzz123   # 用户密码
    • 开启eureka服务

    注意:我所使用的事spring cloud 2.0以上的版本,还需要在两个服务加配置文件。

    Spring Cloud 2.0 以上的security默认启用了csrf检验,要在eureka server端配置security的csrf检验为false。

    /**
     * @Description
     * @Author wzz
     * @Date 2019/10/10 17:22
     */
    @EnableWebSecurity
    public class SecurityConf extends WebSecurityConfigurerAdapter {
        @Override
        protected void configure(HttpSecurity http) throws Exception {
    
            super.configure(http);
    
            http.csrf().disable();
    
        }
    }
  • 相关阅读:
    JS调用App方法及App调用JS方法
    提升用户体验之 选用合适的鼠标光标
    js仿QQ拖拽删除
    Linux下安装 mongodb
    QQ分享-定制分享卡片
    js判断浏览器语言实现网站国际化
    js复制内容到剪切板
    为什么会有堆内存和栈内存之分
    Avro实现RPC
    zookeeper学习day01
  • 原文地址:https://www.cnblogs.com/wzzxz/p/11652837.html
Copyright © 2011-2022 走看看