在Eureka集群的基础上, 启动多个zuul实例
1. zuul pom.xml
<?xml version="1.0"?> <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.1.9.RELEASE</version> <relativePath/> </parent> <groupId>net.fsd</groupId> <artifactId>sfgzuul</artifactId> <version>0.0.1-SNAPSHOT</version> <name>sfgzuul</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <java.version>1.8</java.version> <spring-cloud.version>Greenwich.SR3</spring-cloud.version> <project.build.directory>target</project.build.directory> <skipTests>true</skipTests> </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-starter-netflix-zuul</artifactId> </dependency> </dependencies> <dependencyManagement> <dependencies> <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> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-antrun-plugin</artifactId> <executions> <execution> <phase>package</phase> <goals> <goal>run</goal> </goals> <configuration> <tasks> <echo>********+${project.build.directory}\${project.artifactId}-${project.version}.jar</echo> <echo>${project.basedir}</echo> <copy overwrite="true" tofile="${project.basedir}\\..\\..\\sfglib\\${project.artifactId}-${project.version}.jar" file="${project.build.directory}\\${project.artifactId}-${project.version}.jar"/> </tasks> </configuration> </execution> </executions> </plugin> </plugins> </build> </project> |
2. application-80.yml
eureka.client.serviceUrl.defaultZone=http://localhost:7761/eureka/ server.port=7780 spring.application.name=sfgzuul zuul.routes.sfgserver.path=/sfgserver/** zuul.routes.sfgserver.serviceId=sfgserver zuul.routes.sfgclient.path=/sfgclient/** zuul.routes.sfgclient.serviceId=sfgclient spring.main.allow-bean-definition-overriding=true ribbon.MaxAutoRetries=3 ribbon.MaxAutoRetriesNextServer=0 ribbon.ReadTimeout=5000 ribbon.ConnectTimeout=2000 |
3. application-81.yml
eureka.client.serviceUrl.defaultZone=http://localhost:7761/eureka/ server.port=7781 spring.application.name=sfgzuul zuul.routes.sfgserver.path=/sfgserver/** zuul.routes.sfgserver.serviceId=sfgserver zuul.routes.sfgclient.path=/sfgclient/** zuul.routes.sfgclient.serviceId=sfgclient spring.main.allow-bean-definition-overriding=true ribbon.MaxAutoRetries=3 ribbon.MaxAutoRetriesNextServer=0 ribbon.ReadTimeout=5000 ribbon.ConnectTimeout=2000 |
4. project
![](https://i-blog.csdnimg.cn/blog_migrate/50dacf45e691eeb41032f112c8933b70.png)
5. run each instance with STS
![](https://i-blog.csdnimg.cn/blog_migrate/dc0e566f4480a276d89628b1cc025c5b.png)
6. check instance in Eureka 集群
![](https://i-blog.csdnimg.cn/blog_migrate/b096302157d413627677914a386120d3.png)
![](https://i-blog.csdnimg.cn/blog_migrate/210d642bd291a6ca1f7a33b80b7afd80.png)