• 快速搭建单机版Spring Cloud EurekaServer


    原文链接:http://www.yiidian.com/springcloud/build-eureka-single.html

    本文介绍搭建单机版的Eureka Server服务

    1 创建项目,导入依赖

    <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">
    	<modelVersion>4.0.0</modelVersion>
    	<groupId>com.yiidian</groupId>
    	<artifactId>eureka-server</artifactId>
    	<version>0.0.1-SNAPSHOT</version>
    	<parent>
    		<groupId>org.springframework.boot</groupId>
    		<artifactId>spring-boot-starter-parent</artifactId>
    		<version>2.0.1.RELEASE</version>
    		<relativePath />
    	</parent>
    
    	<properties>
    		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    		<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    		<java.version>1.8</java.version>
    		<!-- SpringCloud版本,F系列 -->
    		<spring-cloud.version>Finchley.RC1</spring-cloud.version>
    	</properties>
    
    	<dependencies>
    		<!-- Eureka服务端 -->
    		<dependency>
    			<groupId>org.springframework.cloud</groupId>
    			<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
    		</dependency>
    	</dependencies>
    
    	<dependencyManagement>
    		<dependencies>
    			<!-- SpringCloud依赖,一定要放到dependencyManagement中,起到管理版本的作用即可 -->
    			<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>
    
    	<repositories>
    		<repository>
    			<id>spring-milestones</id>
    			<name>Spring Milestones</name>
    			<url>https://repo.spring.io/milestone</url>
    			<snapshots>
    				<enabled>false</enabled>
    			</snapshots>
    		</repository>
    	</repositories>
    
    </project>
    

    2 配置Eureka

    建立application.yml,内容如下:

    server:
      port: 10086 # 端口
      
    spring:
      application:
        name: eureka-server # serviceID
        
    # 配置Eureka服务
    eureka:
      client:
        fetch-registry: false  # 是否拉取Eureka服务器的注册信息,默认true。单机版false,集群版true
        register-with-eureka: false   #  是否向Eureka服务器注册  ,默认true。单机版false,集群版true
        service-url:  # 注册地址
          defaultZone: http://127.0.0.1:${server.port}/eureka
    

    3 编写启动类

    package com.yiidian;
    
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
    
    @EnableEurekaServer  //开启Eurea Server
    @SpringBootApplication
    public class EurekaServerApplication {
    	
    	public static void main(String[] args) {
    		SpringApplication.run(EurekaServerApplication.class, args);
    	}
    
    }
    

    4 运行并访问Eureka Server

    运行启动类,浏览器访问: http://localhost:10086,效果如下:
    file

    file

    file

    欢迎关注我的公众号::一点教程。获得独家整理的学习资源和日常干货推送。
    如果您对我的系列教程感兴趣,也可以关注我的网站:yiidian.com

  • 相关阅读:
    Linux下使用rm删除文件,并排除指定文件
    使用use index优化sql查询
    PHP面试中经常出现的composer 问题总结
    MySQL全局锁库锁表
    《MySQL必懂系列》全局锁、表级锁、行锁
    Redis面试题(2020最新版)
    What is stabs?
    链接与加载
    MachO之Segment初探
    为什么要在预编译头中加__OBJC__?
  • 原文地址:https://www.cnblogs.com/yiidian/p/12403063.html
Copyright © 2020-2023  润新知