咱们针对于 HongHu cloud 的 eureka 我的项目做以下构建,整个构建的过程很简略,我会将每一步都构建过程记录下来,心愿能够帮忙到大家:
- 创立一个名为 particle-common-eureka 的 maven 我的项目,继承 particle-commonservice,具体的 pom.xml 配置文件如下:
1. <?xml version="1.0" encoding="UTF-8"?>
2. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4. <modelVersion>4.0.0</modelVersion>
6. <parent>
7. <groupId>com.ml.honghu</groupId>
8. <artifactId>particle-commonservice</artifactId>
9. <version>0.0.1-SNAPSHOT</version>
10. </parent>
12. <artifactId>particle-commonservice-eureka</artifactId>
13. <packaging>jar</packaging>
15. <name>particle-commonservice-eureka</name>
16. <description>particle-commonservice project for Spring Boot</description>
18. <dependencies>
19. <dependency>
20. <groupId>org.springframework.cloud</groupId>
21. <artifactId>spring-cloud-starter-eureka-server</artifactId>
22. </dependency>
23. <dependency>
24. <groupId>org.springframework.boot</groupId>
25. <artifactId>spring-boot-starter-security</artifactId>
26. </dependency>
27. <dependency>
28. <groupId>org.springframework.boot</groupId>
29. <artifactId>spring-boot-devtools</artifactId>
30. </dependency>
32. <dependency>
33. <groupId>org.springframework.boot</groupId>
34. <artifactId>spring-boot-starter-test</artifactId>
35. <scope>test</scope>
36. </dependency>
38. </dependencies>
40. <build>
41. <plugins>
42. <plugin>
43. <groupId>org.springframework.boot</groupId>
44. <artifactId>spring-boot-maven-plugin</artifactId>
45. <executions>
46. <execution>
47. <id>1</id>
48. <goals>
49. <goal>repackage</goal>
50. </goals>
51. </execution>
52. <execution>
53. <id>2</id>
54. <goals>
55. <goal>build-info</goal>
56. </goals>
57. </execution>
58. </executions>
59. <configuration>
60. <executable>true</executable>
61. </configuration>
63. </plugin>
64. </plugins>
65. </build>
66. </project>
- 在启动类入口援用 eureka 的相干配置,代码如下:
1. package com.ml.honghu;
3. import org.springframework.boot.SpringApplication;
4. import org.springframework.boot.autoconfigure.SpringBootApplication;
5. import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
7. @EnableEurekaServer
8. @SpringBootApplication
9. public class ServiceApplication {11. public static void main(String[] args) {12. SpringApplication.run(ServiceApplication.class, args);
13. }
14. }
- 配置 application.yml 文件
1. # server (eureka 默认端口为:8761)
2. server:
3. port: 8761
5. # spring
6. spring:
7. application:
8. name: particle-commonservice-erueka
10. # eureka
11. eureka:
12. client:
13. # 是否注册到 eureka
14. register-with-eureka: true
15. # 是否从 eureka 获取注册信息
16. fetch-registry: false
17. availability-zones:
18. honghu: honghuZone
19. service-url:
20. honghuZone: http://honghu:123456@localhost:8761/eureka/
21. defaultZone: http://honghu:123456@localhost:8761/eureka/
22. instance:
23. prefer-ip-address: true
24. hostname: localhost
25. metadataMap:
26. zone: honghuZone
27. user: ${security.user.name}
28. password: {security.user.password}
30. # 指定环境
31. environment: dev
32. #指定数据中心
33. datacenter: honghu
34. # 敞开自我保护模式
35. server:
36. enable-self-preservation: false
37. #设置清理有效节点的工夫距离,默认 60000,即是 60s
38. eviction-interval-timer-in-ms: 60000
40. # 服务认证
41. security:
42. basic:
43. enabled: true
44. user:
45. name: honghu
46. password: 123456
48. management:
49. security:
50. enabled: false
- 减少我的项目的 log 机制和打包运行机制(前面咱们会具体编写针对于 Linux Centos 下的打包部署机制)(企业架构源码能够加求球:叁五三陆二肆柒二伍玖)
- 自此整个我的项目部署实现,通过手动形式进行 Run As –> Spring Boot App, 运行后果如下:
控制台运行后果:
拜访控制台并登陆:
控制台运行成果:
从当初开始,我这边会将近期研发的 spring cloud 微服务云架构的搭建过程和精华记录下来,帮忙更多有趣味研发 spring cloud 框架的敌人,大家来一起探讨 spring cloud 架构的搭建过程及如何使用于企业我的项目。