sp06zuul-3001
--server.port=3001
sp06zuul-3002
--server.port=3002
启动zuul
现在只能分开监控,如果要同时监控所有服务器,使用Turbine
eureka client 、 turbine
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>springcloud1</artifactId>
<groupId>cn.tedu</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<groupId>cn.tedu</groupId>
<artifactId>sp08-turbine</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>sp08-turbine</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-turbine</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<mainClass>cn.tedu.sp08.Sp08TurbineApplication</mainClass>
</configuration>
<executions>
<execution>
<id>repackage</id>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
# 聚合服务的id列表
zuul,item-service,user-service.............
# 为聚合后的数据命名 名字任意 default为默认名
new String("default")
************************************************************
spring:
application:
name: turbine
server:
port: 5001
eureka:
client:
service-url:
defaultZone: http://eureka1:2001/eureka,http://eureka2:2002/eureka
turbine:
app-config: zuul # aaa,bb,cc可聚合多个,用逗号隔开
cluster-name-expression: new String("default")
@EnableTurbine
package cn.tedu.sp08;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.turbine.EnableTurbine;
@SpringBootApplication
@EnableTurbine
public class Sp08TurbineApplication {
public static void main(String[] args) {
SpringApplication.run(Sp08TurbineApplication.class, args);
}
}
http://localhost:5001/turbine.stream
eureka注册中心效果
hystrix dashboard效果
eureka只是注册中心!!!!!!!!!
item-service-dev.yml
order-service-dev.yml
user-service-dev.yml
dev为开发环境,根据不同环境进行不同的配置
不加-dev为主配置,主配置与不同环境的配置同步加载
-dev -test -pro…
spring:
cloud:
config:
override-none: true
已经创建仓库的就不用创建了
eureka-client config server
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>springcloud1</artifactId>
<groupId>cn.tedu</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<groupId>cn.tedu</groupId>
<artifactId>sp09-config</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>sp09-config</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<mainClass>cn.tedu.sp09.Sp09ConfigApplication</mainClass>
</configuration>
<executions>
<execution>
<id>repackage</id>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
#Git仓库的地址:
https://gitee.com/pigeon01/springcloud1
#存放配置文件的目录
config
********************************
spring:
application:
name: config-server
cloud:
config:
server:
git:
uri: https://gitee.com/pigeon01/springcloud1
search-paths: config
server:
port: 6001
eureka:
client:
service-url:
defaultZone: http://eureka1:2001/eureka,http://eureka2:2002/eureka
@EnableConfigServer
package cn.tedu.sp09;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.config.server.EnableConfigServer;
@SpringBootApplication
@EnableConfigServer
public class Sp09ConfigApplication {
public static void main(String[] args) {
SpringApplication.run(Sp09ConfigApplication.class, args);
}
}
http://localhost:6001/item-service/dev
其实就在访问item-service-dev.yml
http://localhost:6001/user-service/dev
http://localhost:6001/order-service/dev
检查eureka中心
访问配置文件
修改2.3.4连接配置中心,下载配置
config client
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
3.bootstrap.yml配置
#从注册表获得配置中心的地址 再从配置中心下载配置文件
#eureka 地址
#指定配置中心的服务id
#下载指定的配置文件:
- user-service
- dev
*********************************************************
eureka:
client:
service-url:
defaultZone: http://eureka1:2001/eureka,http://eureka2:2002/eureka
spring:
cloud:
config:
discovery:
enabled: true #允许使用服务发现 去发现配置中心
service-id: config-server
name: user-service #文件名
profile: dev # user-service-dev.yml 为完整文件名
如果只启动user-service
版权说明 : 本文为转载文章, 版权归原作者所有 版权申明
原文链接 : https://blog.csdn.net/weixin_55740233/article/details/121395104
内容来源于网络,如有侵权,请联系作者删除!