• 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();
    
        }
    }
  • 相关阅读:
    Andrew Ng
    Matlab 常用语法速记 1
    jQuery 中的常用函数
    JS 删除数组中指定的某个元素的方法
    layer 插件 在子页面关闭自身的方法
    U方法
    读取配置和动态配置(C方法)
    TP框架控制器和对应方法创建
    ThinkPHP基础(1)
    利用ThinkPHP做项目步骤
  • 原文地址:https://www.cnblogs.com/wzzxz/p/11652837.html
Copyright © 2020-2023  润新知