随笔 - 836  文章 - 1 评论 - 40 阅读 - 102万
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

版本:

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

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

 

docker 安装:

spingcloud   admin:

sudo docker run -itd --restart unless-stopped  --name my_admin  -p 9000:9000 --net host -e JAVA_OPTS="-Xmx128m -Xss512k" -e ADMIN_USERNAME=sea -e ADMIN_PASSWORD=sea happysea/micro:admin

 

 

 

依赖:

  

复制代码
    <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/
eureka.instance.prefer-ip-address = true
spring.boot.admin.client.url = http://192.168.25.143:9000
spring.boot.admin.client.username=root
spring.boot.admin.client.password=root
spring.boot.admin.client.instance.service-base-url: http://${spring.cloud.client.ip-address}:${server.port}
#spring.boot.admin.client.instance.service-base-url = http://192.168.18.129:7089  //自动申明IP 
management.endpoints.web.exposure.include =*
management.endpoint.health.show-details= ALWAYS
复制代码

 

 

check:

  http://127.0.0.1:9000/#/applications

 

posted on   lshan  阅读(256)  评论(0编辑  收藏  举报
编辑推荐:
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?
点击右上角即可分享
微信分享提示