1. 前置要求

2. 部署流程

2.1 下载镜像

docker pull xuxueli/xxl-job-admin:2.3.1

2.2 初始化SQL

tables_xxl_job.sql

#
# XXL-JOB v2.4.0-SNAPSHOT
# Copyright (c) 2015-present, xuxueli.
 
CREATE database if NOT EXISTS `xxl_job` default character set utf8mb4 collate utf8mb4_unicode_ci;
use `xxl_job`;
 
SET NAMES utf8mb4;
 
CREATE TABLE `xxl_job_info` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `job_group` int(11) NOT NULL COMMENT '执行器主键ID',
  `job_desc` varchar(255) NOT NULL,
  `add_time` datetime DEFAULT NULL,
  `update_time` datetime DEFAULT NULL,
  `author` varchar(64) DEFAULT NULL COMMENT '作者',
  `alarm_email` varchar(255) DEFAULT NULL COMMENT '报警邮件',
  `schedule_type` varchar(50) NOT NULL DEFAULT 'NONE' COMMENT '调度类型',
  `schedule_conf` varchar(128) DEFAULT NULL COMMENT '调度配置,值含义取决于调度类型',
  `misfire_strategy` varchar(50) NOT NULL DEFAULT 'DO_NOTHING' COMMENT '调度过期策略',
  `executor_route_strategy` varchar(50) DEFAULT NULL COMMENT '执行器路由策略',
  `executor_handler` varchar(255) DEFAULT NULL COMMENT '执行器任务handler',
  `executor_param` varchar(512) DEFAULT NULL COMMENT '执行器任务参数',
  `executor_block_strategy` varchar(50) DEFAULT NULL COMMENT '阻塞处理策略',
  `executor_timeout` int(11) NOT NULL DEFAULT '0' COMMENT '任务执行超时时间,单位秒',
  `executor_fail_retry_count` int(11) NOT NULL DEFAULT '0' COMMENT '失败重试次数',
  `glue_type` varchar(50) NOT NULL COMMENT 'GLUE类型',
  `glue_source` mediumtext COMMENT 'GLUE源代码',
  `glue_remark` varchar(128) DEFAULT NULL COMMENT 'GLUE备注',
  `glue_updatetime` datetime DEFAULT NULL COMMENT 'GLUE更新时间',
  `child_jobid` varchar(255) DEFAULT NULL COMMENT '子任务ID,多个逗号分隔',
  `trigger_status` tinyint(4) NOT NULL DEFAULT '0' COMMENT '调度状态:0-停止,1-运行',
  `trigger_last_time` bigint(13) NOT NULL DEFAULT '0' COMMENT '上次调度时间',
  `trigger_next_time` bigint(13) NOT NULL DEFAULT '0' COMMENT '下次调度时间',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
 
