免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 6312 | 回复: 1
打印 上一主题 下一主题

Spring Cloud云服务架构 - commonservice-eureka 项目过程构建 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2018-06-15 14:56 |只看该作者 |倒序浏览
我们针对于HongHu cloud的eureka项目做以下构建,整个构建的过程很简单,我会将每一步都构建过程记录下来,希望可以帮助到大家:
1. 创建一个名为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>  
  5.   
  6.     <parent>  
  7.         <groupId>com.ml.honghu</groupId>  
  8.         <artifactId>particle-commonservice</artifactId>  
  9.         <version>0.0.1-SNAPSHOT</version>  
  10.     </parent>  
  11.   
  12.     <artifactId>particle-commonservice-eureka</artifactId>  
  13.     <packaging>jar</packaging>  
  14.   
  15.     <name>particle-commonservice-eureka</name>  
  16.     <description>particle-commonservice project for Spring Boot</description>  
  17.   
  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>  
  31.          
  32.         <dependency>  
  33.             <groupId>org.springframework.boot</groupId>  
  34.             <artifactId>spring-boot-starter-test</artifactId>  
  35.             <scope>test</scope>  
  36.         </dependency>  
  37.   
  38.     </dependencies>  
  39.   
  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>  
  62.                   
  63.             </plugin>  
  64.         </plugins>  
  65.     </build>  
  66. </project>  
复制代码
2. 在启动类入口引用eureka的相关配置,代码如下:
  1. package com.ml.honghu;   
  2.    
  3. import org.springframework.boot.SpringApplication;   
  4. import org.springframework.boot.autoconfigure.SpringBootApplication;   
  5. import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;   
  6.    
  7. @EnableEurekaServer   
  8. @SpringBootApplication   
  9. public class ServiceApplication {   
  10.    
  11.     public static void main(String[] args) {   
  12.         SpringApplication.run(ServiceApplication.class, args);   
  13.     }   
  14. }   
复制代码
3. 配置application.yml文件
  1. # server (eureka 默认端口为:8761)  
  2. server:  
  3.   port: 8761  
  4.   
  5. # spring  
  6. spring:  
  7.   application:  
  8.     name: particle-commonservice-erueka  
  9.   
  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}  
  29.         
  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  
  39.   
  40. # 服务认证  
  41. security:   
  42.   basic:   
  43.     enabled: true  
  44.   user:   
  45.     name: honghu  
  46.     password: 123456  
  47.   
  48. management:  
  49.   security:  
  50.     enabled: false  
复制代码
4. 增加项目的log机制和打包运行机制(后面我们会详细编写针对于Linux Centos下的打包部署机制)
5. 自此整个项目部署完成

论坛徽章:
0
2 [报告]
发表于 2018-06-15 14:57 |只看该作者
希望可以帮助更多有兴趣研发spring cloud框架的朋友
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP