Eureka管理界面自定义(Greenwich版)

Stella981
• 阅读 684

Eureka管理界面自定义

开发工具:SpringToolSuite 4
Spring-cloud版本:Greenwich.SR2,

近来公司用Eureka来做服务管理,要把服务端的界面增加些自己公司的属性上去,我简单的记录下修改的过程,过程如:

构建Eureka项目

创建Eureka项目

本人用的是SpringToolSuite的工具来构建Eureka项目,个人喜欢,工具可自行选择,pom.xml配置文件如下:

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.3.RELEASE</version>
    </parent>
    <properties>
        <java.version>1.8</java.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <spring-cloud.version>Greenwich.SR6</spring-cloud.version>
    </properties>
    <!-- 引入 eureka-serverr的核心包 -->
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
        </dependency>
    </dependencies>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

编写启动类

@EnableEurekaServer
@SpringBootApplication
public class ServerEurekaApplication extends SpringBootServletInitializer {

    private static final Logger logger = LoggerFactory.getLogger(ServerEurekaApplication.class);

    public static void main(String[] args) {
        ConfigurableApplicationContext context = SpringApplication.run(ServerEurekaApplication.class, args);
        ConfigurableEnvironment env = context.getEnvironment();
        logger.info(
                "\n----------------------------------------------------------\n\t"
                        + "Application '{}' is running! Access URLs:\n\t" + "Local: \t\thttp://localhost:{}"
                        + "\n----------------------------------------------------------",
                env.getProperty("spring.application.name"), env.getProperty("server.port"));
        logger.info("ServerEurekaApplication 已启动成功.....");
    }

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        return builder.sources(this.getClass());
    }
}

注意:
springboot启动方式:
    1、可以直接在main方法里用SpringApplication.run(EurekaServerApplication.class, args);运行
    2、使用SpringBootServletInitializer启动,不过需要实现configure方法,这样用的第二种
区别暂时就不在此讲解了。

配置文件

配置application.properties

# eureka 端口
server.port=5761
spring.application.name=eureka
# eureka 配置
eureka.instance.hostname=localhost
eureka.client.serviceUrl.defaultZone=http://${eureka.instance.hostname}:${server.port}/eureka/
eureka.instance.prefer-ip-address=true
eureka.instance.instance-id=http://${eureka.instance.hostname}:${server.port}

eureka.client.fetch-registry=true
eureka.client.register-with-eureka=false
eureka.server.enable-self-preservation=false
eureka.client.registry-fetch-interval-seconds=30
eureka.instance.lease-renewal-interval-in-seconds=15
eureka.instance.lease-expiration-duration-in-seconds=45
# logging文件配置
logging.config=classpath:logback-spring.xml
info.logging.path=/eureka/logs/custom-eureka

启动

Eureka管理界面自定义(Greenwich版)

自定义Eureka页面

修改页面模板

在本地仓库中找到spring-cloud-netflix-eureka-server.jar文件所在的目录,版本根据maven引入的版本号
Eureka管理界面自定义(Greenwich版)
打开jar文件
Eureka管理界面自定义(Greenwich版)
eureka.jar目录下的templates文件夹下存放了Erueka Server管理页面的模板文件,修改时可以将模板文件复制出来到当前项目的resources/templates/eureka目录下,然后进行自定义界面内容。

  1. header.ftlh:HOEM页面导航(导航模板页面模板)
  2. lastn.ftlh:页面整合模板,整合了header.ftlh与navbar.ftlh增加服务注册信息展示
  3. navbar.ftlh:System Status+DS Replicas(服务状态和集群信息页面模板)
  4. status.ftlh:Instance Info区域(显示服务器的基本状态)

找到status.ftlh文件,该文件是显示InstanceInfo 后面这一栏,文件中增加版权信息,代码如下:

<footer style="position: fixed;background-color: rgba(43, 166, 166, 0.5);color: #FFF;bottom: 0;left: 0;right: 0;text-align: center;height: 20px;
lie-height: 20px;">Copyright (C) Eureka 2019-2060, All Rights Reserved XXXXX</footer>

