1.0 Nepxion企业级云原生微服务方案-环境搭建

318 阅读4分钟

Nepxion

简介

Nepxion企业级云原生微服务解决方案

Discovery【探索】微服务框架,基于Spring Cloud & Spring Cloud Alibaba,Discovery服务注册发现、Ribbon & Spring Cloud LoadBalancer负载均衡、Feign & RestTemplate & WebClient调用、Spring Cloud Gateway & Zuul过滤等组件全方位增强的企业级微服务开源解决方案,更贴近企业级需求,更具有企业级的插件引入、开箱即用特征

① 微服务框架支持的基本功能,如下

  • 支持阿里巴巴Spring Cloud Alibaba中间件生态圈
  • 支持阿里巴巴Nacos、Eureka、Consul和Zookeeper四个服务注册发现中心
  • 支持阿里巴巴Nacos、携程Apollo、Redis、Zookeeper、Consul和Etcd六个远程配置中心
  • 支持阿里巴巴Sentinel、Hystrix和Resilience4J三个熔断限流降级权限中间件
  • 支持OpenTracing和OpenTelemetry规范下的调用链中间件,Jaeger、SkyWalking和Zipkin等
  • 支持Prometheus Micrometer和Spring Boot Admin两个指标中间件
  • 支持Java Agent解决异步跨线程ThreadLocal上下文传递
  • 支持Spring Spel解决蓝绿灰度参数的驱动逻辑
  • 支持Spring Matcher解决元数据匹配的通配逻辑
  • 支持Spring Cloud Gateway、Zuul网关和微服务三大模块的蓝绿灰度发布等一系列功能
  • 支持和兼容Spring Cloud Edgware版、Finchley版、Greenwich版、Hoxton版和202x版以及更高的Spring Cloud版本
  • 支持和兼容Java8~Java16以及更高的SDK版本

准备工作

本次主要以Nacos2.0的版本作为服务注册发现和配置中心。

下载nacos的版本 github.com/alibaba/nac…

本文主要在window的情况下安装部署nacos 解压nacos的到指定的路径下,然后到bin目录下,修改startup.cmd

#将集群模式修改为标准单机模式
set MODE="standalone"
set FUNCTION_MODE="all"
set SERVER=nacos-server
set MODE_INDEX=-1
set FUNCTION_MODE_INDEX=-1
set SERVER_INDEX=-1
set EMBEDDED_STORAGE_INDEX=-1
set EMBEDDED_STORAGE=""

startup.cmd启动程序

"nacos is starting with standalone"

         ,--.
       ,--.'|
   ,--,:  : |                                           Nacos 2.1.0
,`--.'`|  ' :                       ,---.               Running in stand alone mode, All function modules
|   :  :  | |                      '   ,'\   .--.--.    Port: 8848
:   |   \ | :  ,--.--.     ,---.  /   /   | /  /    '   Pid: 82584
|   : '  '; | /       \   /     \.   ; ,. :|  :  /`./   Console: http://172.21.1.29:8848/nacos/index.html
'   ' ;.    ;.--.  .-. | /    / ''   | |: :|  :  ;_
|   | | \   | \__\/: . ..    ' / '   | .; : \  \    `.      https://nacos.io
'   : |  ; .' ," .--.; |'   ; :__|   :    |  `----.   \
|   | '`--'  /  /  ,.  |'   | '.'|\   \  /  /  /`--'  /
'   : |     ;  :   .'   \   :    : `----'  '--'.     /
;   |.'     |  ,     .-./\   \  /            `--'---'
'---'        `--`---'     `----'

2022-08-08 15:52:03,033 INFO Bean 'org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler@41200e0c' of type [org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)

2022-08-08 15:52:03,056 INFO Bean 'methodSecurityMetadataSource' of type [org.springframework.security.access.method.DelegatingMethodSecurityMetadataSource] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)

2022-08-08 15:52:04,225 INFO Tomcat initialized with port(s): 8848 (http)

2022-08-08 15:52:05,363 INFO Root WebApplicationContext: initialization completed in 14984 ms

