后端开发,构建本地环境,相关问题点

参考文档开发手册后端开发手册

  • 1.本地运行环境系统Linux(Ubuntu)

  • 2.基础组件镜像获取,采用docker-compose方式运行启动,docker-compose.yml如下:

      version: "3"
      services:
        zookeeper-0:
          container_name: zookeeper-0
          image: registry.cn-hangzhou.aliyuncs.com/choerodon-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.cn-hangzhou.aliyuncs.com/choerodon-tools/kafka:1.0.0
          hostname: 127.0.0.1
          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
          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
        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
          image: registry.cn-shanghai.aliyuncs.com/choerodon/eureka-server:0.5.0
          hostname: eureka-server
          ports:
          - "8000:8000"
          depends_on:
          - zookeeper-0
          - kafka-0
          links:
          - zookeeper-0
          - kafka-0
        manager-service:
          container_name: manager-service
          image: registry.cn-shanghai.aliyuncs.com/choerodon/manager-service:0.5.0
          depends_on:
          - zookeeper-0
          - kafka-0
          - eureka-server
          - mysql
          links:
          - zookeeper-0
          - kafka-0
          - eureka-server
          - mysql
          ports:
          - "8963:8963"
          environment:
          - eureka.client.serviceUrl.defaultZone=http://eureka-server:8000/eureka/
          - spring.cloud.stream.kafka.binder.zkNodes=zookeeper-0:2181
          - spring.datasource.url=jdbc:mysql://mysql/iam_service?useUnicode=true&characterEncoding=utf-8&useSSL=false
          - spring.datasource.username=root
          - spring.datasource.password=root
        api-gateway:
          container_name: api-gateway
          image: registry.cn-shanghai.aliyuncs.com/choerodon/api-gateway:0.5.0
          depends_on:
          - zookeeper-0
          - kafka-0
          - eureka-server
          - mysql
          links:
          - zookeeper-0
          - kafka-0
          - eureka-server
          - mysql
          ports:
          - "8080:8080"
          environment:
          - zuul.addHostHeader=true
          - eureka.client.serviceUrl.defaultZone=http://eureka-server:8000/eureka/
          - spring.cloud.stream.kafka.binder.zkNodes=zookeeper-0:2181
          - spring.datasource.url=jdbc:mysql://mysql/iam_service?useUnicode=true&characterEncoding=utf-8&useSSL=false
          - spring.datasource.username=root
          - spring.datasource.password=root
        oauth-server:
          container_name: oauth-server
          image: registry.cn-shanghai.aliyuncs.com/choerodon/oauth-server:0.5.0
          depends_on:
          - zookeeper-0
          - kafka-0
          - eureka-server
          - mysql
          links:
          - zookeeper-0
          - kafka-0
          - eureka-server
          - mysql
          ports:
          - "8020:8020"
          environment:
          - eureka.client.serviceUrl.defaultZone=http://eureka-server:8000/eureka/
          - spring.cloud.stream.kafka.binder.zkNodes=zookeeper-0:2181
          - spring.datasource.url=jdbc:mysql://mysql/iam_service?useUnicode=true&characterEncoding=utf-8&useSSL=false
          - spring.datasource.username=root
          - spring.datasource.password=root
        gateway-helper:
          container_name: gateway-helper
          image: registry.cn-shanghai.aliyuncs.com/choerodon/gateway-helper:0.5.0
          depends_on:
          - zookeeper-0
          - kafka-0
          - eureka-server
          - mysql
          links:
          - zookeeper-0
          - kafka-0
          - eureka-server
          - mysql
          ports:
          - "9180:9180"
          environment:
          - eureka.client.serviceUrl.defaultZone=http://eureka-server:8000/eureka/
          - spring.cloud.stream.kafka.binder.zkNodes=zookeeper-0:2181
          - spring.datasource.url=jdbc:mysql://mysql/iam_service?useUnicode=true&characterEncoding=utf-8&useSSL=false
          - spring.datasource.username=root
          - spring.datasource.password=root
    

    问题点如下:

  • 3.根据文档demo创建本地案例运行

    • 案例bootstrap.yml如下:

      spring:
        eureka:
          instance:
            preferIpAddress: true
            leaseRenewalIntervalInSeconds: 1
            leaseExpirationDurationInSeconds: 3
          client:
            serviceUrl:
              defaultZone: ${EUREKA_DEFAULT_ZONE:http://localhost:8000/eureka/}
        application:
          name: choerodon-todo-service
        datasource:
          url: jdbc:mysql://localhost/choerodon_demo_service_todo?useUnicode=true&characterEncoding=utf-8&useSSL=false
          username: choerodon
          password: 123456
      server:
        port: 8080
      mybatis:
        mapperLocations: classpath*:/mapper/*.xml
        configuration:
          mapUnderscoreToCamelCase: true
      management:
        port: 8081
        security:
          enabled: false
      feign:
        hystrix:
          enabled: true
      security:
        basic:
          enabled: false
        ignored: /v2/api-docs
      
    • TodoServiceApplication项目启动类:
      问题点:
      1. 未添加@EnableEurekaClient注解,项目启动不报错,但服务未能注册到注册中心
      2. 添加@EnableEurekaClient注解注解后,项目无法正常启动,错误日志如下:

      com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server
      	at com.netflix.discovery.shared.transport.decorator.RetryableEurekaHttpClient.execute(RetryableEurekaHttpClient.java:111) ~[eureka-client-1.6.2.jar:1.6.2]
      	at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.register(EurekaHttpClientDecorator.java:56) ~[eureka-client-1.6.2.jar:1.6.2]
      	at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$1.execute(EurekaHttpClientDecorator.java:59) ~[eureka-client-1.6.2.jar:1.6.2]
      	at com.netflix.discovery.shared.transport.decorator.SessionedEurekaHttpClient.execute(SessionedEurekaHttpClient.java:77) ~[eureka-client-1.6.2.jar:1.6.2]
      	at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.register(EurekaHttpClientDecorator.java:56) ~[eureka-client-1.6.2.jar:1.6.2]
      	at com.netflix.discovery.DiscoveryClient.register(DiscoveryClient.java:798) ~[eureka-client-1.6.2.jar:1.6.2]
      	at com.netflix.discovery.InstanceInfoReplicator.run(InstanceInfoReplicator.java:104) [eureka-client-1.6.2.jar:1.6.2]
      	at com.netflix.discovery.InstanceInfoReplicator$1.run(InstanceInfoReplicator.java:88) [eureka-client-1.6.2.jar:1.6.2]
      	at java.util.concurrent.Executors$RunnableAdapter.call$$$capture(Executors.java:511) [na:1.8.0_151]
      	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java) [na:1.8.0_151]
      	at java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:266) [na:1.8.0_151]
      	at java.util.concurrent.FutureTask.run(FutureTask.java) [na:1.8.0_151]
      	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) [na:1.8.0_151]
      	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) [na:1.8.0_151]
      	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_151]
      	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_151]
      	at java.lang.Thread.run(Thread.java:748) [na:1.8.0_151]
      
      2018-06-06 11:50:54.408  WARN [choerodon-todo-service,,,] 7357 --- [nfoReplicator-0] c.n.discovery.InstanceInfoReplicator     : There was a problem with the instance info replicator
      
      com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server
      	at com.netflix.discovery.shared.transport.decorator.RetryableEurekaHttpClient.execute(RetryableEurekaHttpClient.java:111) ~[eureka-client-1.6.2.jar:1.6.2]
      	at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.register(EurekaHttpClientDecorator.java:56) ~[eureka-client-1.6.2.jar:1.6.2]
      	at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$1.execute(EurekaHttpClientDecorator.java:59) ~[eureka-client-1.6.2.jar:1.6.2]
      	at com.netflix.discovery.shared.transport.decorator.SessionedEurekaHttpClient.execute(SessionedEurekaHttpClient.java:77) ~[eureka-client-1.6.2.jar:1.6.2]
      	at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.register(EurekaHttpClientDecorator.java:56) ~[eureka-client-1.6.2.jar:1.6.2]
      	at com.netflix.discovery.DiscoveryClient.register(DiscoveryClient.java:798) ~[eureka-client-1.6.2.jar:1.6.2]
      	at com.netflix.discovery.InstanceInfoReplicator.run(InstanceInfoReplicator.java:104) ~[eureka-client-1.6.2.jar:1.6.2]
      	at com.netflix.discovery.InstanceInfoReplicator$1.run(InstanceInfoReplicator.java:88) [eureka-client-1.6.2.jar:1.6.2]
      	at java.util.concurrent.Executors$RunnableAdapter.call$$$capture(Executors.java:511) [na:1.8.0_151]
      	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java) [na:1.8.0_151]
      	at java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:266) [na:1.8.0_151]
      	at java.util.concurrent.FutureTask.run(FutureTask.java) [na:1.8.0_151]
      	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) [na:1.8.0_151]
      	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) [na:1.8.0_151]
      	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_151]
      	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_151]
      	at java.lang.Thread.run(Thread.java:748) [na:1.8.0_151]
      
      2018-06-06 11:50:54.414  INFO [choerodon-todo-service,,,] 7357 --- [      Thread-31] com.netflix.discovery.DiscoveryClient    : Shutting down DiscoveryClient ...
      2018-06-06 11:50:54.417  INFO [choerodon-todo-service,,,] 7357 --- [      Thread-31] com.netflix.discovery.DiscoveryClient    : Unregistering ...
      2018-06-06 11:50:54.431 ERROR [choerodon-todo-service,,,] 7357 --- [      Thread-31] c.n.d.s.t.d.RedirectingEurekaHttpClient  : Request execution error
      
      com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: 拒绝连接 (Connection refused)
      	at com.sun.jersey.client.apache4.ApacheHttpClient4Handler.handle(ApacheHttpClient4Handler.java:187) ~[jersey-apache-client4-1.19.1.jar:1.19.1]
      	at com.sun.jersey.api.client.filter.GZIPContentEncodingFilter.handle(GZIPContentEncodingFilter.java:123) ~[jersey-client-1.19.1.jar:1.19.1]
      	at com.netflix.discovery.EurekaIdentityHeaderFilter.handle(EurekaIdentityHeaderFilter.java:27) ~[eureka-client-1.6.2.jar:1.6.2]
      	at com.sun.jersey.api.client.Client.handle(Client.java:652) ~[jersey-client-1.19.1.jar:1.19.1]
      	at com.sun.jersey.api.client.WebResource.handle(WebResource.java:682) ~[jersey-client-1.19.1.jar:1.19.1]
      	at com.sun.jersey.api.client.WebResource.access$200(WebResource.java:74) ~[jersey-client-1.19.1.jar:1.19.1]
      	at com.sun.jersey.api.client.WebResource$Builder.delete(WebResource.java:591) ~[jersey-client-1.19.1.jar:1.19.1]
      	at com.netflix.discovery.shared.transport.jersey.AbstractJerseyEurekaHttpClient.cancel(AbstractJerseyEurekaHttpClient.java:76) ~[eureka-client-1.6.2.jar:1.6.2]
      	at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$2.execute(EurekaHttpClientDecorator.java:74) [eureka-client-1.6.2.jar:1.6.2]
      	at com.netflix.discovery.shared.transport.decorator.MetricsCollectingEurekaHttpClient.execute(MetricsCollectingEurekaHttpClient.java:73) ~[eureka-client-1.6.2.jar:1.6.2]
      	at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.cancel(EurekaHttpClientDecorator.java:71) [eureka-client-1.6.2.jar:1.6.2]
      	at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$2.execute(EurekaHttpClientDecorator.java:74) [eureka-client-1.6.2.jar:1.6.2]
      	at com.netflix.discovery.shared.transport.decorator.RedirectingEurekaHttpClient.executeOnNewServer(RedirectingEurekaHttpClient.java:118) ~[eureka-client-1.6.2.jar:1.6.2]
      	at com.netflix.discovery.shared.transport.decorator.RedirectingEurekaHttpClient.execute(RedirectingEurekaHttpClient.java:79) ~[eureka-client-1.6.2.jar:1.6.2]
      	at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.cancel(EurekaHttpClientDecorator.java:71) [eureka-client-1.6.2.jar:1.6.2]
      	at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$2.execute(EurekaHttpClientDecorator.java:74) [eureka-client-1.6.2.jar:1.6.2]
      	at com.netflix.discovery.shared.transport.decorator.RetryableEurekaHttpClient.execute(RetryableEurekaHttpClient.java:119) [eureka-client-1.6.2.jar:1.6.2]
      	at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.cancel(EurekaHttpClientDecorator.java:71) [eureka-client-1.6.2.jar:1.6.2]
      	at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$2.execute(EurekaHttpClientDecorator.java:74) [eureka-client-1.6.2.jar:1.6.2]
      	at com.netflix.discovery.shared.transport.decorator.SessionedEurekaHttpClient.execute(SessionedEurekaHttpClient.java:77) [eureka-client-1.6.2.jar:1.6.2]
      	at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.cancel(EurekaHttpClientDecorator.java:71) [eureka-client-1.6.2.jar:1.6.2]
      	at com.netflix.discovery.DiscoveryClient.unregister(DiscoveryClient.java:885) [eureka-client-1.6.2.jar:1.6.2]
      	at com.netflix.discovery.DiscoveryClient.shutdown(DiscoveryClient.java:863) [eureka-client-1.6.2.jar:1.6.2]
      	at com.netflix.discovery.DiscoveryClient$$FastClassBySpringCGLIB$$a84c8cb4.invoke(<generated>) [eureka-client-1.6.2.jar:1.6.2]
      	at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204) [spring-core-4.3.8.RELEASE.jar:4.3.8.RELEASE]
      	at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:738) [spring-aop-4.3.8.RELEASE.jar:4.3.8.RELEASE]
      	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) [spring-aop-4.3.8.RELEASE.jar:4.3.8.RELEASE]
      	at org.springframework.cloud.context.config.StandardBeanLifecycleDecorator$2.invoke(StandardBeanLifecycleDecorator.java:85) [spring-cloud-context-1.2.4.RELEASE.jar:1.2.4.RELEASE]
      	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) [spring-aop-4.3.8.RELEASE.jar:4.3.8.RELEASE]
      	at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:673) [spring-aop-4.3.8.RELEASE.jar:4.3.8.RELEASE]
      	at org.springframework.cloud.netflix.eureka.CloudEurekaClient$$EnhancerBySpringCGLIB$$739cd6a8.shutdown(<generated>) [spring-cloud-netflix-eureka-client-1.3.5.RELEASE.jar:1.3.5.RELEASE]
      	at org.springframework.cloud.netflix.eureka.serviceregistry.EurekaServiceRegistry.deregister(EurekaServiceRegistry.java:71) [spring-cloud-netflix-eureka-client-1.3.5.RELEASE.jar:1.3.5.RELEASE]
      	at org.springframework.cloud.netflix.eureka.serviceregistry.EurekaAutoServiceRegistration.stop(EurekaAutoServiceRegistration.java:82) [spring-cloud-netflix-eureka-client-1.3.5.RELEASE.jar:1.3.5.RELEASE]
      	at org.springframework.cloud.netflix.eureka.serviceregistry.EurekaAutoServiceRegistration.onApplicationEvent(EurekaAutoServiceRegistration.java:126) [spring-cloud-netflix-eureka-client-1.3.5.RELEASE.jar:1.3.5.RELEASE]
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_151]
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_151]
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_151]
      	at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_151]
      	at org.springframework.context.event.ApplicationListenerMethodAdapter.doInvoke(ApplicationListenerMethodAdapter.java:253) [spring-context-4.3.8.RELEASE.jar:4.3.8.RELEASE]
      	at org.springframework.context.event.ApplicationListenerMethodAdapter.processEvent(ApplicationListenerMethodAdapter.java:174) [spring-context-4.3.8.RELEASE.jar:4.3.8.RELEASE]
      	at org.springframework.context.event.ApplicationListenerMethodAdapter.onApplicationEvent(ApplicationListenerMethodAdapter.java:137) [spring-context-4.3.8.RELEASE.jar:4.3.8.RELEASE]
      	at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:167) [spring-context-4.3.8.RELEASE.jar:4.3.8.RELEASE]
      	at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139) [spring-context-4.3.8.RELEASE.jar:4.3.8.RELEASE]
      	at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:383) [spring-context-4.3.8.RELEASE.jar:4.3.8.RELEASE]
      	at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:337) [spring-context-4.3.8.RELEASE.jar:4.3.8.RELEASE]
      	at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:994) [spring-context-4.3.8.RELEASE.jar:4.3.8.RELEASE]
      	at org.springframework.context.support.AbstractApplicationContext$2.run(AbstractApplicationContext.java:928) [spring-context-4.3.8.RELEASE.jar:4.3.8.RELEASE]
      Caused by: java.net.ConnectException: 拒绝连接 (Connection refused)
      	at java.net.PlainSocketImpl.socketConnect(Native Method) ~[na:1.8.0_151]
      	at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) ~[na:1.8.0_151]
      	at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) ~[na:1.8.0_151]
      	at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) ~[na:1.8.0_151]
      	at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) ~[na:1.8.0_151]
      	at java.net.Socket.connect(Socket.java:589) ~[na:1.8.0_151]
      	at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:121) ~[httpclient-4.5.3.jar:4.5.3]
      	at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:180) ~[httpclient-4.5.3.jar:4.5.3]
      	at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:144) ~[httpclient-4.5.3.jar:4.5.3]
      	at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:134) ~[httpclient-4.5.3.jar:4.5.3]
      	at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:610) ~[httpclient-4.5.3.jar:4.5.3]
      	at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:445) ~[httpclient-4.5.3.jar:4.5.3]
      	at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:835) ~[httpclient-4.5.3.jar:4.5.3]
      	at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:118) ~[httpclient-4.5.3.jar:4.5.3]
      	at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:56) ~[httpclient-4.5.3.jar:4.5.3]
      	at com.sun.jersey.client.apache4.ApacheHttpClient4Handler.handle(ApacheHttpClient4Handler.java:173) ~[jersey-apache-client4-1.19.1.jar:1.19.1]
      	... 46 common frames omitted
      
      2018-06-06 11:50:54.435  WARN [choerodon-todo-service,,,] 7357 --- [      Thread-31] c.n.d.s.t.d.RetryableEurekaHttpClient    : Request execution failed with message: java.net.ConnectException: 拒绝连接 (Connection refused)
      2018-06-06 11:50:54.437 ERROR [choerodon-todo-service,,,] 7357 --- [      Thread-31] com.netflix.discovery.DiscoveryClient    : DiscoveryClient_CHOERODON-TODO-SERVICE/10.212.202.51:choerodon-todo-service:8080 - de-registration failedCannot execute request on any known server
      
      com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server
      	at com.netflix.discovery.shared.transport.decorator.RetryableEurekaHttpClient.execute(RetryableEurekaHttpClient.java:111) ~[eureka-client-1.6.2.jar:1.6.2]
      	at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.cancel(EurekaHttpClientDecorator.java:71) ~[eureka-client-1.6.2.jar:1.6.2]
      	at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$2.execute(EurekaHttpClientDecorator.java:74) ~[eureka-client-1.6.2.jar:1.6.2]
      	at com.netflix.discovery.shared.transport.decorator.SessionedEurekaHttpClient.execute(SessionedEurekaHttpClient.java:77) ~[eureka-client-1.6.2.jar:1.6.2]
      	at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.cancel(EurekaHttpClientDecorator.java:71) ~[eureka-client-1.6.2.jar:1.6.2]
      	at com.netflix.discovery.DiscoveryClient.unregister(DiscoveryClient.java:885) [eureka-client-1.6.2.jar:1.6.2]
      	at com.netflix.discovery.DiscoveryClient.shutdown(DiscoveryClient.java:863) [eureka-client-1.6.2.jar:1.6.2]
      	at com.netflix.discovery.DiscoveryClient$$FastClassBySpringCGLIB$$a84c8cb4.invoke(<generated>) [eureka-client-1.6.2.jar:1.6.2]
      	at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204) [spring-core-4.3.8.RELEASE.jar:4.3.8.RELEASE]
      	at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:738) [spring-aop-4.3.8.RELEASE.jar:4.3.8.RELEASE]
      	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) [spring-aop-4.3.8.RELEASE.jar:4.3.8.RELEASE]
      	at org.springframework.cloud.context.config.StandardBeanLifecycleDecorator$2.invoke(StandardBeanLifecycleDecorator.java:85) [spring-cloud-context-1.2.4.RELEASE.jar:1.2.4.RELEASE]
      	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) [spring-aop-4.3.8.RELEASE.jar:4.3.8.RELEASE]
      	at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:673) [spring-aop-4.3.8.RELEASE.jar:4.3.8.RELEASE]
      	at org.springframework.cloud.netflix.eureka.CloudEurekaClient$$EnhancerBySpringCGLIB$$739cd6a8.shutdown(<generated>) [spring-cloud-netflix-eureka-client-1.3.5.RELEASE.jar:1.3.5.RELEASE]
      	at org.springframework.cloud.netflix.eureka.serviceregistry.EurekaServiceRegistry.deregister(EurekaServiceRegistry.java:71) [spring-cloud-netflix-eureka-client-1.3.5.RELEASE.jar:1.3.5.RELEASE]
      	at org.springframework.cloud.netflix.eureka.serviceregistry.EurekaAutoServiceRegistration.stop(EurekaAutoServiceRegistration.java:82) [spring-cloud-netflix-eureka-client-1.3.5.RELEASE.jar:1.3.5.RELEASE]
      	at org.springframework.cloud.netflix.eureka.serviceregistry.EurekaAutoServiceRegistration.onApplicationEvent(EurekaAutoServiceRegistration.java:126) [spring-cloud-netflix-eureka-client-1.3.5.RELEASE.jar:1.3.5.RELEASE]
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_151]
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_151]
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_151]
      	at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_151]
      	at org.springframework.context.event.ApplicationListenerMethodAdapter.doInvoke(ApplicationListenerMethodAdapter.java:253) [spring-context-4.3.8.RELEASE.jar:4.3.8.RELEASE]
      	at org.springframework.context.event.ApplicationListenerMethodAdapter.processEvent(ApplicationListenerMethodAdapter.java:174) [spring-context-4.3.8.RELEASE.jar:4.3.8.RELEASE]
      	at org.springframework.context.event.ApplicationListenerMethodAdapter.onApplicationEvent(ApplicationListenerMethodAdapter.java:137) [spring-context-4.3.8.RELEASE.jar:4.3.8.RELEASE]
      	at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:167) [spring-context-4.3.8.RELEASE.jar:4.3.8.RELEASE]
      	at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139) [spring-context-4.3.8.RELEASE.jar:4.3.8.RELEASE]
      	at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:383) [spring-context-4.3.8.RELEASE.jar:4.3.8.RELEASE]
      	at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:337) [spring-context-4.3.8.RELEASE.jar:4.3.8.RELEASE]
      	at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:994) [spring-context-4.3.8.RELEASE.jar:4.3.8.RELEASE]
      at org.springframework.context.support.AbstractApplicationContext$2.run(AbstractApplicationContext.java:928) [spring-context-4.3.8.RELEASE.jar:4.3.8.RELEASE]
      
      2018-06-06 11:50:54.456  INFO [choerodon-todo-service,,,] 7357 --- [      Thread-31] com.netflix.discovery.DiscoveryClient    : Completed shut down of DiscoveryClient
      2018-06-06 11:50:54.456  INFO [choerodon-todo-service,,,] 7357 --- [      Thread-31] ationConfigEmbeddedWebApplicationContext : Closing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@6f90b74a: startup date [Wed Jun 06 11:50:51 CST 2018]; parent: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@4bdcaf36
      2018-06-06 11:50:54.457  INFO [choerodon-todo-service,,,] 7357 --- [      Thread-31] o.s.c.n.e.s.EurekaServiceRegistry        : Unregistering application choerodon-todo-service with eureka with status DOWN
      2018-06-06 11:50:54.469  INFO [choerodon-todo-service,,,] 7357 --- [      Thread-31] o.s.c.support.DefaultLifecycleProcessor  : Stopping beans in phase 2147483647
      2018-06-06 11:50:54.470  INFO [choerodon-todo-service,,,] 7357 --- [      Thread-31] o.s.c.support.DefaultLifecycleProcessor  : Stopping beans in phase 0
      2018-06-06 11:50:54.472  INFO [choerodon-todo-service,,,] 7357 --- [      Thread-31] o.s.j.e.a.AnnotationMBeanExporter        : Unregistering JMX-exposed beans on shutdown
      2018-06-06 11:50:54.473  INFO [choerodon-todo-service,,,] 7357 --- [      Thread-31] o.s.j.e.a.AnnotationMBeanExporter        : Unregistering JMX-exposed beans
      
      Process finished with exit code 130 (interrupted by signal 2: SIGINT)
      

    注意: 经测试,我的本地案例代码是可以连接到mysql容器数据库的,并可以进行读取数据等操作,重点在于服务无法注册到注册中心。。。。

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:
    - "./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:
    - "./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:
    - ./mysql/mysql_data:/var/lib/mysql
    - ./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://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:
    - zuul.addHostHeader=true
    - zuul.routes.dev.path=/todo/**
    - zuul.routes.dev.serviceId=choerodon-todo-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:
    - 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有关,可能端口没有映射,你浏览器访问http://127.0.0.1:8000可以访问通不?

浏览器可以访问 Eureka,但是就是本地demo案例一直无法注册上去。。。


这些都没问题,哎,实在不行的话,你能把你那边的demo案例发我一份吗?

我这试了多次了,1.本地新增项目自己构建一个eureka注册中心,demo案例项目服务可以注册;2.项目在不加@EnableEurekaClient注解的情况下启动,无报错,但是服务无法注册,通过postman访问接口,可以拿到mysql容器数据库表中的数据。理论上如果项目可以正常访问mysql容器组件,那么项目服务应该也可以注册到eureka注册中心组件容器吧,而且注册中心这个我通过浏览器localhost:8000是可以访问到的。

咨询下,这个平台线上有运行的环境吗?怎么访问?

如上服务注册的问题,已查找到原因,application.yml配置问题,eureka相关配置挂在了spring节点下导致,如下为正确配置:

spring:
  application:
    name: choerodon-todo-service
  datasource:
    url: jdbc:mysql://localhost/choerodon_demo_service_todo?useUnicode=true&characterEncoding=utf-8&useSSL=false
    username: choerodon
    password: 123456
server:
  port: 9999
mybatis:
  mapperLocations: classpath*:/mapper/*.xml
  configuration:
    mapUnderscoreToCamelCase: true
management:
  port: 8081
  security:
    enabled: false
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/}