网关服务部署

网关服务部署

网关部署配置

网关服务基于Spring Cloud Zuul实现,是所有API接口的入口,zuul旨在实现动态路由,监控,弹性和安全性

网关部署相对来说比较简单,以下分别以单机部署和集群部署的方式分别说明

网关服务单机部署

docker单机部署网关服务

docker run -d --name gateway --restart always --net iot \
    -p 9000:9000 \
    -e JAVA_OPTS=" \
        -Dserver.port=9000 \
        -Deureka.client.service-url.defaultZone=http://127.0.0.1:8763/eureka/ \
        -Dspring.redis.host=redis \
        -Dspring.redis.port=6379 \
        -Dspring.servlet.multipart.max-request-size=100MB \
        -Dspring.servlet.multipart.max-file-size=10MB \
        -Dh-visions.gateway.skip=/file-management/file/downloadFile,/activiti/editor,/activiti/service,/file/downloadFile,/data-query-service/api,/data-query-service/data,/data-query-service/visual,/iot-data-service/dsManagement,/qas-sqlflow,/equipment-management/email,/equipment-management/setting,/equipment-management/group,/equipment-management/equipment,/equipment-management/resource,/equipment-management,/data-query-service/getList,/api/iot-data-service,/iot-data-service/project,/ai-predict/predict/v1/ai_source \
        -Dh-visions.gateway.valid=false \
        -Dh-visions.gateway.license-path=/app/license \
        -Xmx256m \
    " \
    harbor.hipermatrix.com:10300/services/gateway:2.9.4

说明:如果运行提示iot的network找不到,请先使用以下的命令创建名称为iot的网络,之后的docker命令对iot的网络同样都采用这里的处理方式

docker network create iot

eureka.client.service-url.defaultZone配置为eureka服务的地址,根据实际的环境进行对应的配置,上面示例配置的eureka服务运行在本机环境的单机节点,如果eureka server是集群方式运行,eureka的service-url.defaultZone配置成集群的url地址即可,如http://192.168.1.101:8763/eureka/,http://192.168.1.102:8763/eureka/

spring.redis.host和spring.redis.port为redis服务对应的主机地址和端口,这里主机名配置的是redis,保证redis服务的docker容器运行在本机,容器名称也是采用redis命名

java命令单机部署网关服务

java -jar \
    -Dserver.port=9000 \
    -Deureka.client.service-url.defaultZone=http://127.0.0.1:8763/eureka/ \
    -Dspring.redis.host=127.0.0.1 \
    -Dspring.redis.port=6379 \
    -Dspring.servlet.multipart.max-request-size=100MB \
    -Dspring.servlet.multipart.max-file-size=10MB \
    -Dh-visions.gateway.skip=/file-management/file/downloadFile,/activiti/editor,/activiti/service,/file/downloadFile,/data-query-service/api,/data-query-service/data,/data-query-service/visual,/iot-data-service/dsManagement,/qas-sqlflow,/equipment-management/email,/equipment-management/setting,/equipment-management/group,/equipment-management/equipment,/equipment-management/resource,/equipment-management,/data-query-service/getList,/api/iot-data-service,/iot-data-service/project,/ai-predict/predict/v1/ai_source \
    -Dh-visions.gateway.valid=false \
    -Dh-visions.gateway.license-path=/app/license \
    -Xmx256m \
    gateway-2.9.4.jar

配置的调整请参考docker单机部署章节里面的配置调整说明

网关集群部署

在高可用场景下面,需要在多个节点上面部署网关服务的实例,下面以两个服务器节点为例说明服务服务高可用部署

假定两个服务器的节点信息如下:

节点1: 192.168.1.101
节点2: 192.168.1.102

假定两个eureka服务的集群已经部署在节点1和节点2上面,eureka url地址分别为http://192.168.1.101:8763/eureka/和http://192.168.1.102:8763/eureka/

根据实际环境修改为相应的ip地址信息,下面示例中的ip地址根据实际环境中的ip地址进行替换,如果环境中有DNS主机名称的解析,节点的地址可以采用主机名代替ip

docker部署网关服务集群

在节点1上运行:

docker run -d --name gateway --restart always --net iot \
    -p 9000:9000 \
    -e JAVA_OPTS=" \
        -Dserver.port=9000 \
        -Deureka.instance.prefer-ip-address=true \
        -Deureka.instance.ip-address=192.168.1.101 \
        -Deureka.instance.instance-id=gateway-1:9000 \
        -Deureka.client.service-url.defaultZone=http://192.168.1.101:8763/eureka/,http://192.168.1.102:8763/eureka/ \
        -Dspring.redis.host=192.168.1.101 \
        -Dspring.redis.port=6379 \
        -Dspring.servlet.multipart.max-request-size=100MB \
        -Dspring.servlet.multipart.max-file-size=10MB \
        -Dh-visions.gateway.skip=/file-management/file/downloadFile,/activiti/editor,/activiti/service,/file/downloadFile,/data-query-service/api,/data-query-service/data,/data-query-service/visual,/iot-data-service/dsManagement,/qas-sqlflow,/equipment-management/email,/equipment-management/setting,/equipment-management/group,/equipment-management/equipment,/equipment-management/resource,/equipment-management,/data-query-service/getList,/api/iot-data-service,/iot-data-service/project,/ai-predict/predict/v1/ai_source \
        -Dh-visions.gateway.valid=false \
        -Dh-visions.gateway.license-path=/app/license \
        -Xmx256m \
    " \
    harbor.hipermatrix.com:10300/services/gateway:2.9.4