2022-08-08 15:52:15,608 WARN There are no [com.alibaba.nacos.config.server.model.event.LocalDataChangeEvent] publishers for this event, please register

2022-08-08 15:52:22,255 INFO Initializing ExecutorService 'applicationTaskExecutor'

2022-08-08 15:52:22,568 INFO Adding welcome page: class path resource [static/index.html]

2022-08-08 15:52:23,286 INFO Creating filter chain: Ant [pattern='/**'], []

2022-08-08 15:52:23,346 INFO Creating filter chain: any request, [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter@27ace0b1, org.springframework.security.web.context.SecurityContextPersistenceFilter@11ebb1b6, org.springframework.security.web.header.HeaderWriterFilter@5d5b5fa7, org.springframework.security.web.csrf.CsrfFilter@5533dc72, org.springframework.security.web.authentication.logout.LogoutFilter@6869a3b3, org.springframework.security.web.savedrequest.RequestCacheAwareFilter@f3021cb, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter@7bc6d27a, org.springframework.security.web.authentication.AnonymousAuthenticationFilter@664e5dee, org.springframework.security.web.session.SessionManagementFilter@6107165, org.springframework.security.web.access.ExceptionTranslationFilter@64fc097e]

2022-08-08 15:52:23,550 INFO Initializing ExecutorService 'taskScheduler'

2022-08-08 15:52:23,598 INFO Exposing 2 endpoint(s) beneath base path '/actuator'

2022-08-08 15:52:23,822 INFO Tomcat started on port(s): 8848 (http) with context path '/nacos'

2022-08-08 15:52:23,829 INFO Nacos started successfully in stand alone mode. use embedded storage

2022-08-08 15:54:17,662 INFO Initializing Servlet 'dispatcherServlet'

2022-08-08 15:54:17,694 INFO Completed initialization in 30 ms

说明nacos监听了8448端口成功,打开浏览器输入http://localhost:8848/nacos

image.png 默认用户名密码nacos/nacos

环境搭建

① 下载代码,Git clone github.com/Nepxion/Dis…,分支为6.x.x-simple

② 代码导入IDE

修改配置文件

spring.cloud.nacos.discovery.username=nacos
spring.cloud.nacos.discovery.password=nacos

spring.cloud.nacos.config.username=nacos
spring.cloud.nacos.config.password=nacos

启动服务

  • 在IDE中,启动四个应用服务和两个网关服务,如下
类名微服务服务端口版本区域环境可用区
DiscoveryGuideServiceA1.javaA130011.0devenv1zone1
DiscoveryGuideServiceA2.javaA230021.1qacommonzone2
DiscoveryGuideServiceB1.javaB140011.0qaenv1zone1
DiscoveryGuideServiceB2.javaB240021.1devcommonzone2
DiscoveryGuideGateway.javaGateway50011.0
DiscoveryGuideZuul.javaZuul50021.0
  • 部署拓扑图

BasicTopology.jpg

环境验证

通过Postman工具验证

  • 导入Postman的测试脚本postman.json(位于根目录下)
  • 在Postman中执行目录结构下〔Nepxion〕->〔Discovery指南网关接口〕->〔Gateway网关调用示例〕,调用地址为http://localhost:5001/discovery-guide-service-a/invoke/gateway,相关的Header值已经预设,供开发者修改。执行通过Spring Cloud Gateway网关发起的调用,结果为如下格式
gateway 
-> [ID=discovery-guide-service-a][T=service][P=Nacos][H=192.168.0.107:3001][V=1.0][R=dev][E=env1][Z=zone1][G=discovery-guide-group][TID=48682.7508.15870951148324081][SID=49570.77.15870951148480000] 
-> [ID=discovery-guide-service-b][T=service][P=Nacos][H=192.168.0.107:4001][V=1.0][R=qa][E=env1][Z=zone2][G=discovery-guide-group][TID=48682.7508.15870951148324081][SID=49571.85.15870951189970000]

Nacos中有3个服务注册如下图

image.png

总结

本章节主要讲解Nepxion环境如何搭建,后续的章节我们会进行蓝绿部署,灰度部署,滚动部署的样例演示

参考

nepxion.gitee.io/discovery/#…