SpringBoot以及网关服务配置部署和发布

云服务
aliyunCloud,tencentCloud ......

做任何事情之前,先考虑以下几个方面:

1细节决定成败
2墨菲定律


一、工具管理服务搭建

1、Maven搭建
   ......
2、Jenkins搭建
   创建工程名aliyun-release-springboot-infinite-gateway-server
   General  描述XXX服务   
   流水线
    定义  Pipeline script
     脚本
     

pipeline {
   agent { label 'master' }

   tools {
      maven "Maven3.6.3"
   }

   stages {
      stage("git check out"){
         steps{
            git branch: 'release', credentialsId: 'ff9242fa-f8d5-462b-b1e0-0eb992fed0a1', url: 'https://gl.springboot.cn/infinite/springboot-infinite-gateway-server.git'
         }
      }
      stage('docker-push-image') {
         steps{
            sh "mvn  -U clean compile install -e  -P ali-release -Dmaven.test.skip=true docker:build -D pushImage" 
         }
      }
   }
}


    
3、Git搭建
......

4、工程搭建
    gateway-server
    xxxxx-server

5、基础搭建
.....

二、相关配置

springboot-infinite-gateway-server.yml

# tomcat配置
cn:
  springboot:
    aps:
      version: v100000002
    gateway:
      httpclient:
        connectTimeout: 5000
        responseTimeout: 5000
    api:
      req:
        verify:
          isOpen: 0
              
# spring:
#   security:
#     user:
#       name: springboot
#       password: springboot@2020
##sentinel
nacos:
  address: nacos-headless.middleware
  degradeRulesDataId: gateway-degrade-rules
  flowRulesDataId: gateway-flow-rules
  groupId: SENTINEL_GROUP
  tokenServerDataId: yhtplus-token-servers
sentinel:
  dashboardURL: sentinel-dashboard.middleware:8080
  enabled: true
  project:
    name: gateway

server:
  tomcat:
    max-threads: 1000
    min-spare-threads: 500


logging:
  path: /data/logs/inspire

======================================================================================================


springboot-infinite-common.yml

cn:
  springboot:
    swagger: 
      enabled: true
    api:
      access:
        key: UER9oXBfDvdIm7G6Gz9O
      exclude:
        urls: 'health,api-docs'
      req:
        verify:
          isOpen: 1
    feign:
      http:
        timeout: 5000
    leaf:
      zk:
        # server: 172.26.0.24:2181
        server: zookeeper-svc.middleware:2181
        #server: 106.52.167.205:31017
#日志配置
logging:
   level:
      cn.springboot: INFO
      com.alibaba: WARN
   path: /data/log
#fegin配置
feign:
  #feign开启熔断
  hystrix:
    enabled: false
  #使用httpclient
  httpclient:
    enabled: true
  #请求/响应压缩
  compression:
    request:
      enabled: true
      mime-types: text/xml,application/xml,application/json
      min-request-size: 2048
    response:
      enabled: true
hystrix:
  command:
    default:
      circuitBreaker:
        sleepWindowInMilliseconds: 5000
        forceClosed: true
      execution:
        timeout:
          enabled: true
        isolation:
          thread:
            timeoutInMilliseconds: ${cn.springboot.feign.http.timeout}
ribbon:
  ReadTimeout: ${cn.springboot.feign.http.timeout}
  ConnectTimeout: ${cn.springboot.feign.http.timeout}
#监控配置
management:
  health:
    defaults:
      enabled: false
