• SpringBoot admin


    版本:

        <java.version>1.8</java.version>

       <spring-cloud.version>Greenwich.SR6</spring-cloud.version>  (admin server 不需要)

    依赖:

      

        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
            </dependency>
            <dependency>
                <groupId>de.codecentric</groupId>
                <artifactId>spring-boot-admin-starter-server</artifactId>
                <version>2.1.5</version>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-security</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-actuator</artifactId>
            </dependency>
          
        </dependencies>
    

    主类:

    @SpringBootApplication
    @EnableAdminServer
    public class AdminServceApplication {
        public static void main(String[] args) {
            SpringApplication.run(AdminServceApplication.class, args);
        }
    }

    添加配置类: springcloud升级到2.x后Eureka安全配置与1.x有部分变动,新版本的security默认开启csrf了,这里我们先关掉它,否则 服务端注册不上

    新建一个配置类:

    复制代码
    @EnableWebSecurity
    @Configuration
    public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
        @Override
        protected void configure(HttpSecurity http) throws Exception {
            //关闭csrf
            http.csrf().disable();
            //开启认证
             http.authorizeRequests().anyRequest().authenticated().and().httpBasic();
        }
    }
    复制代码

    配置文件: application.yml

    server:
      port: 9000
    #需要导入spring-boot-starter-security
    #为admin server 添加一个认证,当访问localhost:8761会要求验证
    management:
      endpoints:
        web:
          exposure:
            include: '*'
      endpoint:
        health:
          show-details: always
    spring:
      application:
        name: micro-admin
      security: #安全配置
        basic:
         enabled: true
        user:
          name: root
          password: root

    #####################   至此 , admin server 搭建完毕 ########################

    下面是使用:

    依赖:

      

    <dependency>
                <groupId>de.codecentric</groupId>
                <artifactId>spring-boot-admin-starter-client</artifactId>
                <version>2.1.5</version>
     </dependency>

    application.yml:

    spring:
      application:
        name: MICRO-CLENT1-USER
      boot:
        admin:
          client:
            url:  http://root:root@localhost:9000
        
    management:
      endpoints:
        web:
          exposure:
            include: '*'
      endpoint:
        health: #健康检测 查看 http://localhost:8761/actuator/health
          show-details: always

    或者 application.properties

    eureka.client.service-url.defaultZone = http://root:root@192.168.25.140:8761/eureka/,http://root:root@192.168.25.141:8761/eureka/
    #spring.boot.admin.client.url = http://root:root@192.168.25.143:9000
    spring.boot.admin.client.url = http://192.168.25.143:9000
    spring.boot.admin.client.username=root
    spring.boot.admin.client.password=root
    management.endpoints.web.exposure.include =* management.endpoint.health.show-details= ALWAYS
    eureka.instance.prefer-ip-address = true
    spring.boot.admin.client.instance.service-base-url = http://192.168.18.129:7089 //自动申明IP



    check:

      http://127.0.0.1:9000/#/applications

  • 相关阅读:
    安装提示设备为允许启用的解决办法
    xargs命令
    MariaDB链接超时优化
    灵活QinQ配置
    批量删除.pyo后缀的文件
    netcat的使用
    xxe(xml外部实体注入)
    渗透测试前:信息收集
    windows文件命名特性利用漏洞
    ssrf(Server-Side Request Forgery)
  • 原文地址:https://www.cnblogs.com/lshan/p/13176205.html
Copyright © 2020-2023  润新知