CREATE TABLE `xxl_job_log` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `job_group` int(11) NOT NULL COMMENT '执行器主键ID',
  `job_id` int(11) NOT NULL COMMENT '任务,主键ID',
  `executor_address` varchar(255) DEFAULT NULL COMMENT '执行器地址,本次执行的地址',
  `executor_handler` varchar(255) DEFAULT NULL COMMENT '执行器任务handler',
  `executor_param` varchar(512) DEFAULT NULL COMMENT '执行器任务参数',
  `executor_sharding_param` varchar(20) DEFAULT NULL COMMENT '执行器任务分片参数,格式如 1/2',
  `executor_fail_retry_count` int(11) NOT NULL DEFAULT '0' COMMENT '失败重试次数',
  `trigger_time` datetime DEFAULT NULL COMMENT '调度-时间',
  `trigger_code` int(11) NOT NULL COMMENT '调度-结果',
  `trigger_msg` text COMMENT '调度-日志',
  `handle_time` datetime DEFAULT NULL COMMENT '执行-时间',
  `handle_code` int(11) NOT NULL COMMENT '执行-状态',
  `handle_msg` text COMMENT '执行-日志',
  `alarm_status` tinyint(4) NOT NULL DEFAULT '0' COMMENT '告警状态:0-默认、1-无需告警、2-告警成功、3-告警失败',
  PRIMARY KEY (`id`),
  KEY `I_trigger_time` (`trigger_time`),
  KEY `I_handle_code` (`handle_code`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
 
CREATE TABLE `xxl_job_log_report` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `trigger_day` datetime DEFAULT NULL COMMENT '调度-时间',
  `running_count` int(11) NOT NULL DEFAULT '0' COMMENT '运行中-日志数量',
  `suc_count` int(11) NOT NULL DEFAULT '0' COMMENT '执行成功-日志数量',
  `fail_count` int(11) NOT NULL DEFAULT '0' COMMENT '执行失败-日志数量',
  `update_time` datetime DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `i_trigger_day` (`trigger_day`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
 
CREATE TABLE `xxl_job_logglue` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `job_id` int(11) NOT NULL COMMENT '任务,主键ID',
  `glue_type` varchar(50) DEFAULT NULL COMMENT 'GLUE类型',
  `glue_source` mediumtext COMMENT 'GLUE源代码',
  `glue_remark` varchar(128) NOT NULL COMMENT 'GLUE备注',
  `add_time` datetime DEFAULT NULL,
  `update_time` datetime DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
 
CREATE TABLE `xxl_job_registry` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `registry_group` varchar(50) NOT NULL,
  `registry_key` varchar(255) NOT NULL,
  `registry_value` varchar(255) NOT NULL,
  `update_time` datetime DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `i_g_k_v` (`registry_group`,`registry_key`,`registry_value`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
 
CREATE TABLE `xxl_job_group` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `app_name` varchar(64) NOT NULL COMMENT '执行器AppName',
  `title` varchar(12) NOT NULL COMMENT '执行器名称',
  `address_type` tinyint(4) NOT NULL DEFAULT '0' COMMENT '执行器地址类型:0=自动注册、1=手动录入',
  `address_list` text COMMENT '执行器地址列表,多地址逗号分隔',
  `update_time` datetime DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
 
CREATE TABLE `xxl_job_user` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `username` varchar(50) NOT NULL COMMENT '账号',
  `password` varchar(50) NOT NULL COMMENT '密码',
  `role` tinyint(4) NOT NULL COMMENT '角色:0-普通用户、1-管理员',
  `permission` varchar(255) DEFAULT NULL COMMENT '权限:执行器ID列表,多个逗号分割',
  PRIMARY KEY (`id`),
  UNIQUE KEY `i_username` (`username`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
 
CREATE TABLE `xxl_job_lock` (
  `lock_name` varchar(50) NOT NULL COMMENT '锁名称',
  PRIMARY KEY (`lock_name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
 
INSERT INTO `xxl_job_group`(`id`, `app_name`, `title`, `address_type`, `address_list`, `update_time`) VALUES (1, 'xxl-job-executor-sample', '示例执行器', 0, NULL, '2018-11-03 22:21:31' );
INSERT INTO `xxl_job_info`(`id`, `job_group`, `job_desc`, `add_time`, `update_time`, `author`, `alarm_email`, `schedule_type`, `schedule_conf`, `misfire_strategy`, `executor_route_strategy`, `executor_handler`, `executor_param`, `executor_block_strategy`, `executor_timeout`, `executor_fail_retry_count`, `glue_type`, `glue_source`, `glue_remark`, `glue_updatetime`, `child_jobid`) VALUES (1, 1, '测试任务1', '2018-11-03 22:21:31', '2018-11-03 22:21:31', 'XXL', '', 'CRON', '0 0 0 * * ? *', 'DO_NOTHING', 'FIRST', 'demoJobHandler', '', 'SERIAL_EXECUTION', 0, 0, 'BEAN', '', 'GLUE代码初始化', '2018-11-03 22:21:31', '');
INSERT INTO `xxl_job_user`(`id`, `username`, `password`, `role`, `permission`) VALUES (1, 'admin', 'e10adc3949ba59abbe56e057f20f883e', 1, NULL);
INSERT INTO `xxl_job_lock` ( `lock_name`) VALUES ( 'schedule_lock');
 
commit;
 

2.3 配置文件

### web
server.port=8080
server.servlet.context-path=/xxl-job-admin
 
### actuator
management.server.servlet.context-path=/actuator
management.health.mail.enabled=false
 
### resources
spring.mvc.servlet.load-on-startup=0
spring.mvc.static-path-pattern=/static/**
spring.resources.static-locations=classpath:/static/
 
### freemarker
spring.freemarker.templateLoaderPath=classpath:/templates/
spring.freemarker.suffix=.ftl
spring.freemarker.charset=UTF-8
spring.freemarker.request-context-attribute=request
spring.freemarker.settings.number_format=0.##########
 
### mybatis
mybatis.mapper-locations=classpath:/mybatis-mapper/*Mapper.xml
#mybatis.type-aliases-package=com.xxl.job.admin.core.model
 
###更改配置文件连接mysql信息
### xxl-job, datasource
spring.datasource.url=jdbc:mysql://172.31.0.100:3306/xxl_job?characterEncoding=UTF-8&serverTimezone=UTC&useSSL=false&autoReconnect=true ###ip
spring.datasource.username=root
spring.datasource.password=123456
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
 
### datasource-pool
spring.datasource.type=com.zaxxer.hikari.HikariDataSource
spring.datasource.hikari.minimum-idle=10
spring.datasource.hikari.maximum-pool-size=30
spring.datasource.hikari.auto-commit=true
spring.datasource.hikari.idle-timeout=30000
spring.datasource.hikari.pool-name=HikariCP
spring.datasource.hikari.max-lifetime=900000
spring.datasource.hikari.connection-timeout=10000
spring.datasource.hikari.connection-test-query=SELECT 1
spring.datasource.hikari.validation-timeout=1000
 
### xxl-job, email
spring.mail.host=smtp.qq.com
spring.mail.port=25
spring.mail.username=xxx@qq.com
spring.mail.from=xxx@qq.com
spring.mail.password=xxx
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.starttls.required=true
spring.mail.properties.mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFactory
 
### xxl-job, access token
xxl.job.accessToken=default_token
 
### xxl-job, i18n (default is zh_CN, and you can choose "zh_CN", "zh_TC" and "en")
xxl.job.i18n=zh_CN
 
## xxl-job, triggerpool max size
xxl.job.triggerpool.fast.max=200
xxl.job.triggerpool.slow.max=100
 
### xxl-job, log retention days
xxl.job.logretentiondays=30

2.3 运行容器

docker run -d --name xxl-job-admin \
  -v /app/xxljob/application.properties:/application.properties \
  -v /data/applogs:/data/applogs \
  -p 8080:8080 \
  -e PARAMS='--spring.config.location=/application.properties' \
  xuxueli/xxl-job-admin:2.3.1

3. 后端代码

自行forck代码,注意要修改代码里面的application.properties中的xxl.job.admin.addresses并且到xxljob中创建执行器job-demo

https://gitee.com/tanqidi/xxljob-demo
spring.application.name=xxljob-demo
server.port=8080

# 调度中心服务部署的地址
xxl.job.admin.addresses=http://xxljob.default.svc.cluster.local:8080/xxl-job-admin
# 执行器通讯TOKEN,要和调度中心服务部署配置的accessToken一致,要不然无法连接注册
xxl.job.accessToken=
# 执行器AppName
xxl.job.executor.appname=job-demo
# 执行器注册 [选填]:优先使用该配置作为注册地址,为空时使用内嵌服务 ”IP:PORT“ 作为注册地址。从而更灵活的支持容器类型执行器动态IP和动态映射端口问题。
xxl.job.executor.address=
# 执行器IP
xxl.job.executor.ip=
# 执行器端口号:小于等于0则自动获取;默认端口为9999,单机部署多个执行器时,注意要配置不同执行器端口;
xxl.job.executor.port=9999
# 执行器运行日志文件存储磁盘路径 [选填] :需要对该路径拥有读写权限;为空则使用默认路径;
xxl.job.executor.logpath=
# 执行器日志文件保存天数 [选填] : 过期日志自动清理, 限制值大于等于3时生效; 否则, 如-1, 关闭自动清理功能;
xxl.job.executor.logretentiondays=30

3.1 kubesphere devops

pipeline {
  agent {
    node {
      label 'jdk21-maven3.9.9'
    }

  }
  stages {
    stage('编译信息') {
      agent none
      steps {
        script {
          env.FULL_VERSION_NUMBER="${params.INPUT_VERSION_NUMBER}"
        }

        sh 'echo "当前分支:${FULL_VERSION_NUMBER}"'
      }
    }

    stage('拉取项目') {
      agent none
      steps {
        container('maven') {
          git(credentialsId: 'gitee-secret', branch: FULL_VERSION_NUMBER, url: 'https://gitee.com/tanqidi/xxljob-demo.git', changelog: true, poll: false)
        }

      }
    }

    stage('项目编译') {
      agent none
      steps {
        container('maven') {
          sh 'mvn -Dmaven.test.skip=true clean package'
        }

      }
    }

    stage('打包镜像') {
      agent none
      steps {
        container('maven') {
          sh 'docker build -f Dockerfile -t ${REGISTRY}/${HARBOR_NAMESPACE}/${PROJECT_NAME}:${FULL_VERSION_NUMBER}.${BUILD_NUMBER} .'
        }

      }
    }

    stage('镜像推送') {
      agent none
      steps {
        container('maven') {
          withCredentials([usernamePassword(credentialsId : 'aliyun-harbor-secret' ,passwordVariable : 'name' ,usernameVariable : 'passwd' ,)]) {
            sh 'echo "$name" | docker login $REGISTRY -u "$passwd" --password-stdin'
            sh 'docker push ${REGISTRY}/${HARBOR_NAMESPACE}/${PROJECT_NAME}:${FULL_VERSION_NUMBER}.${BUILD_NUMBER}'
          }

        }

      }
    }

    stage('部署到UAT环境') {
      agent none
      steps {
        container('maven') {
          withCredentials([kubeconfigFile(credentialsId: "$KUBECONFIG_CREDENTIAL_ID", variable: 'KUBECONFIG')]) {
            script {
              sh "echo \'${DEPLOY_YAML}\' > deploy.yaml"
              sh "cat deploy.yaml"
              sh "envsubst < deploy.yaml | kubectl apply -f -"
            }

          }

        }

      }
    }

  }
  environment {
    KUBECONFIG_CREDENTIAL_ID = 'k8s-kubeconfig'
    REGISTRY = 'registry.cn-hangzhou.aliyuncs.com'
    HARBOR_NAMESPACE = 'tanqidi-temp'
    PROJECT_NAME = 'xxljob-demo'
    PROJECT_PORT = '8080'
    PROJECT_NAMESPACE = 'default'
    DEPLOY_YAML = '''

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: ${PROJECT_NAME}
  name: ${PROJECT_NAME}
  namespace: ${PROJECT_NAMESPACE}
spec:
  replicas: 1
  selector:
    matchLabels:
      app: ${PROJECT_NAME}
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: 25%
      maxSurge: 25%
  revisionHistoryLimit: 10
  progressDeadlineSeconds: 600

  template:
    metadata:
      labels:
        app: ${PROJECT_NAME}
    spec:
      imagePullSecrets:
        - name: harbor
      containers:
        - name: ${PROJECT_NAME}
          imagePullPolicy: Always
          image: ${REGISTRY}/${HARBOR_NAMESPACE}/${PROJECT_NAME}:${FULL_VERSION_NUMBER}.${BUILD_NUMBER}
          ports:
            - containerPort: ${PROJECT_PORT}
              protocol: TCP
          resources:
            limits:
              cpu: \'1\'
              memory: 2Gi
            requests:
              cpu: 25m
              memory: 850Mi
      restartPolicy: Always
      terminationGracePeriodSeconds: 30
---
apiVersion: v1
kind: Service
metadata:
  name: ${PROJECT_NAME}
  namespace: ${PROJECT_NAMESPACE}
  labels:
    app: ${PROJECT_NAME}
spec:
  ports:
    - port: ${PROJECT_PORT}
      targetPort: ${PROJECT_PORT}
  selector:
    app: ${PROJECT_NAME}
  type: ClusterIP
  sessionAffinity: None

'''
  }
  parameters {
    string(name: 'INPUT_VERSION_NUMBER', defaultValue: '', description: '请输入分支的版本,如:release-1.3.20220531')
  }
}

image-qwks.png

3.2 xxl-job 配置

根据application.properties中的 xxl.job.executor.appname=job-demo 创建出执行器,并且为自动注册

image-qelm.png
任务管理选择为job-demo,新增一个名为demoJobHandler的任务,cron随便填,可以是:*/1 * * * * ?

image-qcwl.png

跑完流水线启动完程序不出意外可以看到顺利自动注册上来了。

image-jduv.png

到任务管理中,手动执行一次demoJobHandler任务,可以看到一切都按照预期完成了工作。

image-pzgd.png

image-lwjb.png

4. 版本升级

XXL-JOB 从 2.1.2 升级到 2.3.1 的 SQL 字段补全内容

ALTER TABLE `xxl-job`.`xxl_job_info` ADD COLUMN `schedule_type` varchar(50)  NOT NULL DEFAULT 'NONE' COMMENT '调度类型' AFTER `alarm_email`;
ALTER TABLE `xxl-job`.`xxl_job_info` ADD COLUMN `schedule_conf` varchar(128)  NULL DEFAULT NULL COMMENT '调度配置,值含义取决于调度类型' AFTER `schedule_type`;
ALTER TABLE `xxl-job`.`xxl_job_info` ADD COLUMN `misfire_strategy` varchar(50)  NOT NULL DEFAULT 'DO_NOTHING' COMMENT '调度过期策略' AFTER `schedule_conf`;
ALTER TABLE `xxl-job`.`xxl_job_log_report` ADD COLUMN `update_time` datetime NULL DEFAULT NULL AFTER `fail_count`;

5. kubernetes

5.1 configmap

kind: ConfigMap
apiVersion: v1
metadata:
  name: xxljob-jdk21-config
  namespace: default
  annotations:
    kubesphere.io/creator: tanqidi
data:
  application.properties: >-
    ### web
    server.port=8080
    server.servlet.context-path=/xxl-job-admin
     
    ### actuator
    management.server.servlet.context-path=/actuator
    management.health.mail.enabled=false
     
    ### resources
    spring.mvc.servlet.load-on-startup=0
    spring.mvc.static-path-pattern=/static/**
    spring.resources.static-locations=classpath:/static/
     
    ### freemarker
    spring.freemarker.templateLoaderPath=classpath:/templates/
    spring.freemarker.suffix=.ftl
    spring.freemarker.charset=UTF-8
    spring.freemarker.request-context-attribute=request
    spring.freemarker.settings.number_format=0.##########
     
    ### mybatis
    mybatis.mapper-locations=classpath:/mybatis-mapper/*Mapper.xml
    #mybatis.type-aliases-package=com.xxl.job.admin.core.model
     
    ###更改配置文件连接mysql信息
    ### xxl-job, datasource
    spring.datasource.url=jdbc:mysql://172.31.0.100:3306/xxl_job:3306/xxl-job?characterEncoding=UTF-8&serverTimezone=UTC&useSSL=false&autoReconnect=true
    ###ip
    spring.datasource.username=root
    spring.datasource.password=123456
    spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
     
    ### datasource-pool
    spring.datasource.type=com.zaxxer.hikari.HikariDataSource
    spring.datasource.hikari.minimum-idle=10
    spring.datasource.hikari.maximum-pool-size=30
    spring.datasource.hikari.auto-commit=true
    spring.datasource.hikari.idle-timeout=30000
    spring.datasource.hikari.pool-name=HikariCP
    spring.datasource.hikari.max-lifetime=900000
    spring.datasource.hikari.connection-timeout=10000
    spring.datasource.hikari.connection-test-query=SELECT 1
    spring.datasource.hikari.validation-timeout=1000
     
    ### xxl-job, email
    spring.mail.host=smtp.qq.com
    spring.mail.port=25
    spring.mail.username=xxx@qq.com
    spring.mail.from=xxx@qq.com
    spring.mail.password=xxx
    spring.mail.properties.mail.smtp.auth=true
    spring.mail.properties.mail.smtp.starttls.enable=true
    spring.mail.properties.mail.smtp.starttls.required=true
    spring.mail.properties.mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFactory
     
    ### xxl-job, access token
    xxl.job.accessToken=
     
    ### xxl-job, i18n (default is zh_CN, and you can choose "zh_CN", "zh_TC" and
    "en")
    xxl.job.i18n=zh_CN
     
    ## xxl-job, triggerpool max size
    xxl.job.triggerpool.fast.max=200
    xxl.job.triggerpool.slow.max=100
     
    ### xxl-job, log retention days
    xxl.job.logretentiondays=30

5.2 service

以nodeport方式试验访问,路径是:http://xxx.xxx.xxx.xxx:30990/xxl-job-admin/toLogin

kind: Service
apiVersion: v1
metadata:
  name: xxljob
  namespace: default
  labels:
    app: xxljob
  annotations:
    kubesphere.io/creator: admin
spec:
  ports:
    - name: http-8080
      protocol: TCP
      port: 8080
      targetPort: 8080
      nodePort: 30990
  selector:
    app: xxljob
  type: NodePort
  sessionAffinity: None
  externalTrafficPolicy: Cluster
  ipFamilies:
    - IPv4
  ipFamilyPolicy: SingleStack
  internalTrafficPolicy: Cluster

5.3 deployment

kind: Deployment
apiVersion: apps/v1
metadata:
  name: xxljob
  namespace: default
  annotations:
    deployment.kubernetes.io/revision: '3'
    kubesphere.io/creator: tanqidi
spec:
  replicas: 1
  selector:
    matchLabels:
      app: xxljob
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: xxljob
      annotations:
        kubesphere.io/restartedAt: '2025-03-21T08:32:56.000Z'
    spec:
      volumes:
        - name: host-time
          hostPath:
            path: /etc/localtime
            type: ''
        - name: conf
          configMap:
            name: xxljob-jdk21-config
            defaultMode: 420
      containers:
        - name: xxljob
          image: 'xuxueli/xxl-job-admin:2.3.1'
          command:
            - /bin/sh
            - '-c'
            - >
              java -server -Xms4096M -Xmx4096M  -XX:+PrintGC -XX:+PrintGCDetails
              -XX:+PrintGCTimeStamps -Xloggc:/data/jvm.log
              -XX:+HeapDumpOnOutOfMemoryError
              -XX:HeapDumpPath=/data/heapdump.bin -Xdebug
              -Xrunjdwp:transport=dt_socket,server=y,suspend=n 
              -Djava.security.egd=file:/dev/./urandom -jar /app.jar
              --spring.config.location=/app/application.properties
          ports:
            - name: client
              containerPort: 8080
              protocol: TCP
          env:
            - name: LANG
              value: en_US.UTF-8
          resources:
            limits:
              cpu: '4'
              memory: 6Gi
            requests:
              cpu: 200m
              memory: 4Gi
          volumeMounts:
            - name: host-time
              readOnly: true
              mountPath: /etc/localtime
            - name: conf
              mountPath: /app/application.properties
              subPath: application.properties
          livenessProbe:
            httpGet:
              path: /xxl-job-admin/actuator/health
              port: 8080
              scheme: HTTP
            timeoutSeconds: 2
            periodSeconds: 10
            successThreshold: 1
            failureThreshold: 6
          readinessProbe:
            httpGet:
              path: /xxl-job-admin/actuator/health
              port: 8080
              scheme: HTTP
            timeoutSeconds: 2
            periodSeconds: 5
            successThreshold: 1
            failureThreshold: 3
          startupProbe:
            httpGet:
              path: /xxl-job-admin/actuator/health
              port: 8080
              scheme: HTTP
            initialDelaySeconds: 100
            timeoutSeconds: 2
            periodSeconds: 5
            successThreshold: 1
            failureThreshold: 40
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
          imagePullPolicy: IfNotPresent
      restartPolicy: Always
      terminationGracePeriodSeconds: 30
      dnsPolicy: ClusterFirst
      securityContext: {}
      schedulerName: default-scheduler
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: 25%
      maxSurge: 25%
  revisionHistoryLimit: 10
  progressDeadlineSeconds: 600

5.4 ingress

kind: Ingress
apiVersion: networking.k8s.io/v1
metadata:
  name: xxljob-dashborad
  namespace: default
  annotations:
    kubernetes.io/ingress.class: nginx
    kubesphere.io/alias-name: xxljob管理
    kubesphere.io/creator: admin
    nginx.ingress.kubernetes.io/proxy-redirect-from: 'http://'
    nginx.ingress.kubernetes.io/proxy-redirect-to: '$scheme://'
    nginx.ingress.kubernetes.io/server-snippet: 'rewrite ^/$ http://xxljob.uat.tanqidi.com/xxl-job-admin permanent;'
    nginx.ingress.kubernetes.io/upstream-hash-by: $binary_remote_addr
spec:
  tls:
    - hosts:
        - xxljob.uat.tanqidi.com
      secretName: tanqidi-uat-ssl
  rules:
    - host: xxljob.uat.tanqidi.com
      http:
        paths:
          - path: /
            pathType: ImplementationSpecific
            backend:
              service:
                name: xxljob
                port:
                  number: 8080

5. 常见异常

能顺利启动xxljob,但是服务却一直无法注册,响应的错误内容是一大串html内容 response content invalid(<!DOCTYPE html>...... 你必须要认真检查一下application.properties的配置项,以下写法会导致此错误

正确:server.servlet.context-path =/xxl-job-admin

错误:server.context-path = /xxl-job-admin

57cff3f6-ed4b-43d0-9568-20301c6ac0a9.jpeg

16:32:56,938 ERROR co.xx.jo.co.ut.XxlJobRemotingUtil.postBody 118 [xxl-job, executor ExecutorRegistryThread] xxl-job remoting (url=http://xxljob.bx.svc.cluster.local:8080/xxl-job-admin/api/registry) response content invalid(<!DOCTYPE html><html><head> <link rel="icon" href="/static/favicon.ico" /> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <!-- Tell the browser to be responsive to screen width --> <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport"> <!-- Bootstrap --> <link rel="stylesheet" href="/static/adminlte/bower_components/bootstrap/css/bootstrap.min.css">。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。

com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $

at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:397) ~[gson-2.10.1.jar!/:?]

at com.google.gson.Gson.fromJson(Gson.java:1227) ~[gson-2.10.1.jar!/:?]

at com.google.gson.Gson.fromJson(Gson.java:1137) ~[gson-2.10.1.jar!/:?]

at com.google.gson.Gson.fromJson(Gson.java:1047) ~[gson-2.10.1.jar!/:?]

at com.google.gson.Gson.fromJson(Gson.java:1014) ~[gson-2.10.1.jar!/:?]

at com.xxl.job.core.util.GsonTool.fromJson(GsonTool.java:52) ~[xxl-job-core-2.3.1.jar!/:?]

at com.xxl.job.core.util.XxlJobRemotingUtil.postBody(XxlJobRemotingUtil.java:114) ~[user-center-biz-2.0.20250310.jar!/:?]

at com.xxl.job.core.biz.client.AdminBizClient.registry(AdminBizClient.java:42) ~[xxl-job-core-2.3.1.jar!/:?]

at com.xxl.job.core.thread.ExecutorRegistryThread$1.run(ExecutorRegistryThread.java:48) ~[xxl-job-core-2.3.1.jar!/:?]

at java.lang.Thread.run(Thread.java:1583) [?:?]

Caused by: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $

at com.google.gson.stream.JsonReader.beginObject(JsonReader.java:393) ~[gson-2.10.1.jar!/:?]

at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:386) ~[gson-2.10.1.jar!/:?]

... 9 more