查看效果

重新运行eureka项目,访问原先的页面可以看到已经增加了公司版权一栏。
Eureka管理界面自定义(Greenwich版)

总结

以上是简单的修改了eureka页面的展示内容,当然再复杂的信息可以自行发挥,如包括可以修改logo,中文翻译,修改样式等。
由于本章设计的代码比较多,请结合源码进行学习
源码参考:https://gitee.com/viphzc/springcloud

点赞
收藏
评论区
推荐文章
blmius blmius
2年前
MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1
文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s
Wesley13 Wesley13
2年前
Spring Cloud Eureka源代码解析(1)Eureka启动,原生启动与SpringCloudEureka启动异同
Eureka作为服务注册中心对整个微服务架构起着最核心的整合作用,因此对Eureka还是有很大的必要进行深入研究。Eureka1.x版本是纯基于servlet的应用。为了与springcloud结合使用,除了本身eureka代码,还有个粘合模块springcloudnetflixeurekaserver。在我们启动EurekaServer实例
Easter79 Easter79
2年前
springCloud 搭建eureka服务之天坑
这里我是采用gradle来管理jar包的。1、使用idea创建一个gradle项目。2、编辑settings.gradle文件rootProject.name'jtm'//include'jtm_core'//include'jtm_sys'//include'jtm_eureka'
Easter79 Easter79
2年前
SpringCloud注册中心高可用搭建
SpringCloud的注册中心可以由Eureka、Consul、Zookeeper、ETCD等来实现,这里推荐使用SpringCloudEureka来实现注册中心,它基于Netfilix的Eureka做了二次封装,完成分布式服务中服务治理的功能,微服务系统中的服务注册与发现都通过这个注册中心来进行管理。引入EurekaServer依赖
Stella981 Stella981
2年前
Eureka 开发时快速剔除失效服务
Spring Cloud 版本:Dalston.SR5服务端配置:关闭保护机制eureka.server.enableselfpreservationfalse剔除失效服务间隔eureka.server.evictionintervaltimerinms2000客户端配置
Stella981 Stella981
2年前
Eureka
目录:一:Eureka介绍二:Eureka架构图三:Eureka组件四:Eureka作用五:Eureka和Zookeeper对比什么是Eureka  引入SpringCloud中文文档介绍EurekaisaREST(RepresentationalStateTransfer)
Stella981 Stella981
2年前
Golang注册Eureka的工具包goeureka发布
1.简介提供Go微服务客户端注册到Eureka中心。点击:github地址(https://www.oschina.net/action/GoToLink?urlhttps%3A%2F%2Fgithub.com%2FSimonWang00%2Fgoeureka),欢迎各位多多star!(已通过测试验证,用于正式生产部署)2.原理
Easter79 Easter79
2年前
SpringCloud Eureka服务治理机制
一、基础架构!(https://oscimg.oschina.net/oscnet/c088a917c16ee8be06202e47bd73e50a7a0.png)构建Eureka服务治理有三个核心角色:服务注册中心、服务提供者和服务消费者。上图就是这三个角色之间的通信工作架构图。服务注册中心(Eureka 
Stella981 Stella981
2年前
Spring Cloud 学习笔记
Eureka客户端的服务注册       Eureka客户端在运行时会向Eureka服务端发送周期性的心跳,Eureka服务端利用客户端周期性的心跳续约请求来保证注册表的实时性。其中客户端会向服务端提供一个如果多久没有向服务端发送心跳请求,就不再维护这个客户端的时间阈值。!eureka.instance.leaserenew
Stella981 Stella981
2年前
Spring Cloud Eureka的基础架构
基础架构服务注册中心:Eureka提供的服务端,提供服务注册于发现的功能,也就是在上一节中我们实现的eurekaserver服务提供者:提供服务的应用,可以是springBoot应用,也可以是其他技术平台且遵循Eureka通信机制的应用。它将自己提供的服务注册到Eureka,以供其他应用发现,也