初始化Spring Cloud建立Eureka服務(wù)注冊中心

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的服務(wù)注冊中心

登錄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內(nèi)容如下

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 自我保護模式以及心跳周期長的原因,經(jīng)常會遇到 Eureka Server 不剔除已關(guān)停的節(jié)點的問題

? ? 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

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容