@fuchen 另外你的demo配置好像少spring.cloud
的配置
如下为服务器当前配置:
version: "3"
services:
zookeeper-0:
container_name: zookeeper-0
image: registry.saas.hand-china.com/tools/zookeeper:3.4.10
hostname: zookeeper-0
environment:
- ZK_REPLICAS=1
- ZK_HEAP_SIZE=2G
- ZK_TICK_TIME=2000
- ZK_INIT_LIMIT=10
- ZK_SYNC_LIMIT=5
- ZK_MAX_CLIENT_CNXNS=60
- ZK_SNAP_RETAIN_COUNT=3
- ZK_PURGE_INTERVAL=1
- ZK_LOG_LEVEL=INFO
- ZK_CLIENT_PORT=2181
- ZK_SERVER_PORT=2888
- ZK_ELECTION_PORT=3888
ports:
- "2181:2181"
- "2888:2888"
- "3888:3888"
command:
- sh
- -c
- zkGenConfig.sh && exec zkServer.sh start-foreground
volumes:
- "/docker-share/kafka/zk:/var/lib/zookeeper"
kafka-0:
container_name: kafka-0
image: registry.saas.hand-china.com/tools/kafka:1.0.0
hostname: 172.20.10.10
depends_on:
- zookeeper-0
links:
- zookeeper-0
ports:
- "9092:9092"
command:
- sh
- -c
- "/opt/kafka/bin/kafka-server-start.sh config/server.properties \
--override zookeeper.connect=zookeeper-0:2181 \
--override log.dirs=/opt/kafka/data/logs \
--override broker.id=0 "
volumes:
- "/docker-share/kafka/kafka:/opt/kafka/data"
mysql:
container_name: mysql
image: registry.cn-hangzhou.aliyuncs.com/choerodon-tools/mysql:5.7.17
hostname: mysql
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: root
volumes:
- /docker-share/mysql/mysql_data:/var/lib/mysql
- /docker-share/mysql/mysql_db.cnf:/etc/mysql/conf.d/mysql_db.cnf
expose:
- "3306"
eureka-server:
container_name: eureka-server
hostname: eureka-server
image: registry.cn-shanghai.aliyuncs.com/choerodon/eureka-server:0.5.0
ports:
- "8000:8000"
links:
- kafka-0
environment:
- spring.kafka.bootstrap-servers=kafka-0:9092
- eureka.client.serviceUrl.defaultZone=http://172.20.10.10:8000/eureka/
- eureka.client.register-with-eureka=false
- eureka.client.fetch-registry=false
- hystrix.stream.queue.enabled=false
- spring.cloud.bus.enabled=false
- spring.sleuth.stream.enabled=false
expose:
- "8000"
api-gateway:
container_name: api-gateway
image: registry.cn-shanghai.aliyuncs.com/choerodon/api-gateway:0.5.0
links:
- eureka-server
depends_on:
- eureka-server
ports:
- "8080:8080"
environment:
- zuul.routes.test.path=/test/** # 新增自定义服务时需要添加zuul.routes.服务名.path/serviceId这两个配置
- zuul.routes.test.serviceId=test-service
- eureka.client.serviceUrl.defaultZone=http://eureka-server:8000/eureka/
- hystrix.stream.queue.enabled=false
- spring.cloud.bus.enabled=false
- spring.sleuth.stream.enabled=false
expose:
- "8080"
gateway-helper:
container_name: gateway-helper
image: registry.cn-shanghai.aliyuncs.com/choerodon/gateway-helper:0.5.0
depends_on:
- eureka-server
- mysql
links:
- eureka-server
- mysql
ports:
- "9180:9180"
environment:
- zuul.routes.test.path=/test/** # 新增自定义服务时需要添加zuul.routes.服务名.path/serviceId这两个配置
- zuul.routes.test.serviceId=test-service
- eureka.client.serviceUrl.defaultZone=http://eureka-server:8000/eureka/
- spring.datasource.url=jdbc:mysql://mysql/iam_service?useUnicode=true&characterEncoding=utf-8&useSSL=false
- spring.datasource.username=root
- spring.datasource.password=root
- hystrix.stream.queue.enabled=false
- spring.cloud.bus.enabled=false
- spring.sleuth.stream.enabled=false
iam-service:
container_name: iam-service
image: registry.cn-shanghai.aliyuncs.com/choerodon/iam-service:0.5.0
depends_on:
- eureka-server
- mysql
- kafka-0
links:
- eureka-server
- mysql
- kafka-0
ports:
- "8030:8030"
environment:
- eureka.client.serviceUrl.defaultZone=http://eureka-server:8000/eureka/
- spring.kafka.bootstrap-servers=kafka-0:9092
- spring.datasource.url=jdbc:mysql://mysql/iam_service?useUnicode=true&characterEncoding=utf-8&useSSL=false
- spring.datasource.username=root
- spring.datasource.password=root
- hystrix.stream.queue.enabled=false
- spring.cloud.bus.enabled=false
- spring.sleuth.stream.enabled=false
manager-service:
container_name: manager-service
image: registry.cn-shanghai.aliyuncs.com/choerodon/manager-service:0.5.0
depends_on:
- eureka-server
- mysql
- kafka-0
links:
- eureka-server
- mysql
- kafka-0
ports:
- "8963:8963"
environment:
- spring.kafka.bootstrap-servers=kafka-0:9092
- eureka.client.serviceUrl.defaultZone=http://eureka-server:8000/eureka/
- spring.datasource.url=jdbc:mysql://mysql/manager_service?useUnicode=true&characterEncoding=utf-8&useSSL=false
- spring.datasource.username=root
- spring.datasource.password=root
- hystrix.stream.queue.enabled=false
- spring.cloud.bus.enabled=false
- spring.sleuth.stream.enabled=false
oauth-server:
container_name: oauth-server
image: registry.cn-shanghai.aliyuncs.com/choerodon/oauth-server:0.5.0
depends_on:
- eureka-server
- mysql
links:
- eureka-server
- mysql
ports:
- "8020:8020"
environment:
- eureka.client.serviceUrl.defaultZone=http://eureka-server:8000/eureka/
- spring.datasource.username=root
- spring.datasource.url=jdbc:mysql://mysql/iam_service?useUnicode=true&characterEncoding=utf-8&useSSL=false
- spring.datasource.password=root
- hystrix.stream.queue.enabled=false
- spring.cloud.bus.enabled=false
- spring.sleuth.stream.enabled=false
docker-compose方式可正常运行,无异常
按照你所述的在服务器端hosts 添加如下配置:
172.20.10.10 zookeeper-0
172.20.10.10 kafka-0
本地开发电脑运行demo案例,还是报之前的zk问题,本地配置为:
spring:
application:
name: test-service
datasource:
url: jdbc:mysql://172.20.10.10:3306/test?useUnicode=true&characterEncoding=utf-8&useSSL=false
username: root
password: root
server:
port: 9999
mybatis:
mapperLocations: classpath*:/mapper/*.xml
configuration:
mapUnderscoreToCamelCase: true
management:
port: 8081
security:
enabled: true
feign:
hystrix:
enabled: true
security:
basic:
enabled: false
ignored: /v2/api-docs
eureka:
instance:
preferIpAddress: true
leaseRenewalIntervalInSeconds: 10
leaseExpirationDurationInSeconds: 30
client:
serviceUrl:
defaultZone: ${EUREKA_DEFAULT_ZONE:http://172.20.10.10:8000/eureka/}
修改的是本地的hosts,非服务器的hosts, 本地配置参考:
spring:
sleuth:
...
kafka: #如果使用kafka需要配置
bootstrap-servers: kafka-0:9092
cloud:
bus:
enabled: false #不需要收集调用链设置false
stream:
kafka: # 当 bus.enabled不为false时需要设置
binder:
brokers: kafka-0:9092
zkNodes: zookeeper-0:2181
...
大佬,这个zk的问题解决了,那个swagger认证的问题麻烦给瞅瞅哈
这个问题哈,麻烦了
看截图,你的swagger地址是172.20.10.10,但是跳转是localhost?
如果是通过平台部署,确认下部署的配置中有没有CHOERODON_SWAGGER_OAUTH_URL
和CHOERODON_GATEWAY_DOMAIN
如果是本地启动,确认下配置中
choerodon.swagger.oauth-url: http://api.example.com/oauth/oauth/authorize
choerodon.gateway.domain: http://api.example.com
非本地,本地只是一个demo案例测试连接服务器
我的部署配置,就是上面发的那个docker-compose.yml文件内容