apache / shenyu

Apache ShenYu is a Java native API Gateway for service proxy, protocol conversion and API governance.
https://shenyu.apache.org/
Apache License 2.0
8.44k stars 2.93k forks source link

[Question] When i use docker-compose to star up shenyu on local dev env, is there any problems for configuration? #5265

Closed WXzhongwang closed 12 months ago

WXzhongwang commented 1 year ago

Question

Is there anything i missed?

shenyu-admin:

image

this is the shenyu-admin yaml config:

server:
  port: 9095
  address: 0.0.0.0

spring:
  profiles:
    active: mysql
  thymeleaf:
    cache: true
    encoding: utf-8
    enabled: true
    prefix: classpath:/static/
    suffix: .html
  mvc:
    pathmatch:
      matching-strategy: ant_path_matcher
  jackson:
    time-zone: GMT+8 # GMT , Asia/Shanghai
  messages:
    basename: message/i18n

management:
  health:
    mail:
      enabled: off
  endpoints:
    web:
      exposure:
        include:
          - 'health'
          - 'prometheus'
    enabled-by-default: true

mybatis:
  config-location: classpath:/mybatis/mybatis-config.xml
  mapper-locations: classpath:/mappers/*.xml
  type-handlers-package: org.apache.shenyu.admin.mybatis.handler

shenyu:
  register:
    registerType: http #http #zookeeper #etcd #nacos #consul
    serverLists: #localhost:2181 #http://localhost:2379 #localhost:8848
    props:
      sessionTimeout: 5000
      connectionTimeout: 2000
      checked: true
      zombieCheckThreads: 10
      zombieCheckTimes: 5
      scheduledTime: 10
      nacosNameSpace: ShenyuRegisterCenter
  sync:
    websocket:
      enabled: true
      messageMaxSize: 10240
      allowOrigins: ws://localhost:9095;ws://localhost:9195;
#    apollo:
#      meta: http://localhost:8080
#      appId: shenyu
#      portalUrl: http://localhost:8070
#      env: dev
#      clusterName: test
#      namespace: application
#      token: 0fff5645fc74ee5e0d63a6389433c8c8afc0beea31eed0279ecc1c8961d12da9
#    zookeeper:
#      url: localhost:2181
#      sessionTimeout: 5000
#      connectionTimeout: 2000
#    http:
#      enabled: true
#    nacos:
#      url: localhost:8848
#      namespace: 1c10d748-af86-43b9-8265-75f487d20c6c
#      username:
#      password:
#      acm:
#        enabled: false
#        endpoint: acm.aliyun.com
#        namespace:
#        accessKey:
#        secretKey:
#    polaris:
#      url: 127.0.0.1:8093
#      namespace:
#      fileGroup:
#    etcd:
#      url: http://localhost:2379
#    consul:
#      url: http://localhost:8500
  ldap:
    enabled: false
    url: ldap://xxxx:xxx
    bind-dn: cn=xxx,dc=xxx,dc=xxx
    password: xxxx
    base-dn: ou=xxx,dc=xxx,dc=xxx
    object-class: person
    login-field: cn
  jwt:
    expired-seconds: 86400000
  shiro:
    white-list:
      - /
      - /favicon.*
      - /static/**
      - /index**
      - /platform/login
      - /websocket
      - /error
      - /actuator/health
      - /actuator/health/** # /actuator/health/readiness /actuator/health/liveness
      - /actuator/prometheus
      - /swagger-ui.html
      - /swagger-ui/**
      - /webjars/**
      - /v3/api-docs/**
      - /csrf
      - /alert/report
  dashboard:
    core:
      onlySuperAdminPermission:
        - system:manager:add
        - system:manager:edit
        - system:manager:delete
        - system:role:add
        - system:role:edit
        - system:role:delete
        - system:resource:addButton
        - system:resource:addMenu
        - system:resource:editButton
        - system:resource:editMenu
        - system:resource:deleteButton
        - system:resource:deleteMenu

springdoc:
  api-docs:
    enabled: true
  swagger-ui:
    enabled: true
    tags-sorter: alpha
  packages-to-scan: org.apache.shenyu.admin.controller
  paths-to-match: /**

logging:
  level:
    root: info
    org.springframework.boot: info
    org.apache.ibatis: info
    org.apache.shenyu.bonuspoint: info
    org.apache.shenyu.lottery: info
    org.apache.shenyu: info
#    org.apache.shenyu.admin.utils.HttpUtils: debug

application-mysql.yaml:

shenyu:
  database:
    dialect: mysql
    init_enable: true

spring:
  datasource:
    url: jdbc:mysql://host.docker.internal:3306/shenyu?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai&zeroDateTimeBehavior=convertToNull
    username: root
    password: xxxx
    driver-class-name: com.mysql.cj.jdbc.Driver
    hikari:
      connection-timeout: 30000
      minimum-idle: 5
      maximum-pool-size: 20
      auto-commit: true
      idle-timeout: 600000
      max-lifetime: 1800000
      connection-test-query: SELECT 1
      connection-init-sql: SET NAMES utf8mb4
      validation-timeout: 800
  mail:
    # Attention: this is mail server address.
    host: smtp.qq.com
    username: shenyu@apache.com
    # Attention: this is not email account password, this requires an email authorization code
    password: your-password
    #Attention: Tencent mail smtps 465,smtp 587
    port: 587
    properties:
      mail:
        smtp:
          socketFactoryClass: javax.net.ssl.SSLSocketFactory
          ssl:
            enable: true

shenyu-bootstrap:

image
WXzhongwang commented 1 year ago

And i find the logs files are empty?

WXzhongwang commented 1 year ago
image image
WXzhongwang commented 1 year ago

Looking forward your reply.

image
moremind commented 1 year ago

execute the command docker exec -it shenyu-admin /bin/bash and show your logs

moremind commented 1 year ago

execute the command docker exec -it shenyu-admin /bin/bash and show your logs

shenyu admin must launch firstly, pls check shenyu admin

WXzhongwang commented 1 year ago

shenyu-admin log files is empty as well.

WXzhongwang commented 1 year ago
image
WXzhongwang commented 1 year ago
image
WXzhongwang commented 1 year ago
image

the java progress seems to be alived.

WXzhongwang commented 1 year ago

docker-compose.yml

version: "3"
services:
  shenyu-bootstrap:
    image: apache/shenyu-bootstrap:latest
    container_name: shenyu-bootstrap
    ports:
      - "9195:9195"
    volumes:
      - ./shenyu-bootstrap/logs/:/opt/shenyu-bootstrap/logs
      - ./shenyu-bootstrap/conf/:/opt/shenyu-bootstrap/conf
    depends_on:
      - shenyu-admin
    environment:
      - shenyu.sync.websocket.urls=ws://shenyu-admin:9095/websocket
    healthcheck:
      test: [ "CMD", "wget", "http://shenyu-bootstrap:9195/actuator/health" ]
      timeout: 2s
      retries: 30
  shenyu-admin:
    image: apache/shenyu-admin:latest
    container_name: shenyu-admin
    volumes:
      - ./shenyu-admin/logs/:/opt/shenyu-admin/logs
      - ./shenyu-admin/conf/:/opt/shenyu-admin/conf
    ports:
      - "9095:9095"
    healthcheck:
      test: [ "CMD-SHELL", "wget -q -O - http://shenyu-admin:9095/actuator/health | grep UP || exit 1" ]
      timeout: 2s
      retries: 30
WXzhongwang commented 1 year ago
image
WXzhongwang commented 1 year ago

@moremind how can i make some testing, or any direction i can use for move on. Cause i have been blocked. Hopefully your help.

moremind commented 1 year ago

@moremind how can i make some testing, or any direction i can use for move on. Cause i have been blocked. Hopefully your help.

your services may be unhealthy?

moremind commented 1 year ago

if you pull images from docker hub, you should change the service of shenyu-admin version to v2.6.0. If you build want to build images in your local environment, pls execute the command: ./mvnw -B clean install -Prelease,docker -Dmaven.javadoc.skip=true -B -Drat.skip=true -Dmaven.test.skip=true -Djacoco.skip=true -DskipITs -DskipTests package -T1C

WXzhongwang commented 1 year ago

@moremind First of all, appreaciate for your reply, I did have a try today and pulled images from docker hub v2.6.0, two questions here:

  1. the docker-compose.yml seems that the "ext-lib" dir volume mapping was missing so that the shenyu-admin didn't work fine, screenshot as below. image
  2. shenyu-bootstrap container cann't work fine, screenshot as below. if i assist to run shenyu-bootstrap like this way, how can i resolve this problem? add command line args? Hopefully your help. image
WXzhongwang commented 1 year ago

and then i used docker to set up two containters as below:

docker network create shenyu
docker run --name shenyu-admin \
-v /Users/yuanjinxiu/shenyu-v2.6.0/shenyu-admin/ext-lib:/opt/shenyu-admin/ext-lib \
-v /Users/yuanjinxiu/shenyu-v2.6.0/shenyu-admin/logs:/opt/shenyu-admin/logs \
-e "SPRING_PROFILES_ACTIVE=mysql"\
 -e "spring.datasource.url=jdbc:mysql://host.docker.internal:3306/shenyu?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai&zeroDateTimeBehavior=convertToNull" \
 -e "spring.datasource.username=root" \
 -e "spring.datasource.password=xxx" \
 -d -p 9095:9095 \
 --net shenyu \
 apache/shenyu-admin:2.6.0

docker run -d \
  -p 9195:9195 \
  --name shenyu-bootstrap \
  -v /Users/yuanjinxiu/shenyu-v2.6.0/shenyu-bootstrap/logs/:/opt/shenyu-bootstrap/logs \
  -v /Users/yuanjinxiu/shenyu-v2.6.0/shenyu-bootstrap/conf/:/opt/shenyu-bootstrap/conf \
  -e "shenyu.register.serverLists=zookeeper:2181" \
  -e "shenyu.register.registerType=zookeeper" \
  -e "spring.main.allow-bean-definition-overriding=true" \
  --net shenyu \
  --env SHENYU_SYNC_WEBSOCKET_URLS=ws://shenyu-admin:9095/websocket \
  apache/shenyu-bootstrap:2.6.0

the yaml of shenyu bootstrap as below:

server:
  port: 9195
  address: 0.0.0.0
  compression:
    enabled: true
    minResponseSize: 1MB # If the response data is greater than 1MB, enable compression.

spring:
  main:
    allow-bean-definition-overriding: true
  application:
    name: shenyu-bootstrap
  codec:
    max-in-memory-size: 2MB
  cloud:
    discovery:
      enabled: false
    nacos:
      discovery:
        server-addr: 127.0.0.1:8848 # Spring Cloud Alibaba Dubbo use this.
        enabled: false
        namespace: ShenyuRegisterCenter

# if you want use ribbon please config every server.
#springCloud-test:
#  ribbon:
#    NIWSServerListClassName: com.netflix.niws.loadbalancer.DiscoveryEnabledNIWSServerList

eureka:
  client:
    enabled: false
    serviceUrl:
      defaultZone: http://localhost:8761/eureka/
  instance:
    prefer-ip-address: true

#  security:
#    oauth2:
#      client:
#        registration:
#          <your client-registration-id>:
#            client-id: <your client-id>
#            client-secret: <your client-secret>
#        provider:
#          <your client-registration-id>:
#            authorization-uri: <your authorization-uri>
#            token-uri: <your access-token-uri>
#            user-info-uri: <your user-info-uri>
#            jwk-set-uri: <your jwk-set-uri>

management:
  health:
    redis:
      enabled: false
    elasticsearch:
      enabled: false
  endpoint:
    health:
      enabled: true
      show-details: always
  endpoints:
    web:
      exposure:
        include: "*" # or health,info

shenyu:
  selectorMatchCache:
    ## selector L1 cache
    cache:
      enabled: false
      initialCapacity: 10000 # initial capacity in cache
      maximumSize: 10000 # max size in cache
    ## selector L2 cache, use trie as L2 cache
    trie:
      enabled: false
      cacheSize: 128 # the number of plug-ins
      matchMode: antPathMatch
  ruleMatchCache:
    ## rule L1 cache
    cache:
      enabled: true
      initialCapacity: 10000 # initial capacity in cache
      maximumSize: 65536 # max size in cache
    ## rule L2 cache, use trie as L2 cache
    trie:
      enabled: false
      cacheSize: 1024 # the number of selectors
      matchMode: antPathMatch
  netty:
    http:
      # set to false, user can custom the netty tcp server config.
      webServerFactoryEnabled: true
      selectCount: 1
      workerCount: 8
      accessLog: false
      serverSocketChannel:
        soRcvBuf: 87380
        soBackLog: 128
        soReuseAddr: false
        connectTimeoutMillis: 10000
        writeBufferHighWaterMark: 65536
        writeBufferLowWaterMark: 32768
        writeSpinCount: 16
        autoRead: false
        allocType: "pooled"
        messageSizeEstimator: 8
        singleEventExecutorPerGroup: true
      socketChannel:
        soKeepAlive: false
        soReuseAddr: false
        soLinger: -1
        tcpNoDelay: true
        soRcvBuf: 87380
        soSndBuf: 16384
        ipTos: 0
        allowHalfClosure: false
        connectTimeoutMillis: 10000
        writeBufferHighWaterMark: 65536
        writeBufferLowWaterMark: 32768
        writeSpinCount: 16
        autoRead: false
        allocType: "pooled"
        messageSizeEstimator: 8
        singleEventExecutorPerGroup: true
      sni:
        enabled: false
        mod: k8s #manul
        defaultK8sSecretNamespace: shenyu-ingress
        defaultK8sSecretName: default-cert
#        mod: manual
#        certificates:
#          - domain: 'localhost'
#            keyCertChainFile: '/Users/zhukunshuai/Desktop/cert/example.com+1.pem'
#            keyFile: '/Users/zhukunshuai/Desktop/cert/example.com+1-key.pem'
#          - domain: 'example.com'
#            keyCertChainFile: '/Users/zhukunshuai/Desktop/cert/example.com+1.pem'
#            keyFile: '/Users/zhukunshuai/Desktop/cert/example.com+1-key.pem'
#  httpclient:
#    strategy: webClient # netty
#    connectTimeout: 45000
#    responseTimeout: 3000
#    readerIdleTime: 3000
#    writerIdleTime: 3000
#    allIdleTime: 3000
#    readTimeout: 3000
#    writeTimeout: 3000
#    wiretap: false
#    keepAlive: false
#    maxInMemorySize: 1 #1mb
#    pool:
#      type: ELASTIC
#      name: proxy
#      maxConnections: 16
#      acquireTimeout: 45000
#      maxIdleTime: 3000 # unit: ms
#      maxLifeTime:  # unit: ms
#      evictionInterval:  # unit: ms
#      metrics: false
#    proxy:
#      host:
#      port:
#      username:
#      password:
#      nonProxyHostsPattern:
#    ssl:
#      useInsecureTrustManager: true
#      keyStoreType: PKCS12
#      keyStorePath: classpath:keystore.p12
#      keyStorePassword: 123456
#      keyStoreProvider:
#      keyPassword: 123456
#      trustedX509Certificates:
#      handshakeTimeout:
#      closeNotifyFlushTimeout:
#      closeNotifyReadTimeout:
#      defaultConfigurationType:
#    threadPool:
#      prefix: shenyu
#      selectCount: 1
#      workerCount: 8
#      daemon: true
  duplicate-response-header:
    strategy: RETAIN_FIRST
    headers:
      - Access-Control-Allow-Origin
  register:
    enabled: false
    registerType: zookeeper #etcd #consul
    serverLists: localhost:2181 #http://localhost:2379 #localhost:8848
    props:
  cross:
    enabled: true
    allowedHeaders:
    allowedMethods: "*"
    allowedAnyOrigin: true # the same of Access-Control-Allow-Origin: "*"
#    allowedOrigin:
      # format : schema://prefix spacer domain
      # Access-Control-Allow-Origin: "http://a.apache.org,http://b.apache.org"
#      spacer: "."
#      domain: apache.org
#      prefixes:
#        - a # a.apache.org
#        - b # b.apache.org
#      origins:
#        - c.apache.org
#        - d.apache.org
#        - http://e.apache.org
#      originRegex: ^http(|s)://(.*\.|)abc.com$
    allowedExpose: ""
    maxAge: "18000"
    allowCredentials: true

  switchConfig:
    local: true
    collapseSlashes: false
  file:
    enabled: true
    maxSize : 10
  sync:
    websocket:
      urls: ws://shenyu-admin:9095/websocket
#      allowOrigin: ws://shenyu-admin:9195
#    apollo:
#      appId: shenyu
#      meta: http://localhost:8080
#      env: dev
#      clusterName: test
#      namespace: application
#    zookeeper:
#      url: localhost:2181
#      sessionTimeout: 5000
#      connectionTimeout: 2000
#    http:
#      url: http://localhost:9095
#      username:
#      password:
#    nacos:
#      url: localhost:8848
#      namespace: 1c10d748-af86-43b9-8265-75f487d20c6c
#      username:
#      password:
#      acm:
#        enabled: false
#        endpoint: acm.aliyun.com
#        namespace:
#        accessKey:
#        secretKey:
#    polaris:
#      url: 127.0.0.1:8093
#      namespace:
#      fileGroup:
#    etcd:
#      url: http://localhost:2379
#    consul:
#      url: http://localhost:8500
#      waitTime: 10000
#      watchDelay: 10000
  exclude:
    enabled: false
    paths:
      - /favicon.ico
  fallback:
    enabled: false
    paths:
      - /fallback/hystrix
      - /fallback/resilience4j
      - /fallback/sentinel
  health:
    enabled: true
    paths:
      - /actuator
      - /health_check
  alert:
    enabled: true
    admins: localhost:9095
  extPlugin:
    path:
    enabled: true
    threads: 1
    scheduleTime: 300
    scheduleDelay: 30
  scheduler:
    enabled: false
    type: fixed
    threads: 16
  upstreamCheck:
    enabled: false
    poolSize: 10
    timeout: 3000
    healthyThreshold: 1
    unhealthyThreshold: 1
    interval: 5000
    printEnabled: true
    printInterval: 60000
  springCloudCache:
    enabled: false
  ribbon:
    serverListRefreshInterval: 10000
  metrics:
    enabled: false
    name : prometheus
    host: 127.0.0.1
    port: 8090
    jmxConfig:
    props:
      jvm_enabled: true
#  plugins:
#    rate-limiter.enabled: false
  local:
    enabled: false
    sha512Key: "BA3253876AED6BC22D4A6FF53D8406C6AD864195ED144AB5C87621B6C233B548BAEAE6956DF346EC8C17F5EA10F35EE3CBC514797ED7DDD3145464E2A0BAB413"
  websocket:
    enableProxyPing: false
#  sharedPool:
#    enable: true
#    prefix: "shenyu-shared"
#    corePoolSize: 200
#    maximumPoolSize: 2000
#    keepAliveTime: 60000
#    # 1GB
#    maxWorkQueueMemory: 1073741824
#    # 256MB
#    maxFreeMemory: 268435456

logging:
  level:
    root: info
    org.springframework.boot: info
    org.apache.ibatis: info
    org.apache.shenyu.bonuspoint: info
    org.apache.shenyu.lottery: info
    org.apache.shenyu: info
    org.springframework.http.server.reactive: info
    org.springframework.web.reactive: info
    reactor.ipc.netty: info
    reactor.netty: info

shenyu-admin start up normally, shenyu-bootstrap was launched this time, but there are some error logs occured.

image image

Any helps would be appreciated!

moremind commented 1 year ago

websocket-sync configuration is error, pls refer to:https://shenyu.apache.org/docs/user-guide/property-config/gateway-property-config