Giter Site home page Giter Site logo

zhangxd1989 / spring-boot-cloud Goto Github PK

View Code? Open in Web Editor NEW
2.1K 204.0 1.2K 1.26 MB

基于 Spring Boot、Spring Cloud、Spring Oauth2 和 Spring Cloud Netflix 等框架构建的微服务项目

Java 100.00%
eureka zuul feign ribbon spring-cloud-sleuth spring-boot-admin zipkin oauth hystrix turbine spring-cloud consul

spring-boot-cloud's Introduction

基于 Spring Cloud 的微服务架构

本项目是一个基于 Spring Boot、Spring Cloud、Spring Oauth2 和 Spring Cloud Netflix 等框架构建的微服务项目。

技术栈

  • Spring boot - 微服务的入门级微框架,用来简化 Spring 应用的初始搭建以及开发过程。
  • Eureka - 云端服务发现,一个基于 REST 的服务,用于定位服务,以实现云端中间层服务发现和故障转移。
  • Spring Cloud Config - 配置管理工具包,让你可以把配置放到远程服务器,集中化管理集群配置,目前支持本地存储、Git 以及 Subversion。
  • Hystrix - 熔断器,容错管理工具,旨在通过熔断机制控制服务和第三方库的节点,从而对延迟和故障提供更强大的容错能力。
  • Zuul - Zuul 是在云平台上提供动态路由,监控,弹性,安全等边缘服务的框架。Zuul 相当于是设备和 Netflix 流应用的 Web 网站后端所有请求的前门。
  • Spring Cloud Bus - 事件、消息总线,用于在集群(例如,配置变化事件)中传播状态变化,可与 Spring Cloud Config 联合实现热部署。
  • Spring Cloud Sleuth - 日志收集工具包,封装了 Dapper 和 log-based 追踪以及 Zipkin 和 HTrace 操作,为 SpringCloud 应用实现了一种分布式追踪解决方案。
  • Ribbon - 提供云端负载均衡,有多种负载均衡策略可供选择,可配合服务发现和断路器使用。
  • Turbine - Turbine 是聚合服务器发送事件流数据的一个工具,用来监控集群下 hystrix 的 metrics 情况。
  • Spring Cloud Stream - Spring 数据流操作开发包,封装了与 Redis、Rabbit、Kafka 等发送接收消息。
  • Feign - Feign 是一种声明式、模板化的 HTTP 客户端。
  • Spring Cloud OAuth2 - 基于 Spring Security 和 OAuth2 的安全工具包,为你的应用程序添加安全控制。

应用架构

该项目包含 8 个服务

  • registry - 服务注册与发现
  • config - 外部配置
  • monitor - 监控
  • zipkin - 分布式跟踪
  • gateway - 代理所有微服务的接口网关
  • auth-service - OAuth2 认证服务
  • svca-service - 业务服务A
  • svcb-service - 业务服务B

体系架构

architecture

应用组件

components

启动项目

  • 使用 Docker 快速启动
    1. 配置 Docker 环境
    2. mvn clean package 打包项目及 Docker 镜像
    3. 在项目根目录下执行 docker-compose up -d 启动所有项目
  • 本地手动启动
    1. 配置 rabbitmq
    2. 修改 hosts 将主机名指向到本地
      127.0.0.1 registry config monitor rabbitmq auth-service
      或者修改各服务配置文件中的相应主机名为本地 ip
    3. 启动 registry、config、monitor、zipkin
    4. 启动 gateway、auth-service、svca-service、svcb-service

项目预览

注册中心

访问 http://localhost:8761/ 默认账号 user,密码 password

registry

监控

访问 http://localhost:8040/ 默认账号 admin,密码 admin

控制面板

monitor

应用注册历史

monitor

Turbine Hystrix面板

monitor

应用信息、健康状况、垃圾回收等详情

monitor

计数器

monitor

查看和修改环境变量

monitor

管理 Logback 日志级别

monitor

查看并使用 JMX

monitor

查看线程

monitor

认证历史

monitor

查看 Http 请求轨迹

monitor

Hystrix 面板

monitor

链路跟踪

访问 http://localhost:9411/ 默认账号 admin,密码 admin

控制面板

zipkin

链路跟踪明细

zipkin

服务依赖关系

zipkin

RabbitMQ 监控

Docker 启动访问 http://localhost:15673/ 默认账号 guest,密码 guest(本地 rabbit 管理系统默认端口15672)

rabbit

接口测试

  1. 获取 Token
curl -X POST -vu client:secret http://localhost:8060/uaa/oauth/token -H "Accept: application/json" -d "password=password&username=anil&grant_type=password&scope=read%20write"

返回如下格式数据:

{
  "access_token": "eac56504-c4f0-4706-b72e-3dc3acdf45e9",
  "token_type": "bearer",
  "refresh_token": "da1007dc-683c-4309-965d-370b15aa4aeb",
  "expires_in": 3599,
  "scope": "read write"
}
  1. 使用 access token 访问 service a 接口
curl -i -H "Authorization: Bearer eac56504-c4f0-4706-b72e-3dc3acdf45e9" http://localhost:8060/svca

返回如下数据:

svca-service (172.18.0.8:8080)===>name:zhangxd
svcb-service (172.18.0.2:8070)===>Say Hello
  1. 使用 access token 访问 service b 接口
curl -i -H "Authorization: Bearer eac56504-c4f0-4706-b72e-3dc3acdf45e9" http://localhost:8060/svcb

返回如下数据:

svcb-service (172.18.0.2:8070)===>Say Hello
  1. 使用 refresh token 刷新 token
curl -X POST -vu client:secret http://localhost:8060/uaa/oauth/token -H "Accept: application/json" -d "grant_type=refresh_token&refresh_token=da1007dc-683c-4309-965d-370b15aa4aeb"

返回更新后的 Token:

{
  "access_token": "63ff57ce-f140-482e-ba7e-b6f29df35c88",
  "token_type": "bearer",
  "refresh_token": "da1007dc-683c-4309-965d-370b15aa4aeb",
  "expires_in": 3599,
  "scope": "read write"
}
  1. 刷新配置
curl -X POST -vu user:password http://localhost:8888/bus/refresh

spring-boot-cloud's People

Contributors

zhangxd1989 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

spring-boot-cloud's Issues

docker启动报错问题

我先后执行了
git clone https://github.com/zhangxd1989/spring-boot-cloud.git
cd spring-boot-cloud
mvn clean package 报错,在pom.xml中添加

org.apache.maven.plugins
maven-surefire-plugin
2.18.1

true


解决了问题,然后执行docker-compose up -d,提示unkonwhost: register,错误退出137,我应该怎么修改,还有哪些操作是我遗漏的?谢谢!

每个服务都要有两个,会不会太麻烦?

scvb和scva这两个服务,我看代码在scva里的client里调了scvb的服务,大概意思就是每个功能模块都有要一个提供者和一个消费者,那这scvb和scva可以合并成一个不???

auth-service在admin里状态一直都是down

查找了发现原因是auth-service的health地址监听错了,但是代码完全是按照博主的写的,不知博主是怎么让它变成up的?这个是不是和自定义了eureka的health地址有关?
我在admin里右上角显示auth-service的health地址是
http://xxx:5000/mgmt/uaa/mgmt/health,多了一个mgmt,但不知道配置错在哪里,而直接访问
http://xxx:5000/uaa/mgmt/health是可以返回health信息的,这是什么原因?求解!

> > > @陈辰生 你好。我把你版本更新后的代码在docker里面跑起来了。但是不知道如何去访问呢?麻烦你可不可以在告诉我一下。

@陈辰生 你好。我把你版本更新后的代码在docker里面跑起来了。但是不知道如何去访问呢?麻烦你可不可以在告诉我一下。
image
image

项目的 README 里有讲呀

访问http://localhost:8761/ 访问不到服务。
image

那 8040 能访问吗, 你可以到我项目里提个 issue

Originally posted by @chenchensheng in #24 (comment)

rabbitmq

spring:
application:
name: zipkin
rabbitmq:
host: rabbitmq

请问上述配置中的 host:rabbitmq 是指向自己的rabbitmq服务吗,也就是本地跑应用还需要安装搭建rabbitmq?还是指向其他的

遇到的问题

请问在docker-compose up的时候,总是有几个服务应用不能启动

能否提供一下docker部署的example

java.lang.IllegalStateException: Could not locate PropertySource and the fail fast property is set, failing

java.lang.IllegalStateException: Could not locate PropertySource and the fail fast property is set, failing
at org.springframework.cloud.config.client.ConfigServicePropertySourceLocator.locate(ConfigServicePropertySourceLocator.java:132)
at org.springframework.cloud.config.client.ConfigServicePropertySourceLocator$$FastClassBySpringCGLIB$$fa44b2a.invoke()
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:721)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.retry.interceptor.RetryOperationsInterceptor$1.doWithRetry(RetryOperationsInterceptor.java:91)
at org.springframework.retry.support.RetryTemplate.doExecute(RetryTemplate.java:286)
at org.springframework.retry.support.RetryTemplate.execute(RetryTemplate.java:163)
at org.springframework.retry.interceptor.RetryOperationsInterceptor.invoke(RetryOperationsInterceptor.java:118)
at org.springframework.retry.annotation.AnnotationAwareRetryOperationsInterceptor.invoke(AnnotationAwareRetryOperationsInterceptor.java:152)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:656)
at org.springframework.cloud.config.client.ConfigServicePropertySourceLocator$$EnhancerBySpringCGLIB$$4b3405c.locate()
at org.springframework.cloud.bootstrap.config.PropertySourceBootstrapConfiguration.initialize(PropertySourceBootstrapConfiguration.java:93)
at org.springframework.boot.SpringApplication.applyInitializers(SpringApplication.java:611)
at org.springframework.boot.SpringApplication.prepareContext(SpringApplication.java:348)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:312)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1162)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1151)
at cn.zhangxd.gateway.GatewayApplication.main(GatewayApplication.java:14)
Caused by: org.springframework.web.client.ResourceAccessException: I/O error on GET request for "http://localhost:8888/gateway/default": Connection refused: connect; nested exception is java.net.ConnectException: Connection refused: connect
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:666)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:613)
at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:531)
at org.springframework.cloud.config.client.ConfigServicePropertySourceLocator.getRemoteEnvironment(ConfigServicePropertySourceLocator.java:172)
at org.springframework.cloud.config.client.ConfigServicePropertySourceLocator.locate(ConfigServicePropertySourceLocator.java:93)
... 19 common frames omitted
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:345)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at java.net.Socket.connect(Socket.java:538)
at sun.net.NetworkClient.doConnect(NetworkClient.java:180)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:432)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:527)
at sun.net.www.http.HttpClient.(HttpClient.java:211)
at sun.net.www.http.HttpClient.New(HttpClient.java:308)
at sun.net.www.http.HttpClient.New(HttpClient.java:326)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:1167)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1103)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:997)
at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:931)
at org.springframework.http.client.SimpleBufferingClientHttpRequest.executeInternal(SimpleBufferingClientHttpRequest.java:78)
at org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal(AbstractBufferingClientHttpRequest.java:48)
at org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:53)
at org.springframework.http.client.InterceptingClientHttpRequest$InterceptingRequestExecution.execute(InterceptingClientHttpRequest.java:99)
at org.springframework.cloud.config.client.ConfigServicePropertySourceLocator$GenericRequestHeaderInterceptor.intercept(ConfigServicePropertySourceLocator.java:237)
at org.springframework.http.client.InterceptingClientHttpRequest$InterceptingRequestExecution.execute(InterceptingClientHttpRequest.java:86)
at org.springframework.http.client.InterceptingClientHttpRequest.executeInternal(InterceptingClientHttpRequest.java:70)
at org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal(AbstractBufferingClientHttpRequest.java:48)
at org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:53)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:652)
... 23 common frames omitted

Process finished with exit code 1

测试获取Token接口报错

请问用http请求怎么测试?通过postman怎么调用?获取token的接口我转成http调用调不通,返回{

"timestamp": 1566802688851,
"status": 401,
"error": "Unauthorized",
"message": "Full authentication is required to access this resource",
"path": "/uaa/oauth/token"

多个微服务,如何优雅地调试?

楼主,你好!感谢分享!刚解除微服务,不太了解,8个微服务如何调试呢?是不是要用IDEA同时打开,然后同时运行这8个微服务呢?谢谢

大神你好 关于oauth的问题想问下

大神 按照github上的实例我搭建成功了,最后卡在了oauth认证这里,
我部分程序在跑在winods上面,使用postman调用的话如何使用
curl -X POST -vu client:secret http://localhost:8060/uaa/oauth/token -H "Accept: application/json" -d "password=password&username=anil&grant_type=password&scope=read%20write"
我理解为
{

"password": "password",
"username": "anil",
"grant_type": "password",
"scope": "read"
}
但是返回都是
{
"timestamp": 1496748152926,
"status": 401,
"error": "Unauthorized",
"message": "Full authentication is required to access this resource",
"path": "/uaa/oauth/token"
}
请问我该如何做,可以留下你的联系方式吗QQ 邮箱之类的

遇到问题

希望和建议:
1、项目的部署启动文档有点少,没有cloud搭建经验很难运行启动起来。
2、项目的数据库能不能配置多个,基础的Java程序员用mysql可能会好一些。

Hystrix仪表盘

报这个错误:Unable to connect to Command Metric Stream 'api/turbine/stream?cluster=default'.
Error: {"isTrusted":true}

在网上找资料:新加入三个包spring-cloud-starter-hystrix,spring-boot-starter-actuator,spring-cloud-starter-hystrix-dashboard,启动引入@EnableHystrix,@EnableHystrixDashboard,@EnableCircuitBreaker,但是问题依然还有。

monitor无法注册到eureka上

docker run -d --name registry -p 127.0.0.1:8761:8761 registry
docker run -d --name monitor -p 127.0.0.1:8040:8040 -p 127.0.0.1:8041:8041 monitor
我启动两个容器分别跑registry和monitor,各自的ui界面都能打开,但是在eureka上发现,并没有monitor注册进来。

如果不使用docker分别java -jar xxx.jar 启动发现monitor的确是注册到了eureka上。为何?
@zhangxd1989

执行mvn package docker:build无法正常生成镜像

按照README.md的流程进行操作。执行命令‘ mvn clean package ’时报错。
Failed to execute goal com.spotify:docker-maven-plugin:1.0.0:build (default-cli) on project spring-boot-cloud: Exception caught: basedir /Users/jiangbiao/Documents/Spring-boot/spring-boot-cloud/target does not exist -> [Help 1]

使用Eclipse 运行项目不报错,登录报错!

ERROR o.j.m.system.controller.SysPermissionController:144 - nested exception is org.apache.ibatis.builder.BuilderException: Error evaluating expression 'ew.sqlSegment != null and ew.sqlSegment != '' and ew.nonEmptyOfWhere'. Cause: org.apache.ibatis.ognl.OgnlException: sqlSegment [org.apache.ibatis.reflection.ReflectionException: Error parsing property name 'lambda$2'. Didn't start with 'is', 'get' or 'set'.]
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.builder.BuilderException: Error evaluating expression 'ew.sqlSegment != null and ew.sqlSegment != '' and ew.nonEmptyOfWhere'. Cause: org.apache.ibatis.ognl.OgnlException: sqlSegment [org.apache.ibatis.reflection.ReflectionException: Error parsing property name 'lambda$2'. Didn't start with 'is', 'get' or 'set'.]
at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:77)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:446)
at com.sun.proxy.$Proxy134.selectList(Unknown Source)

应该是lombok注解的问题
Didn't start with 'is', 'get' or 'set'.

使用 myeclispe 运行项目正常

oauth2 相关问题

请问在auth-service模块中,clientID是client的client是为了用户登录用嘛?那是不是前端在请求access_token 时必须传所有参数是嘛?也就是说前端必须知道clientid,secret,grant_type,scope,username,password

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.