eureka server服务中心 是把所有的eureka client各个服务 都注册到服务中心上
例如服务 A B C中配置如下:
application.yml文件配置:
1 server: 2 port: 10003 3 spring: 4 mvc: 5 favicon: 6 enabled: false 7 eureka: 8 client: 9 service: 10 serviceUrl: 11 defaultZone: http://127.0.0.1:9998/eureka/ 12 //这里就是服务中心的配置文件 13 pagehelper: 14 helperDialect : mysql 15 reasonable : true 16 supportMethodsArguments : true 17 params : count=countSql 18 tg: 19 sercurity: 20 filter: 21 includes: /energy/* 22 excludes: /energy/metering/*,/energy/enterprise/*,/energy/process/*,/energy/processunit/*,/energy/collectItemConfig/*, 23 /energy/sys/*,/energy/park/*,/energy/parkEnterprise/*,/energy/enengyRate/*,/energy/enengySaving/*,/energy/enengyStandard/*,/energy/analysis/* 24 db: 25 sharding: 26 path: config/sharding.yml 27 default: em2_sysbase 28 customname: em2_sysbase 29 em2_sysbase: 30 driverClassName: com.mysql.jdbc.Driver 31 url: jdbc:mysql://192.168.1.64:3306/em2_sysbase?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true 32 username: root 33 password: 123456 34 filters: stat 35 maxActive: 30 36 initialSize: 5 37 minIdle: 10 38 maxWait: 60000 39 validationQuery: SELECT 1 40 testWhileIdle : true 41 poolPreparedStatements : true 42 maxOpenPreparedStatements : 100 43
bootstrap.yml文件配置:
1 spring: 2 application: 3 name: em2-energy-service 4 redis: 5 host: 127.0.0.1 6 port:3369
服务中心yml配置文件
1 server: 2 port: 9998 //这个端口以后就是登陆的时候输入进去的 3 4 eureka: 5 instance: 6 hostname: 127.0.0.1 7 client: 8 registerWithEureka: false //是否注册到服务中心默认true 9 fetchRegistry: false 10 serviceUrl: 11 defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
zuul是集路由 负载均衡 熔断器等一体的服务
它的yml配置如下:
1 server: 2 port: 9999 //登陆用的 3 zuul: 4 routes: 5 auth: 6 customSensitiveHeadsers: true 7 sensitiveHeaders: 8 stripPrefix: false 9 path: /auth/** 10 serviceId: em2-auth-service 11 //path就是url的请求到这里会被拦截通过serviceId进入到当前的服务,serviceId这个就是各个服务的application name,stripPrefix: false这个是对/api做的过滤 12 static: 13 customSensitiveHeadsers: true 14 sensitiveHeaders: 15 path: /static/** 16 stripPrefix: true 17 serviceId: em2-ui 18 oss: 19 path: /oss/** 20 url: http://192.168.1.64:10010/ 21 stripPrefix: false 22 max: 23 host: 24 connections: 500 25 host: 26 socket-timeout-millis: 120000 27 connect-timeout-millis: 120000 28 eureka: 29 client: 30 service: 31 serviceUrl: 32 defaultZone: http://127.0.0.1:9998/eureka/ 33 34 ##timeout config 35 hystrix: 36 command: 37 default: 38 execution: 39 timeout: 40 enabled: false 41 isolation: 42 thread: 43 timeoutInMilliseconds: 120000 44 ribbon: 45 ReadTimeout: 120000 46 ConnectTimeout: 120000 47 MaxAutoRetries: 0 48 MaxAutoRetriesNextServer: 1 49 eureka: 50 enabled: true