免费注册 查看新帖 |

Chinaunix

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

spring cloud云服务架构 - eureka 项目构建过程 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2018-07-03 11:13 |只看该作者 |倒序浏览
上一篇我们回顾了关于 spring cloud eureka的相关基础知识,现在我们针对于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.         <parent>
  6.                 <groupId>com.ml.honghu</groupId>
  7.                 <artifactId>particle-commonservice</artifactId>
  8.                 <version>0.0.1-SNAPSHOT</version>
  9.         </parent>

  10.         <artifactId>particle-commonservice-eureka</artifactId>
  11.         <packaging>jar</packaging>

  12.         <name>particle-commonservice-eureka</name>
  13.         <description>particle-commonservice project for Spring Boot</description>

  14.         <dependencies>
  15.                 <dependency>
  16.                         <groupId>org.springframework.cloud</groupId>
  17.                         <artifactId>spring-cloud-starter-eureka-server</artifactId>
  18.                 </dependency>
  19.                 <dependency>
  20.                         <groupId>org.springframework.boot</groupId>
  21.                         <artifactId>spring-boot-starter-security</artifactId>
  22.                 </dependency>
  23.                 <dependency>
  24.                         <groupId>org.springframework.boot</groupId>
  25.                         <artifactId>spring-boot-devtools</artifactId>
  26.                 </dependency>
  27.                
  28.                 <dependency>
  29.                         <groupId>org.springframework.boot</groupId>
  30.                         <artifactId>spring-boot-starter-test</artifactId>
  31.                         <scope>test</scope>
  32.                 </dependency>

  33.         </dependencies>

  34.         <build>
  35.                 <plugins>
  36.                         <plugin>
  37.                                 <groupId>org.springframework.boot</groupId>
  38.                                 <artifactId>spring-boot-maven-plugin</artifactId>
  39.                                 <executions>
  40.                                         <execution>
  41.                                                 <id>1</id>
  42.                                                 <goals>
  43.                                                         <goal>repackage</goal>
  44.                                                 </goals>
  45.                                         </execution>
  46.                         <execution>
  47.                                 <id>2</id>
  48.                             <goals>
  49.                                 <goal>build-info</goal>
  50.                             </goals>
  51.                         </execution>
  52.                                 </executions>
  53.                                 <configuration>
  54.                                         <executable>true</executable>
  55.                                 </configuration>
  56.                                
  57.                         </plugin>
  58.                 </plugins>
  59.         </build>
  60. </project>
复制代码

2. 在启动类入口引用eureka的相关配置,代码如下:

  1. package com.ml.honghu;

  2. import org.springframework.boot.SpringApplication;
  3. import org.springframework.boot.autoconfigure.SpringBootApplication;
  4. import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;

  5. @EnableEurekaServer
  6. @SpringBootApplication
  7. public class ServiceApplication {

  8.         public static void main(String[] args) {
  9.                 SpringApplication.run(ServiceApplication.class, args);
  10.         }
  11. }
复制代码

3. 配置application.yml文件

  1. # server (eureka 默认端口为:8761)
  2. server:
  3.   port: 8761

  4. # spring
  5. spring:
  6.   application:
  7.     name: particle-commonservice-erueka

  8. # eureka
  9. eureka:
  10.   client:
  11.     # 是否注册到eureka
  12.     register-with-eureka: true
  13.     # 是否从eureka获取注册信息
  14.     fetch-registry: false
  15.     availability-zones:
  16.       honghu: honghuZone
  17.     service-url:
  18.       honghuZone: http://honghu:123456@localhost:8761/eureka/
  19.       defaultZone: http://honghu:123456@localhost:8761/eureka/
  20.   instance:
  21.     prefer-ip-address: true
  22.     hostname: localhost
  23.     metadataMap:
  24.       zone: honghuZone
  25.       user: ${security.user.name}
  26.       password: {security.user.password}
  27.       
  28.   # 指定环境
  29.   environment: dev
  30.   #指定数据中心
  31.   datacenter: honghu
  32.   # 关闭自我保护模式
  33.   server:
  34.     enable-self-preservation: false
  35.   #设置清理无效节点的时间间隔,默认60000,即是60s
  36.     eviction-interval-timer-in-ms: 60000

  37. # 服务认证
  38. security:
  39.   basic:
  40.     enabled: true
  41.   user:
  42.     name: honghu
  43.     password: 123456

  44. management:
  45.   security:
  46.     enabled: false
复制代码

4. 增加项目的log机制和打包运行机制(后面我们会详细编写针对于Linux Centos下的打包部署机制)

从现在开始,我这边会将近期研发的spring cloud微服务云架构的搭建过程和精髓记录下来,帮助更多有兴趣研发spring cloud框架的朋友,大家来一起探讨spring cloud架构的搭建过程及如何运用于企业项目。


论坛徽章:
0
2 [报告]
发表于 2018-07-03 11:13 |只看该作者
感兴趣的可以企鹅1903832579
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP