From bb3a22e99f945ec29dcc88bd64be3befd9c3d09e Mon Sep 17 00:00:00 2001 From: lsy <18332763730@163.com> Date: Sat, 27 Jan 2018 22:52:18 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ms/config-server/pom.xml | 2 +- .../src/main/resources/application.yml | 2 + .../src/main/resources/log4j2-dev.xml | 20 ++++ ms/gateway/pom.xml | 91 +++++++------------ .../fast/gateway/GatewayApplication.java | 10 +- .../gateway/config/DocumentationConfig.java | 3 +- ms/gateway/src/main/resources/bootstrap.yml | 5 +- ms/gateway/src/main/resources/log4j2-dev.xml | 20 ++++ ms/monitor-center/pom.xml | 5 + .../src/main/resources/application.yml | 18 ---- .../src/main/resources/log4j2-dev.xml | 20 ++++ ms/oauth/pom.xml | 16 +++- ms/oauth/src/main/resources/bootstrap.yml | 7 +- ms/oauth/src/main/resources/log4j2-dev.xml | 20 ++++ ms/pom.xml | 9 ++ .../src/main/resources/log4j2-dev.xml | 20 ++++ .../src/main/resources/bootstrap.yml | 2 +- .../src/main/resources/log4j2-dev.xml | 20 ++++ ms/ucenter/pom.xml | 77 ++++++---------- .../fast/ucenter/UcenterApplication.java | 9 +- ms/ucenter/src/main/resources/bootstrap.yml | 3 + ms/ucenter/src/main/resources/log4j2-dev.xml | 20 ++++ ms/upms/src/main/resources/bootstrap.yml | 18 +--- .../resources/{log4j2.xml => log4j2-dev.xml} | 0 pom.xml | 28 +----- 25 files changed, 263 insertions(+), 182 deletions(-) create mode 100644 ms/config-server/src/main/resources/log4j2-dev.xml create mode 100644 ms/gateway/src/main/resources/log4j2-dev.xml delete mode 100644 ms/monitor-center/src/main/resources/application.yml create mode 100644 ms/monitor-center/src/main/resources/log4j2-dev.xml create mode 100644 ms/oauth/src/main/resources/log4j2-dev.xml create mode 100644 ms/register-center1/src/main/resources/log4j2-dev.xml create mode 100644 ms/register-center2/src/main/resources/log4j2-dev.xml create mode 100644 ms/ucenter/src/main/resources/log4j2-dev.xml rename ms/upms/src/main/resources/{log4j2.xml => log4j2-dev.xml} (100%) diff --git a/ms/config-server/pom.xml b/ms/config-server/pom.xml index af6a65a..6324f2b 100644 --- a/ms/config-server/pom.xml +++ b/ms/config-server/pom.xml @@ -32,7 +32,7 @@ org.springframework.boot spring-boot-starter-actuator - + org.springframework.cloud spring-cloud-starter-eureka diff --git a/ms/config-server/src/main/resources/application.yml b/ms/config-server/src/main/resources/application.yml index 29acfe3..7fbb471 100644 --- a/ms/config-server/src/main/resources/application.yml +++ b/ms/config-server/src/main/resources/application.yml @@ -19,4 +19,6 @@ security: user: name: config password: server +logging: + config: classpath:log4j2-dev.xml diff --git a/ms/config-server/src/main/resources/log4j2-dev.xml b/ms/config-server/src/main/resources/log4j2-dev.xml new file mode 100644 index 0000000..ef00409 --- /dev/null +++ b/ms/config-server/src/main/resources/log4j2-dev.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ms/gateway/pom.xml b/ms/gateway/pom.xml index 2c99528..565174d 100644 --- a/ms/gateway/pom.xml +++ b/ms/gateway/pom.xml @@ -26,11 +26,17 @@ org.springframework.cloud spring-cloud-starter-config - + + + org.springframework.cloud + spring-cloud-starter-zuul + + org.springframework.cloud spring-cloud-starter-eureka + org.springframework.cloud spring-cloud-starter-ribbon @@ -39,71 +45,36 @@ org.springframework.cloud spring-cloud-starter-feign + + + org.springframework.cloud + spring-cloud-starter-hystrix + + + + org.springframework.cloud + spring-cloud-starter-hystrix-dashboard + + + + org.springframework.cloud + spring-cloud-starter-bus-amqp + + + org.springframework.retry + spring-retry + + + + org.springframework.cloud + spring-cloud-starter-zipkin + org.springframework.boot spring-boot-starter-test test - - - org.springframework.cloud - spring-cloud-starter-zuul - - - - - org.springframework.cloud - spring-cloud-starter-hystrix - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - io.springfox - springfox-swagger2 - - - io.springfox - springfox-swagger-ui - diff --git a/ms/gateway/src/main/java/com/micro/fast/gateway/GatewayApplication.java b/ms/gateway/src/main/java/com/micro/fast/gateway/GatewayApplication.java index b610b4b..9538ab1 100644 --- a/ms/gateway/src/main/java/com/micro/fast/gateway/GatewayApplication.java +++ b/ms/gateway/src/main/java/com/micro/fast/gateway/GatewayApplication.java @@ -3,6 +3,8 @@ package com.micro.fast.gateway; import org.springframework.boot.SpringApplication; import org.springframework.cloud.client.SpringCloudApplication; import org.springframework.cloud.netflix.feign.EnableFeignClients; +import org.springframework.cloud.netflix.hystrix.EnableHystrix; +import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard; import org.springframework.cloud.netflix.zuul.EnableZuulProxy; import springfox.documentation.swagger2.annotations.EnableSwagger2; @@ -15,9 +17,13 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2; @SpringCloudApplication //开启路径代理 @EnableZuulProxy -//开启feign对服务的调用 -@EnableFeignClients @EnableSwagger2 +//服务调用 +@EnableFeignClients +//熔断 +@EnableHystrix +//对用熔断情况进行统计并展示 +@EnableHystrixDashboard public class GatewayApplication { public static void main(String[] args) { diff --git a/ms/gateway/src/main/java/com/micro/fast/gateway/config/DocumentationConfig.java b/ms/gateway/src/main/java/com/micro/fast/gateway/config/DocumentationConfig.java index 3132e1f..af50283 100644 --- a/ms/gateway/src/main/java/com/micro/fast/gateway/config/DocumentationConfig.java +++ b/ms/gateway/src/main/java/com/micro/fast/gateway/config/DocumentationConfig.java @@ -18,8 +18,9 @@ public class DocumentationConfig implements SwaggerResourcesProvider { @Override public List get() { List resources = new ArrayList<>(); - resources.add(swaggerResource("用户中心", "/ucenter/api/api-doc", "2.0")); + resources.add(swaggerResource("服务网关", "/api/api-doc", "2.0")); resources.add(swaggerResource("后台权限控制系统", "/upms/api/api-doc", "2.0")); + resources.add(swaggerResource("用户中心", "/ucenter/api/api-doc", "2.0")); return resources; } diff --git a/ms/gateway/src/main/resources/bootstrap.yml b/ms/gateway/src/main/resources/bootstrap.yml index e336e87..b972573 100644 --- a/ms/gateway/src/main/resources/bootstrap.yml +++ b/ms/gateway/src/main/resources/bootstrap.yml @@ -15,7 +15,10 @@ eureka: serviceUrl: defaultZone: http://micro:fast@www.register1.com:10002/eureka/,http://micro:fast@www.register2.com:10004/eureka/ #配置所有的注册中心 instance: - hostname: fthipw.natappfree.cc + hostname: fthipw.natappfree.cc +# 配置熔断监控的集群名称 + metadata-map: + cluster: ms-gateway diff --git a/ms/gateway/src/main/resources/log4j2-dev.xml b/ms/gateway/src/main/resources/log4j2-dev.xml new file mode 100644 index 0000000..ef141a5 --- /dev/null +++ b/ms/gateway/src/main/resources/log4j2-dev.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ms/monitor-center/pom.xml b/ms/monitor-center/pom.xml index 6d24778..2ad019d 100644 --- a/ms/monitor-center/pom.xml +++ b/ms/monitor-center/pom.xml @@ -42,6 +42,11 @@ org.springframework.boot spring-boot-starter-actuator + + + org.springframework.cloud + spring-cloud-starter-hystrix + org.springframework.cloud diff --git a/ms/monitor-center/src/main/resources/application.yml b/ms/monitor-center/src/main/resources/application.yml deleted file mode 100644 index c099e3b..0000000 --- a/ms/monitor-center/src/main/resources/application.yml +++ /dev/null @@ -1,18 +0,0 @@ -spring: - application: - name: monitor-center -server: - port: 10018 -security: - basic: - enabled: false -turbine: - aggregator: -# ָ¶¨¾ۺÏÄÄЩ¼¯Ⱥ£¬¶à¸öʹÓÃ","·ָĬÈÏΪdefault¡£¿ÉʹÓÃhttp://.../turbine.stream?cluster={clusterConfig֮һ}·ÃÎÊ - cluster-config: default -# ÅäÖÃEurekaÖеÄserviceIdÁбí£¬±íÃ÷¼à¿ØÄÄЩ·þÎñ - app-config: upms,oauth - cluster-name-expression: new String("default") -# 1. clusterNameExpressionָ¶¨¼¯ȺÃû³ƣ¬ĬÈϱí´ïʽappName£»´Ëʱ£ºturbine.aggregator.clusterConfigÐèҪÅäÖÃÏëҪ¼à¿صÄӦÓÃÃû³Æ -# 2. µ±clusterNameExpression: defaultʱ£¬turbine.aggregator.clusterConfig¿ÉÒԲ»д£¬ÒòΪĬÈϾÍÊÇdefault -# 3. µ±clusterNameExpression: metadata['cluster']ʱ£¬¼ÙÉèÏëҪ¼à¿صÄӦÓÃÅäÖÃÁËeureka.instance.metadata-map.cluster: ABC£¬ÔòÐèҪÅäÖã¬ͬʱturbine.aggregator.clusterConfig: ABC \ No newline at end of file diff --git a/ms/monitor-center/src/main/resources/log4j2-dev.xml b/ms/monitor-center/src/main/resources/log4j2-dev.xml new file mode 100644 index 0000000..e355a3f --- /dev/null +++ b/ms/monitor-center/src/main/resources/log4j2-dev.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ms/oauth/pom.xml b/ms/oauth/pom.xml index ccf518b..9b5817d 100644 --- a/ms/oauth/pom.xml +++ b/ms/oauth/pom.xml @@ -37,7 +37,7 @@ org.springframework.cloud spring-cloud-starter-eureka - + org.springframework.cloud spring-cloud-starter-ribbon @@ -56,6 +56,20 @@ org.springframework.cloud spring-cloud-starter-hystrix-dashboard + + + org.springframework.cloud + spring-cloud-starter-bus-amqp + + + org.springframework.retry + spring-retry + + + + org.springframework.cloud + spring-cloud-starter-zipkin + org.springframework.boot diff --git a/ms/oauth/src/main/resources/bootstrap.yml b/ms/oauth/src/main/resources/bootstrap.yml index 6fd4d18..5940b57 100644 --- a/ms/oauth/src/main/resources/bootstrap.yml +++ b/ms/oauth/src/main/resources/bootstrap.yml @@ -16,7 +16,6 @@ eureka: defaultZone: http://micro:fast@www.register1.com:10002/eureka/,http://micro:fast@www.register2.com:10004/eureka/ #配置所有的注册中心 instance: hostname: www.oauth.com -# 允许feign负载均衡降级 -feign: - hystrix: - enabled: true +# 配置熔断监控的集群名称 + metadata-map: + cluster: ms-oauth diff --git a/ms/oauth/src/main/resources/log4j2-dev.xml b/ms/oauth/src/main/resources/log4j2-dev.xml new file mode 100644 index 0000000..1e6a1b6 --- /dev/null +++ b/ms/oauth/src/main/resources/log4j2-dev.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ms/pom.xml b/ms/pom.xml index ce90f3a..d59742f 100644 --- a/ms/pom.xml +++ b/ms/pom.xml @@ -46,6 +46,15 @@ org.apache.logging.log4j log4j-flume-ng + + + io.springfox + springfox-swagger2 + + + io.springfox + springfox-swagger-ui + diff --git a/ms/register-center1/src/main/resources/log4j2-dev.xml b/ms/register-center1/src/main/resources/log4j2-dev.xml new file mode 100644 index 0000000..11a3493 --- /dev/null +++ b/ms/register-center1/src/main/resources/log4j2-dev.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ms/register-center2/src/main/resources/bootstrap.yml b/ms/register-center2/src/main/resources/bootstrap.yml index da23d1a..c62738a 100644 --- a/ms/register-center2/src/main/resources/bootstrap.yml +++ b/ms/register-center2/src/main/resources/bootstrap.yml @@ -10,4 +10,4 @@ eureka: service-url: defaultZone: http://micro:fast@www.register1.com:10002/eureka #和其他注册中心连接 instance: - hostname: www.register2.com \ No newline at end of file + hostname: www.register2.com diff --git a/ms/register-center2/src/main/resources/log4j2-dev.xml b/ms/register-center2/src/main/resources/log4j2-dev.xml new file mode 100644 index 0000000..81f0da6 --- /dev/null +++ b/ms/register-center2/src/main/resources/log4j2-dev.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ms/ucenter/pom.xml b/ms/ucenter/pom.xml index 90a66ab..07fa55f 100644 --- a/ms/ucenter/pom.xml +++ b/ms/ucenter/pom.xml @@ -42,11 +42,12 @@ org.springframework.cloud spring-cloud-starter-config - + org.springframework.cloud spring-cloud-starter-eureka + org.springframework.cloud spring-cloud-starter-ribbon @@ -55,62 +56,36 @@ org.springframework.cloud spring-cloud-starter-feign + + + org.springframework.cloud + spring-cloud-starter-hystrix + + + + org.springframework.cloud + spring-cloud-starter-hystrix-dashboard + + + + org.springframework.cloud + spring-cloud-starter-bus-amqp + + + org.springframework.retry + spring-retry + + + + org.springframework.cloud + spring-cloud-starter-zipkin + org.springframework.boot spring-boot-starter-test test - - - - - - - - - org.springframework.cloud - spring-cloud-starter-hystrix - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/ms/ucenter/src/main/java/com/micro/fast/ucenter/UcenterApplication.java b/ms/ucenter/src/main/java/com/micro/fast/ucenter/UcenterApplication.java index 2885a9a..e7afb4c 100644 --- a/ms/ucenter/src/main/java/com/micro/fast/ucenter/UcenterApplication.java +++ b/ms/ucenter/src/main/java/com/micro/fast/ucenter/UcenterApplication.java @@ -6,11 +6,18 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; import org.springframework.cloud.client.SpringCloudApplication; import org.springframework.cloud.netflix.feign.EnableFeignClients; +import org.springframework.cloud.netflix.hystrix.EnableHystrix; +import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard; @SpringCloudApplication -@EnableFeignClients @MapperScan(basePackages = {"com.micro.fast.ucenter.dao"}) @EnableAutoConfiguration(exclude = DataSourceAutoConfiguration.class) +//服务调用 +@EnableFeignClients +//熔断 +@EnableHystrix +//对用熔断情况进行统计并展示 +@EnableHystrixDashboard public class UcenterApplication { public static void main(String[] args) { diff --git a/ms/ucenter/src/main/resources/bootstrap.yml b/ms/ucenter/src/main/resources/bootstrap.yml index bea055e..05aa12f 100644 --- a/ms/ucenter/src/main/resources/bootstrap.yml +++ b/ms/ucenter/src/main/resources/bootstrap.yml @@ -16,3 +16,6 @@ eureka: defaultZone: http://micro:fast@www.register1.com:10002/eureka/,http://micro:fast@www.register2.com:10004/eureka/ #配置所有的注册中心 instance: hostname: www.ucenter.com +# 配置熔断监控的集群名称 + metadata-map: + cluster: ms-ucenter \ No newline at end of file diff --git a/ms/ucenter/src/main/resources/log4j2-dev.xml b/ms/ucenter/src/main/resources/log4j2-dev.xml new file mode 100644 index 0000000..282e617 --- /dev/null +++ b/ms/ucenter/src/main/resources/log4j2-dev.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ms/upms/src/main/resources/bootstrap.yml b/ms/upms/src/main/resources/bootstrap.yml index c884e3f..d679d77 100644 --- a/ms/upms/src/main/resources/bootstrap.yml +++ b/ms/upms/src/main/resources/bootstrap.yml @@ -1,7 +1,5 @@ # 从配置中心加载文件 spring: - session: - store-type: none cloud: config: profile: dev @@ -12,28 +10,16 @@ spring: enabled: true username: config password: server -# 允许记录消息的所有发送和接收事件 - bus: - trace: - enabled: true -# 消息总线 - rabbitmq: - host: localhost - port: 5672 -# 向服务监控调用中心暴露端口 - zipkin: - base-url: http://www.monitorcenter.com:10018 eureka: client: serviceUrl: defaultZone: http://micro:fast@www.register1.com:10002/eureka/,http://micro:fast@www.register2.com:10004/eureka/ #配置所有的注册中心 instance: hostname: www.upms.com +# 配置熔断监控的集群名称 metadata-map: cluster: ms-upms -# 日志配置 -logging: - config: classpath:log4j2.xml + diff --git a/ms/upms/src/main/resources/log4j2.xml b/ms/upms/src/main/resources/log4j2-dev.xml similarity index 100% rename from ms/upms/src/main/resources/log4j2.xml rename to ms/upms/src/main/resources/log4j2-dev.xml diff --git a/pom.xml b/pom.xml index cc6e82b..61e458b 100644 --- a/pom.xml +++ b/pom.xml @@ -89,26 +89,10 @@ - ubuntu-dev + deploy false - - - - org.springframework.boot - spring-boot-devtools - ${springboot.version} - true - - - - - - ubuntu-deploy - - true - @@ -121,16 +105,10 @@ - win-dev + dev - false + true - - - 1.8 - 1.8 - 1.8 -