在节点2上运行:

docker run -d --name gateway --restart always --net iot \
    -p 9000:9000 \
    -e JAVA_OPTS=" \
        -Dserver.port=9000 \
        -Deureka.instance.prefer-ip-address=true \
        -Deureka.instance.ip-address=192.168.1.102 \
        -Deureka.instance.instance-id=gateway-2:9000 \
        -Deureka.client.service-url.defaultZone=http://192.168.1.101:8763/eureka/,http://192.168.1.102:8763/eureka/ \
        -Dspring.redis.host=192.168.1.101 \
        -Dspring.redis.port=6379 \
        -Dspring.servlet.multipart.max-request-size=100MB \
        -Dspring.servlet.multipart.max-file-size=10MB \
        -Dh-visions.gateway.skip=/file-management/file/downloadFile,/activiti/editor,/activiti/service,/file/downloadFile,/data-query-service/api,/data-query-service/data,/data-query-service/visual,/iot-data-service/dsManagement,/qas-sqlflow,/equipment-management/email,/equipment-management/setting,/equipment-management/group,/equipment-management/equipment,/equipment-management/resource,/equipment-management,/data-query-service/getList,/api/iot-data-service,/iot-data-service/project,/ai-predict/predict/v1/ai_source \
        -Dh-visions.gateway.valid=false \
        -Dh-visions.gateway.license-path=/app/license \
        -Xmx256m \
    " \
    harbor.hipermatrix.com:10300/services/gateway:2.9.4

eureka相关的参数说明如下:
eureka.instance.instance-id: 表示注册到eureka服务上的服务id
eureka.client.service-url.defaultZone: 表示eureka服务集群的地址
prefer-ip-address: 表示使用eureka client的服务采用ip地址的信息注册到eureka server
ip-address: eureka client注册到eureka server使用的ip地址,在节点1和节点2部署时,分别采用各自的ip地址

java命令部署运行网关服务集群

节点1上面运行:

java -jar \
    -Dserver.port=9000 \
    -Deureka.instance.prefer-ip-address=true \
    -Deureka.instance.ip-address=192.168.1.101 \
    -Deureka.instance.instance-id=gateway-1:9000 \
    -Deureka.client.service-url.defaultZone=http://192.168.1.101:8763/eureka/,http://192.168.1.102:8763/eureka/ \
    -Dspring.redis.host=192.168.1.101 \
    -Dspring.redis.port=6379 \
    -Dspring.servlet.multipart.max-request-size=100MB \
    -Dspring.servlet.multipart.max-file-size=10MB \
    -Dh-visions.gateway.skip=/file-management/file/downloadFile,/activiti/editor,/activiti/service,/file/downloadFile,/data-query-service/api,/data-query-service/data,/data-query-service/visual,/iot-data-service/dsManagement,/qas-sqlflow,/equipment-management/email,/equipment-management/setting,/equipment-management/group,/equipment-management/equipment,/equipment-management/resource,/equipment-management,/data-query-service/getList,/api/iot-data-service,/iot-data-service/project,/ai-predict/predict/v1/ai_source \
    -Dh-visions.gateway.valid=false \
    -Dh-visions.gateway.license-path=/app/license \
    -Xmx256m \
    gateway-2.9.4.jar

节点2上面运行:

java -jar \
    -Dserver.port=9000 \
    -Deureka.instance.prefer-ip-address=true \
    -Deureka.instance.ip-address=192.168.1.102 \
    -Deureka.instance.instance-id=gateway-1:9000 \
    -Deureka.client.service-url.defaultZone=http://192.168.1.101:8763/eureka/,http://192.168.1.102:8763/eureka/ \
    -Dspring.redis.host=192.168.1.101 \
    -Dspring.redis.port=6379 \
    -Dspring.servlet.multipart.max-request-size=100MB \
    -Dspring.servlet.multipart.max-file-size=10MB \
    -Dh-visions.gateway.skip=/file-management/file/downloadFile,/activiti/editor,/activiti/service,/file/downloadFile,/data-query-service/api,/data-query-service/data,/data-query-service/visual,/iot-data-service/dsManagement,/qas-sqlflow,/equipment-management/email,/equipment-management/setting,/equipment-management/group,/equipment-management/equipment,/equipment-management/resource,/equipment-management,/data-query-service/getList,/api/iot-data-service,/iot-data-service/project,/ai-predict/predict/v1/ai_source \
    -Dh-visions.gateway.valid=false \
    -Dh-visions.gateway.license-path=/app/license \
    -Xmx256m \
    gateway-2.9.4.jar
2022-08-11
0