spring:
  mvc:
    throw-exception-if-no-handler-found: true
    static-path-pattern: /statics/**
JsonResult:
  dev:
    enabled: true


注: ${cn.springboot.feign.http.timeout}
表示嵌套使用
cn:
  springboot:
    feign: ..........


======================================================================

springboot-infinite-dynamic-routes.yml

routes:
# base-auth
- id: springboot-bullet-image-rest
  predicates:
  - Path=/springboot-bullet-image-rest/**
  uri: lb://springboot-bullet-image-rest
  filters:
  - StripPrefix=1
- id: springboot-genius-marketing-rest
  predicates:
  - Path=/springboot-genius-marketing-rest/**
  uri: lb://springboot-genius-marketing-rest
  filters:
  - StripPrefix=1
- id: springboot-infinite-abtest-rest
  predicates:
  - Path=/springboot-infinite-abtest-rest/**
  uri: lb://springboot-infinite-abtest-rest
  filters:
  - StripPrefix=1
- id: springboot-infinite-monitor-service
  predicates:
  - Path=/springboot-infinite-monitor-service/**
  uri: lb://springboot-infinite-monitor-service
  filters:
  - StripPrefix=1


配置好nacos之后


springboot-infinite-gateway-server
bootstrap.yaml

spring:
  application:
    name: springboot-infinite-gateway-server
  profiles:
    active: '@filter-resource-name@'
  cloud:
    nacos:
      config:
        file-extension: yml
        shared-dataids: springboot-infinite-common.yml
        router-dataids: springboot-infinite-dynamic-routes.yml
        refreshable-dataids: ${spring.cloud.nacos.config.shared-dataids},${spring.application.name}.yml,${spring.cloud.nacos.config.router-dataids}
    gateway:
      discovery:
        locator:
          enabled: false
      httpclient:
        connect-timeout: ${cn.springboot.gateway.httpclient.connectTimeout}
        response-timeout: ${cn.springboot.gateway.httpclient.responseTimeout}
# server
server:
  port: 8000
#下面这一行务必不能少,区分不同配置,而且必须是三个字符"-"
---
spring:
  profiles: dev
  cloud:
    nacos:
      discovery:
        server-addr: localhost:8848
        namespace: d7b38dd9-ac15-4328-b18b-2719040ebf96
      config:
        server-addr: localhost:8848
        namespace: d7b38dd9-ac15-4328-b18b-2719040ebf96
---


启动springboot-infinite-gateway-server项目

输入localhost:8000

{"resultCode":0,"resultMsg":"OK","detailMsg":null,"resultData":"Hello, Gateway!"}

三、部署
以aliyun平台模板


进入阿里云服务,进入
容器服务 Kubernetes 版

创建环境


打开jenkins  左边(BuildHistory)构建历史#进入
点入到  控制台输出 ( Console Output )

找到镜像打包的字符串  202011061557  找到路径地址
[INFO] Pushing registry.cn-shenzhen.aliyuncs.com/weige/inspire-ali-release-springboot-infinite-gateway-server:202011061557

镜像:202011061557

复制模块
inspire-ali-release-springboot-infinite-gateway-server

右上角使用
镜像创建
应用名称,副本数量1,时区同步

镜像名称:选择镜像 ,搜索inspire-ali-release-springboot-infinite-gateway-server 然后选中确定
镜像Tag:选择镜像tag  -  202011061557
资源限制  8c16g 填写  8  Core  - 16384 Mib
所需资源  如上
环境变量:
就绪检查:开启,http请求,HTTP,路径,端口
数据卷:增加本地存储  ,增加云存储声明
日志服务
访问设置

阿里云-容器服务
先配置A服务(服务端口,容器端口)
服务类型选择虚拟集群IP,服务端口和容器端口一样,协议TCP
yaml文件,如下
apiVersion: v1
kind: Service
metadata:
  creationTimestamp: '2020-12-15T08:14:56Z'
  name: springboot-infinite-gateway-server-dot-svc
  namespace: inspire
  resourceVersion: '1217085008'
  selfLink: /api/v1/namespaces/inspire/services/springboot-infinite-gateway-server-dot-svc
  uid: 15bc7d88-f13d-4930-9ec5-784883aed31d
spec:
  clusterIP: 172.21.1.212
  ports:
    - port: 8000
      protocol: TCP
      targetPort: 8000
  selector:
    app: springboot-infinite-gateway-server-dot
  sessionAffinity: None
  type: ClusterIP
status:
  loadBalancer: {}

selector
  app: 这个就是容器服务名称

再配置,路由创建,选择对应A服务,端口号


配置arms控制台和ahas
tomcat


网关
spec:
  progressDeadlineSeconds: 600
  replicas: 1
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      app: springboot-infinite-gateway-server-dot
  strategy:
    rollingUpdate:
      maxSurge: 25%
      maxUnavailable: 25%
    type: RollingUpdate
  template:
    metadata:
      annotations:
        ahasAppName: release-springboot-infinite-gateway-server-dot
        ahasPilotAutoEnable: 'on'
        armsPilotAutoEnable: 'on'
        armsPilotCreateAppName: release-springboot-infinite-gateway-server-dot
        redeploy-timestamp: '1608013032242'
      labels:
        app: springboot-infinite-gateway-server-dot

这块主要是设置ahas流量监控qps等等
      annotations:
        ahasAppName: release-springboot-infinite-gateway-server-dot
        ahasPilotAutoEnable: 'on'
        armsPilotAutoEnable: 'on'
        armsPilotCreateAppName: release-springboot-infinite-gateway-server-dot
        redeploy-timestamp: '1608013032242'

yaml文件
这块就是配置ahas的配置

配置域名
进入容器服务

找到
服务与路由
先创建服务

然后
路由创建
名称
springboot-infinite-dot-rest
域名
ali-test-getway-dot.XXXXXXXX.com
选择服务名称
端口8000

镜像拉取策略    IfNotPresent
环境变量    
LANG: C.UTF-8
LC_ALL: C.UTF-8
LANGUAGE: C.UTF-8
JAVA_OPTS: -Xmx12g -Xms12g -Xss512K -XX:MetaspaceSize=256m -XX:MaxMetaspaceSize=512m -XX:+EliminateAllocations -XX:+UseG1GC -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/data/logs/jvm/oom/springboot-infinite-dot-rest-business.hprof -XX:ErrorFile=/data/logs/jvm/springboot-infinite-dot-rest-business_hs_err_pid.log
SW_AGENT_NAME: springboot-infinite-dot-rest-business
DISCOVERY_ADDRESS: nacos-headless.middleware
DISCOVERY_NAMESPACE: ali-test
aliyun_logs_springboot-infinite-dot-rest-ali-test: /data/log/springboot-infinite-dot-rest/run.*.log*
所需资源    CPU: 8 Memory: 16Gi
资源限制    CPU: 8 Memory: 16Gi

 

 

如果本地,重启服务,输出localhost:8000

{"resultCode":0,"resultMsg":"OK","detailMsg":null,"resultData":"Hello, Gateway!"}

正常

 

以上内容会在优化和把下载地址链接也给到,方便大家下载就能稍微配置就可以使用,极简体验,谢谢指导!!!

你可能感兴趣的:(JAVA,java,服务器)