介绍
XXL-JOB 官方文档:
- https://www.xuxueli.com/xxl-job/
- https://www.xuxueli.com/xxl-job/#%E4%BA%8C%E3%80%81%E5%BF%AB%E9%80%9F%E5%85%A5%E9%97%A8
xxl-job源码的github地址:
xxl-job-admin的官方docker镜像主页地址:
xxl-job-admin的官方docker镜像各个版本清单地址:
xxl-job的docker启动命令及参数:
docker run -p 8080:8080 -v /tmp:/data/applogs --name xxl-job-admin -d xuxueli/xxl-job-admin:{指定版本}
- 如需自定义 mysql 等配置,可通过 “-e PARAMS” 指定,参数格式 PARAMS=“–key=value --key2=value2” ;
- 配置项参考文件:/xxl-job/xxl-job-admin/src/main/resources/application.properties
- 如需自定义 JVM内存参数 等配置,可通过 “-e JAVA_OPTS” 指定,参数格式 JAVA_OPTS=“-Xmx512m” ;
docker run -e PARAMS="--spring.datasource.url=jdbc:mysql://127.0.0.1:3306/xxl_job?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&serverTimezone=Asia/Shanghai" -p 8080:8080 -v /tmp:/data/applogs --name xxl-job-admin -d xuxueli/xxl-job-admin:{指定版本}
关注-e PARAMS= 部分,后面编写k8s的yaml文件要用到
执行xxl-job-admin的建库脚本
- 请将以上sql文件手动导入mysql数据库
创建 ConfigMap
创建 ConfigMap 配置
vim xxl-job-admin-env-configmap.yaml
---
apiVersion: v1
kind: ConfigMap
metadata:
name: xxl-job-admin-env-configmap
data:
# https://github.com/xuxueli/xxl-job/blob/master/xxl-job-admin/src/main/resources/application.properties
PARAMS: >-
--spring.datasource.url=jdbc:mysql://127.0.0.1:3306/xxl_job?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&serverTimezone=Asia/Shanghai
--spring.datasource.username=root
--spring.datasource.password=root_pwd
--server.servlet.context-path=/xxl-job-admin
--xxl.job.i18n=zh_CN
--xxl.job.triggerpool.fast.max=500
--xxl.job.triggerpool.slow.max=200
--xxl.job.logretentiondays=30
注:上下文路径默认是 /xxl-job-admin ,根据需求看看是否要修改,我这里指定为根路径。
kubectl apply -f xxl-job-admin-env-configmap.yaml -n xxl-job
调度中心配置内容说明:
### 调度中心JDBC链接:链接地址请保持和 2.1章节 所创建的调度数据库的地址一致
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/xxl_job?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&serverTimezone=Asia/Shanghai
spring.datasource.username=root
spring.datasource.password=root_pwd
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
### 报警邮箱
spring.mail.host=smtp.qq.com
spring.mail.port=25
spring.mail.username=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
### 调度中心通讯TOKEN [选填]:非空时启用;
xxl.job.accessToken=
### 调度中心国际化配置 [必填]: 默认为 "zh_CN"/中文简体, 可选范围为 "zh_CN"/中文简体, "zh_TC"/中文繁体 and "en"/英文;
xxl.job.i18n=zh_CN
## 调度线程池最大线程配置【必填】
xxl.job.triggerpool.fast.max=200
xxl.job.triggerpool.slow.max=100
### 调度中心日志表数据保存天数 [必填]:过期日志自动清理;限制大于等于7时生效,否则, 如-1,关闭自动清理功能;
xxl.job.logretentiondays=30
部署xxl-job-admin
编写deployment 配置文件
vim xxl-job-admin-test4-deployment.yaml
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: xxl-job-admin
spec:
replicas: 2
selector:
matchLabels:
app: xxl-job-admin
template:
metadata:
labels:
app: xxl-job-admin
spec:
containers:
- name: xxl-job-admin
image: xuxueli/xxl-job-admin:2.4.1
imagePullPolicy: Always # 优先使用本地镜像
ports:
- containerPort: 8080
# env:
# - name: PARAMS
# value: "--spring.datasource.url=jdbc:mysql://127.0.0.1:3306/xxl_job?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&serverTimezone=Asia/Shanghai"
env:
- name: PARAMS
valueFrom:
configMapKeyRef:
name: xxl-job-admin-env-configmap
key: PARAMS
# envFrom:
# - configMapRef:
# name: xxl-job-admin-env-configmap
---
apiVersion: v1
kind: Service
metadata:
name: xxl-job-admin
labels:
app: xxl-job-admin
spec:
type: ClusterIP
ports:
- port: 8080
targetPort: 8080
nodePort: 31528
selector:
app: xxl-job-admin
服务部署
kubectl apply -f xxl-job-admin-test4-deployment.yaml -n xxl-job
检查服务状态
# kubectl get all -n xxl-job
NAME READY STATUS RESTARTS AGE
pod/xxl-job-admin-test4-7bccb75fd6-lrr4l 1/1 Running 0 32m
pod/xxl-job-admin-test4-7bccb75fd6-zlsbk 1/1 Running 0 32m
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/xxl-job-admin-test4 ClusterIP 10.247.103.195 <none> 8080/TCP 77m
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/xxl-job-admin-test4 2/2 2 2 77m
配置web访问
配置Ingress
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: "ingress-xxl-job-admin"
namespace: "xxl-job"
annotations:
nginx.ingress.kubernetes.io/connection-proxy-header: ""
nginx.ingress.kubernetes.io/keep-alive: "650"
nginx.ingress.kubernetes.io/keep-alive-requests: "10000"
nginx.ingress.kubernetes.io/proxy-body-size: 1000M
nginx.ingress.kubernetes.io/proxy-buffering: "off"
nginx.ingress.kubernetes.io/proxy-connect-timeout: "7200"
nginx.ingress.kubernetes.io/proxy-http-version: "1.1"
nginx.ingress.kubernetes.io/proxy-next-upstream: error timeout invalid_header http_500 http_502 http_503 http_504
nginx.ingress.kubernetes.io/proxy-read-timeout: "7200"
nginx.ingress.kubernetes.io/proxy-send-timeout: "7200"
nginx.ingress.kubernetes.io/proxy-tcp-nodelay: "on"
nginx.ingress.kubernetes.io/proxy-tcp-nopush: "off"
nginx.ingress.kubernetes.io/proxy-request-buffering: "off"
nginx.ingress.kubernetes.io/configuration-snippet: |
rewrite ^/$ /xxl-job-admin/ permanent;
more_set_headers "Expires: -1";
spec:
ingressClassName: nginx-ingress
rules:
- host: "xxl-job.qsh.com"
http:
paths:
- path: /xxl-job-admin
backend:
service:
name: xxl-job-admin
port:
number: 8080
pathType: Prefix
调度中心访问地址:http://xxl-job.qsh.com/xxl-job-admin (该地址执行器将会使用到,作为回调地址)
默认登录账号 “admin/123456”, 登录后运行界面如下图所示。