美文网首页
初始化Spring Cloud建立Eureka服务注册中心

初始化Spring Cloud建立Eureka服务注册中心

作者: 昕昕的爸爸 | 来源:发表于2018-12-05 13:49 被阅读0次

1、新建项目  

https://gitee.com/frankawp/vishnu  新建一个git项目

打开git bash

git clone https://gitee.com/frankawp/vishnu

git remote add vishnu https://gitee.com/frankawp/vishnu

touch test

git add .

git commit -m initial

git push origin master

初始化git完毕

刷新https://gitee.com/frankawp/vishnu  多了一个test文件

2、新建一个spring cloud的服务注册中心

登录https://start.spring.io/

先建一个注册中心

Group: cn.battlecruiser.vishnu

Artifact: vishnu-eureka

Search for dependencies :Eureka Server

Generate project

下载下来后,解开,将vishnu-eureka 放在vishnu目录下

为加快maven下载速度,加aliyun的maven仓库,maven settings.xml里

<mirror> 

   <id>nexus-aliyun</id> 

    <mirrorOf>central</mirrorOf>   

    <name>Nexus aliyun</name> 

    <url>https://maven.aliyun.com/nexus/content/groups/public</url> 

</mirror>

spring.io上初始化的工程用的是application.properties .  删掉好了,用bootstrap.yml内容如下

server:

  port: 1025

spring:

  application:

    name: vishnu-eureka-server

eureka:

  client:

    fetch-registry: false

    register-with-eureka: false

    serviceUrl:

      defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/

  instance:

    hostname: localhost

  server:  #配置属性,但由于 Eureka 自我保护模式以及心跳周期长的原因,经常会遇到 Eureka Server 不剔除已关停的节点的问题

    enable-self-preservation: false

    eviction-interval-timer-in-ms: 5000

测试一下:

cd vishnu-eureka

mvn clean package

mvn spring-boot:run

启动成功

http://localhost:1025/actuator 可以访问

但是登录不了主页 http://localhost:1025

main方法上没有@EnableEurekaServer注解   重启  可以了,不知道它的默认工程为什么没加这个。

3、加安全

pom.xml 加

<dependency>

<groupId>org.springframework.cloud</groupId>

<artifactId>spring-cloud-starter-security</artifactId>

</dependency>

启动后控制台会打印一个随机密码

Using generated security password: eaeed05e-a0ea-42aa-81d5-e27b485ba6ef

用户名是 : user

如果要自定义

bootstrap.yml中加

security:

  basic:

    enabled: true # 启用身份认证

  user:

    name: frank # 定义用户名

    password: frank123 # 定义密码

4、git push

git add .

git commit -m eureka-init

git push

相关文章

网友评论

      本文标题:初始化Spring Cloud建立Eureka服务注册中心

      本文链接:https://www.haomeiwen.com/subject/qkbvcqtx.html