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

文章讲述了如何在SpringCloudEureka环境中,自定义Eureka服务器的端口号,并在YML配置中设置相应的实例名、注册行为和监控页面地址,以实现服务的独立部署和集群管理。

 

 

 导包

<?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/就好了
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值