-
本地拉取相关镜像通过docker-compose构建启动
如上图中api-gateway组件容器端口是否必须得8080?? -
本地demo案例
此处应用端口是否也必须为8080?? -
如上若本地运行,会存在端口冲突,demo案例虽然可以启动,但是服务无法正常注册,修改端口后导致manager-service中swagger方式访问无法正确得到资源数据,如图:
此处的应该是api-gateway的ip和端口信息,按正常思路我这应该是可以拿到请求数据的,但是这里无法获取到数据,我案例应用端口已修改为9999(该请求我通过其他方式可以获取到数据,比如postman)
修改下本地demo案例的端口就可以了。swagger配置的gateway的domain默认为127.0.0.1:8080,所以直接改了gateway端口会访问不通,需要修改manager的choerodon.gateway.domain的环境变量,比如127.0.0.1:8090
demo案例application.yml:
spring:
application:
name: test-service
datasource:
url: jdbc:mysql://localhost: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: 1
leaseExpirationDurationInSeconds: 3
client:
serviceUrl:
defaultZone: ${EUREKA_DEFAULT_ZONE:http://localhost:8000/eureka/}
我这是根据这个配置启动的,demo案例资源服务在swagger还是无法调用成功,这个有啥问题吗?还是说我需要更改docker-compose.yml这个配置?,当前如下:
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:
- "/home/guoqingdeng/Desktop/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: kafka-0
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:
- "/home/guoqingdeng/Desktop/docker-share/kafka/kafka:/opt/kafka/data"
redis:
container_name: redis
image: hub.c.163.com/library/redis:latest
ports:
- "6379:6379"
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:
- /home/guoqingdeng/Desktop/docker-share/mysql/mysql_data:/var/lib/mysql
- /home/guoqingdeng/Desktop/docker-share/mysql/mysql_db.cnf:/etc/mysql/conf.d/mysql_db.cnf
expose:
- "3306"
phpadmin:
container_name: phpadmin
image: registry.saas.hand-china.com/tools/phpmyadmin
ports:
- "8888:80" # 80端口方便浏览器直接访问
environment:
PMA_ARBITRARY: 1 # 用于开启phpadmin关于可否输入host的设置
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://127.0.0.1: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:
- 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:
- 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
需要修改manager的choerodon.gateway.domain的环境变量??这个怎么改??
manager加个environment啊
老哥,你能否看下我上面的配置,你那边验证好再发我哈,这个swagger还是无法调通demo的服务资源
choerodon.gateway.domain设置的是api-gateway的地址,你要是改了api-gateway的端口需要设置这个;你要是改了demo的端口不需要配置这个
按照你所说的,我这边只改demo的server.port地址就行了吧??但是我改了之后swagger是调不通的
api-gateway和gateway-helper都需要配下你的demo服务路由,可以通过环境变量加上。可以看下api-gateway和gateway-helper的日志。本地docker-compose配置不是很方便,而且往往内存不够,我们本地开发直接跑的代码