1、搭建注册中心Eureka
1.1、在IntelliJ IDEA里面创建一个叫Eureka-Center的Maven项目,创建过程比较简单,我不再赘述。其中的pom.xml内容如下:
- <?xml version="1.0" encoding="UTF-8"?>
- <project xmlns="http://maven.apache.org/POM/4.0.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <parent>
- <artifactId>all-learning</artifactId>
- <groupId>com.lvxiaosha</groupId>
- <version>0.0.1-SNAPSHOT</version>
- </parent>
- <modelVersion>4.0.0</modelVersion>
-
- <artifactId>Eureka-Center</artifactId>
- <packaging>pom</packaging>
- <modules>
- <module>Eureka-Server</module>
- </modules>
-
- <properties>
- <maven.compiler.source>17</maven.compiler.source>
- <maven.compiler.target>17</maven.compiler.target>
- <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
- </properties>
- <dependencyManagement>
- <dependencies>
- <!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-dependencies -->
- <dependency>
- <groupId>org.springframework.cloud</groupId>
- <artifactId>spring-cloud-dependencies</artifactId>
- <version>2021.0.4</version>
- <type>pom</type>
- <scope>import</scope>
- </dependency>
-
-
- <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-parent -->
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-parent</artifactId>
- <version>2.7.3</version>
- <type>pom</type>
- </dependency>
-
- </dependencies>
- </dependencyManagement>
-
-
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <version>3.6.0</version>
- <configuration>
- <source>17</source>
- <target>17</target>
- <encoding>UTF-8</encoding>
- </configuration>
- </plugin>
- </plugins>
- </build>
- </project>
<dependencyManagement>和
1.2、在Eureka的Maven项目下创建一个子Module的Maven项目,起名字叫Eureka-Server,pom.xml内容如下:
- <?xml version="1.0" encoding="UTF-8"?>
- <project xmlns="http://maven.apache.org/POM/4.0.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <parent>
- <artifactId>Eureka-Center</artifactId>
- <groupId>com.lvxiaosha</groupId>
- <version>0.0.1-SNAPSHOT</version>
- </parent>
- <modelVersion>4.0.0</modelVersion>
-
- <artifactId>Eureka-Server</artifactId>
-
- <properties>
- <maven.compiler.source>17</maven.compiler.source>
- <maven.compiler.target>17</maven.compiler.target>
- <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
- </properties>
-
- <dependencies>
- <dependency>
- <groupId>org.springframework.cloud</groupId>
- <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
- </dependency>
- </dependencies>
-
- </project>
项目结构:
1.3、新建EurekaServerApplication项目启动类:
- import org.springframework.boot.WebApplicationType;
- import org.springframework.boot.autoconfigure.SpringBootApplication;
- import org.springframework.boot.builder.SpringApplicationBuilder;
- import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
-
- /**
- * Created by lvgp.
- */
- @SpringBootApplication
- @EnableEurekaServer
- public class EurekaServerApplication {
-
- public static void main(String[] args) {
- new SpringApplicationBuilder(EurekaServerApplication.class)
- .web(WebApplicationType.SERVLET)
- .run(args);
- }
-
- }
1.4、新建application.yml配置文件:
- ## 启动顺序: #1
-
- spring:
- application:
- name: eureka-server
- profiles:
- active: dev
-
- server:
- port: 20000
-
- eureka:
- client:
- fetch-registry: false
- register-with-eureka: false
- instance:
- ## 将localhost指向本机(host文件)
- hostname: localhost
1.5、启动EurekaServerApplication后,访问http://localhost:20000/
2、注册中心UI页面参数解读
currenttime:当前系统的时间,这个时间并不会自动地刷新,只有当你主动地刷新页面时,这个当前时间才会刷新。
uptime:表示自从注册中心启动到运行至今的时间。
lease expiration enable:是否启动租约过期 ( 服务续约,服务剔除,服务自保 ) 租约过期没有续约直接剔除服务。 false代表自保机关是开着的 服务自保。
renews threshold:每分钟最少的续约数。
renews:最后一分钟的续约数量。它不包括当前这一分钟,它表示的是上一分钟。
General Info
total-avail-memory:总可用内存
environment:名称
num-of-cpus:cpu个数
current-memory-usage:当前只用内存百分比
server-uptime: 启动到运行到现在的时间
registered-replicas:集群相邻复制节点
unavailable-replicas:不可用集群节点
available-replicas:可用集群节点