什么是Eureka?以及Eureka注册服务的搭建

 

 

 导包

<?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>springcloud</artifactId>
        <groupId>com.kuang</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>springcloud-eureka-7001</artifactId>

    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
    </properties>


<!--    导包-->
    <dependencies>
<!--      Eureka -server  -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-eureka-server</artifactId>
            <version>1.4.6.RELEASE</version>
        </dependency>
        <!--     热部署   -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
        </dependency>
    </dependencies>

</project>

 这是默认的Eureka server 的地址端口号为8761

如果我想用,子集的地址和自己的端口号,那么得在 yml配置文件里去写响应的配置,具体如下面的代码块实现

 yml

server:
  port: 7001
#Eureka配置
eureka:
  instance:
    hostname: localhost #Eureka 服务端的实例名称
  client:
    register-with-eureka: false  #表示是否向eureka注册中心注册自己
    fetch-registry: false  #fetch-registry 如果为false,则表示自己为注册中心,职责为维护自己的实例,不需要去注册服务
    service-url: #监控页面,交互的地址
      defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/

主启动类

package com.kuang.springcloud;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;

@SpringBootApplication//代表是一个springboot项目
@EnableEurekaServer//EnableEurekaServer 他是一个服务端的启动类,可以接收别人注册进来
public class EurekaServer_7001 {
    public static void main(String[] args) {
        SpringApplication.run(EurekaServer_7001.class,args);
    }
}

配置文件配置了,相当于把Eureka-server 那个类加载到IOC容器里供spring使用

然后允许就可以了,就是这么简单

http://localhost:7001/

注册的服务都会体现在这个位置 

 

 可以做一些集群

server:
  port: 7001
#Eureka配置
eureka:
  instance:
    hostname: localhost #Eureka 服务端的实例名称
  client:
    register-with-eureka: false  #表示是否向eureka注册中心注册自己
    fetch-registry: false  #fetch-registry 如果为false,则表示自己为注册中心,职责为维护自己的实例,不需要去注册服务
    service-url: #监控页面,交互的地址
      defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/ #注册的地址,给服务注册的地址,加个/eureka/就好了

猜你喜欢

转载自blog.csdn.net/qq_53374893/article/details/132388654