码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2018-12-13 20:55:13      阅读:281      评论:0      收藏:0      [点我收藏+]

标签:工程   with   sea   注解   project   https   clone   search   url   

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服务注册中心

标签:工程   with   sea   注解   project   https   clone   search   url   

原文地址:https://www.cnblogs.com/frankawp/p/10116273.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!