• Kubernetes v1.21.5部署xxl-job 2.3.1


    目录

    1、软件版本

    2、制作xxl-job-admin的docker镜像

               Dockerfile:

               执行命令:

    3、部署xxl-job

    3.0、创建MySQL的xxl-job数据库,导入SQL脚本

    3.1、xxl-job-admin的rabc.yaml

    3.2、xxl-job-admin的config-map.yaml

    3.3、xxl-job-admin的deployment.yaml

    3.4、xxl-job-admin的service.yaml

    3.5、容器启动日志

    3.6、访问xxl-job-admin

    4、部署executor执行器

     4.1、Dockerfile:xxl-job-executor-sample-springboot

    构建镜像:

     4.2、部署xxl-job-executor-sample-springboot的pod

              4.3、部署xxl-job-executor-sample-springboot的服务

    xxl-job-executor-sample-springboot启动日志

     4.4、xxl-job-admin页面新建执行器

    自定义添加执行器在数据库的保存

    等待一会儿,自动注册方式,Online的机器地址会显示出来 

    5、执行测试

    5.1、任务管理新建任务

    5.2、运行模式GLUE(Java),编辑内容

    5.3、在容器中查看运行日志

    5.4、xxl-job-admin调度日志

    附录:


    1、软件版本

    Kubernetesv1.21.5
    kubespherev3.2.1
    xxl-jobv2.3.1
    mysql5.7
    xxl-job官网
     
    分布式任务调度平台XXL-JOB (xuxueli.com)

    2、制作xxl-job-admin的docker镜像

    Dockerfile:

    1. FROM java:8
    2. MAINTAINER demo
    3. RUN mkdir -p /app/config/
    4. ENV MYPATH /app
    5. WORKDIR $MYPATH
    6. ENV PARAMS="--spring.config.location=file:/app/config/application.properties"
    7. ENV TZ=PRC
    8. RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
    9. ADD target/xxl-job-admin-*.jar app.jar
    10. EXPOSE 8080
    11. EXPOSE 6666
    12. EXPOSE 9999
    13. ENTRYPOINT ["sh","-c","java -jar $JAVA_OPTS -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=6666 app.jar $PARAMS"]

    执行命令:

    1. docker build -t zhxl1989/xxl-job:2.3.1 .
    2. docker push zhxl1989/xxl-job:2.3.1

    3、部署xxl-job

    3.0、创建MySQL的xxl-job数据库,导入SQL脚本

    3.1、xxl-job-admin的rabc.yaml

    1. apiVersion: v1
    2. kind: ServiceAccount
    3. metadata:
    4. name: xxl-job
    5. namespace: default
    6. ---
    7. apiVersion: rbac.authorization.k8s.io/v1
    8. kind: RoleBinding
    9. metadata:
    10. name: xxl-job
    11. namespace: default
    12. roleRef:
    13. apiGroup: rbac.authorization.k8s.io
    14. kind: Role
    15. name: xxl-job
    16. subjects:
    17. - kind: ServiceAccount
    18. name: xxl-job
    19. namespace: default
    20. ---
    21. kind: Role
    22. apiVersion: rbac.authorization.k8s.io/v1
    23. metadata:
    24. namespace: default
    25. name: xxl-job
    26. rules:
    27. - apiGroups: [""]
    28. resources: ["pods"]
    29. verbs: ["get", "watch", "list"]

    3.2、xxl-job-admin的config-map.yaml

    1. apiVersion: v1
    2. kind: ConfigMap
    3. metadata:
    4. name: xxl-job-config
    5. namespace: default
    6. data:
    7. application.properties: |
    8. ### web
    9. server.port=${server.port}
    10. server.servlet.context-path=${server.servlet.context-path}
    11. ### actuator
    12. management.server.servlet.context-path=/actuator
    13. management.health.mail.enabled=false
    14. ### resources
    15. spring.mvc.servlet.load-on-startup=0
    16. spring.mvc.static-path-pattern=/static/**
    17. spring.resources.static-locations=classpath:/static/
    18. ### freemarker
    19. spring.freemarker.templateLoaderPath=classpath:/templates/
    20. spring.freemarker.suffix=.ftl
    21. spring.freemarker.charset=UTF-8
    22. spring.freemarker.request-context-attribute=request
    23. spring.freemarker.settings.number_format=0.##########
    24. ### mybatis
    25. mybatis.mapper-locations=classpath:/mybatis-mapper/*Mapper.xml
    26. #mybatis.type-aliases-package=com.xxl.job.admin.core.model
    27. ### xxl-job, datasource
    28. spring.datasource.url=${datasource.url}
    29. spring.datasource.username=${datasource.username}
    30. spring.datasource.password=${datasource.password}
    31. spring.datasource.driver-class-name=${datasource.driver.class.name}
    32. ### datasource-pool
    33. spring.datasource.type=com.zaxxer.hikari.HikariDataSource
    34. spring.datasource.hikari.minimum-idle=10
    35. spring.datasource.hikari.maximum-pool-size=30
    36. spring.datasource.hikari.auto-commit=true
    37. spring.datasource.hikari.idle-timeout=30000
    38. spring.datasource.hikari.pool-name=HikariCP
    39. spring.datasource.hikari.max-lifetime=900000
    40. spring.datasource.hikari.connection-timeout=10000
    41. spring.datasource.hikari.connection-test-query=SELECT 1
    42. spring.datasource.hikari.validation-timeout=1000
    43. ### xxl-job, email
    44. spring.mail.host=${mail.host}
    45. spring.mail.port=${mail.port}
    46. spring.mail.username=${mail.username}
    47. spring.mail.from=${mail.username}
    48. spring.mail.password=${mail.password}
    49. spring.mail.properties.mail.smtp.auth=${mail.properties.mail.smtp.auth}
    50. spring.mail.properties.mail.smtp.starttls.enable=${mail.properties.mail.smtp.starttls.enable}
    51. spring.mail.properties.mail.smtp.starttls.required=${mail.properties.mail.smtp.starttls.required}
    52. spring.mail.properties.mail.smtp.socketFactory.class=${mail.properties.mail.smtp.socketFactory.class}
    53. ### xxl-job, access token
    54. xxl.job.accessToken=default_token
    55. ### xxl-job, i18n (default is zh_CN, and you can choose "zh_CN", "zh_TC" and "en")
    56. xxl.job.i18n=${i18n}
    57. ## xxl-job, triggerpool max size
    58. xxl.job.triggerpool.fast.max=${fast}
    59. xxl.job.triggerpool.slow.max=${slow}
    60. ### xxl-job, log retention days
    61. xxl.job.logretentiondays=${logretentiondays}

    3.3、xxl-job-admin的deployment.yaml

    1. apiVersion: apps/v1
    2. kind: Deployment
    3. metadata:
    4. name: xxl-job
    5. namespace: default
    6. spec:
    7. replicas: 1
    8. selector:
    9. matchLabels:
    10. app: xxl-job
    11. strategy:
    12. type: RollingUpdate
    13. rollingUpdate:
    14. maxUnavailable: 25%
    15. maxSurge: 25%
    16. revisionHistoryLimit: 10
    17. progressDeadlineSeconds: 600
    18. template:
    19. metadata:
    20. labels:
    21. app: xxl-job
    22. release: default
    23. spec:
    24. restartPolicy: Always
    25. terminationGracePeriodSeconds: 30
    26. dnsPolicy: ClusterFirst
    27. serviceAccountName: xxl-job
    28. serviceAccount: xxl-job
    29. securityContext: {}
    30. schedulerName: default-scheduler
    31. containers:
    32. - name: xxl-job
    33. image: zhxl1989/xxl-job:2.3.1
    34. imagePullPolicy: Always
    35. ports:
    36. - containerPort: 8080
    37. name: http
    38. - containerPort: 6666
    39. name: transport
    40. - containerPort: 9999
    41. name: executor
    42. resources:
    43. limits:
    44. cpu: '1'
    45. memory: 2Gi
    46. #nvidia.com/gpu: 4k
    47. requests:
    48. cpu: 500m
    49. memory: 1Gi
    50. #nvidia.com/gpu: 4k
    51. env:
    52. - name: server.port
    53. value: "8080"
    54. - name: server.servlet.context-path
    55. value: "/xxl-job-admin"
    56. - name: datasource.url
    57. value: "jdbc:mysql://mysql.shenyu.svc.cluster.local:3306/xxl_job?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&serverTimezone=Asia/Shanghai"
    58. - name: datasource.username
    59. value: "root"
    60. - name: datasource.password
    61. value: "123456"
    62. - name: datasource.driver.class.name
    63. value: "com.mysql.cj.jdbc.Driver"
    64. - name: mail.host
    65. value: "smtp.qq.com"
    66. - name: mail.port
    67. value: "25"
    68. - name: mail.username
    69. value: "1024122298@qq.com"
    70. - name: mail.password
    71. value: "thomsesuwwfcf19jcnwrddi"
    72. - name: mail.properties.mail.smtp.auth
    73. value: "true"
    74. - name: mail.properties.mail.smtp.starttls.enable
    75. value: "true"
    76. - name: mail.properties.mail.smtp.starttls.required
    77. value: "true"
    78. - name: mail.properties.mail.smtp.socketFactory.class
    79. value: "javax.net.ssl.SSLSocketFactory"
    80. - name: i18n
    81. value: "zh_CN"
    82. - name: fast
    83. value: "200"
    84. - name: slow
    85. value: "100"
    86. - name: logretentiondays
    87. value: "30"
    88. - name: real_host
    89. valueFrom:
    90. fieldRef:
    91. fieldPath: status.podIP
    92. volumeMounts:
    93. - mountPath: /etc/localtime
    94. name: volume-localtime
    95. - name: config
    96. mountPath: /app/config/application.properties
    97. #对应面下面的path,保持一致
    98. subPath: application.properties
    99. terminationMessagePath: /dev/termination-log
    100. terminationMessagePolicy: File
    101. volumes:
    102. - hostPath:
    103. path: /etc/localtime
    104. type: ''
    105. name: volume-localtime
    106. - name: config
    107. configMap:
    108. #对应config-map的名称
    109. name: xxl-job-config
    110. items:
    111. - key: application.properties
    112. #对应上面的subPath,保持一致
    113. path: application.properties

    3.4、xxl-job-admin的service.yaml

    1. apiVersion: v1
    2. kind: Service
    3. metadata:
    4. name: xxl-job
    5. namespace: default
    6. labels:
    7. service: xxl-job
    8. spec:
    9. sessionAffinity: "ClientIP"
    10. ports:
    11. - name: transport
    12. port: 6666
    13. protocol: TCP
    14. targetPort: 6666
    15. nodePort: 30666
    16. - name: http
    17. port: 8080
    18. protocol: TCP
    19. targetPort: 8080
    20. nodePort: 30888
    21. - name: executor
    22. port: 9999
    23. protocol: TCP
    24. targetPort: 9999
    25. nodePort: 31999
    26. selector:
    27. app: xxl-job
    28. type: NodePort

    3.5、容器启动日志

    3.6、访问xxl-job-admin

    任务调度中心

    4、部署executor执行器

    4.1、Dockerfile:xxl-job-executor-sample-springboot

    1. FROM java:8
    2. MAINTAINER demo
    3. RUN mkdir -p /data/applogs/xxl-job/jobhandler
    4. ENV MYPATH /
    5. WORKDIR $MYPATH
    6. ENV PARAMS=""
    7. ENV TZ=PRC
    8. RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
    9. ADD target/xxl-job-executor-sample-springboot-*.jar /app.jar
    10. EXPOSE 8081
    11. EXPOSE 9999
    12. ENTRYPOINT ["sh","-c","java -jar $JAVA_OPTS /app.jar $PARAMS"]

    构建镜像:

    1. docker build -t zhxl1989/xxl-job-executor-sample-springboot:2.3.1 .
    2. docker push zhxl1989/xxl-job-executor-sample-springboot:2.3.1

    4.2、部署xxl-job-executor-sample-springboot的pod

    1. apiVersion: apps/v1
    2. kind: Deployment
    3. metadata:
    4. name: xxl-job-executor-sample-springboot
    5. namespace: default
    6. spec:
    7. replicas: 1
    8. selector:
    9. matchLabels:
    10. app: xxl-job-executor-sample-springboot
    11. strategy:
    12. type: RollingUpdate
    13. rollingUpdate:
    14. maxUnavailable: 25%
    15. maxSurge: 25%
    16. revisionHistoryLimit: 10
    17. progressDeadlineSeconds: 600
    18. template:
    19. metadata:
    20. labels:
    21. app: xxl-job-executor-sample-springboot
    22. release: default
    23. spec:
    24. restartPolicy: Always
    25. containers:
    26. - name: xxl-job-executor-sample-springboot
    27. image: zhxl1989/xxl-job-executor-sample-springboot:2.3.1
    28. imagePullPolicy: Always
    29. ports:
    30. - containerPort: 8081
    31. name: http
    32. - containerPort: 9999
    33. name: executor
    34. resources:
    35. limits:
    36. cpu: '1'
    37. memory: 2Gi
    38. requests:
    39. cpu: 500m
    40. memory: 1Gi
    41. volumeMounts:
    42. - mountPath: /etc/localtime
    43. name: volume-localtime
    44. volumes:
    45. - hostPath:
    46. path: /etc/localtime
    47. type: ''
    48. name: volume-localtime

    4.3、部署xxl-job-executor-sample-springboot的服务

    1. apiVersion: v1
    2. kind: Service
    3. metadata:
    4. name: xxl-job-executor-sample-springboot
    5. namespace: default
    6. labels:
    7. service: xxl-job-executor-sample-springboot
    8. spec:
    9. ports:
    10. - name: executor
    11. port: 9999
    12. protocol: TCP
    13. targetPort: 9999
    14. nodePort: 30999
    15. - name: http
    16. port: 8081
    17. protocol: TCP
    18. targetPort: 8081
    19. nodePort: 30881
    20. selector:
    21. app: xxl-job-executor-sample-springboot
    22. type: NodePort

    xxl-job-executor-sample-springboot启动日志

    4.4、xxl-job-admin页面新建执行器

    AppName为POD(xxl-job-executor-sample-springboot-54dfccf96b-8th69)的应用名称,名称自定义。

    自定义添加执行器在数据库的保存

    在表xxl_job_registry和xxl_job_group中可以看到添加的内容

    等待一会儿,自动注册方式,Online的机器地址会显示出来 

    5、执行测试

    5.1、任务管理新建任务

    5.2、运行模式GLUE(Java),编辑内容

    在右侧“操作”中选择GLUE IDE编辑内容,编辑后保存,每两分钟执行定时任务。

     5.3、在容器中查看运行日志

    5.4、xxl-job-admin调度日志

    附录:

    1. docker stop test && docker rm test
    2. docker images | grep zhxl1989 | awk '{print $3}' | xargs docker rmi
    3. docker build -t zhxl1989/xxl-job:2.3.1 .
    4. docker push zhxl1989/xxl-job:2.3.1
    5. kubectl describe pod xxl-job
    6. docker stop test && docker rm test
    7. docker run -itd --privileged=true --name test -p 8080:8080 -v /home/deploy/:/app/config/ --restart unless-stopped zhxl1989/xxl-job:2.3.1
    8. docker logs -f test
    9. kubectl exec -it dnsutils nslookup kubernetes.default
    10. kubectl exec -it dnsutils -- cat /etc/resolv.conf
    11. kubectl get pods --namespace=kube-system -l k8s-app=kube-dns
    12. kubectl get endpoints coredns --namespace=kube-system
    13. kubectl describe svc coredns --namespace=kube-system
    14. kubectl -n kube-system edit configmap coredns
    15. kubectl logs -f --namespace=kube-system -l k8s-app=kube-dns
    16. kubectl get svc kube-dns -n kube-system
    17. kubectl get deployment coredns -n kube-system

  • 相关阅读:
    基于单片机的公共场所马桶设计(论文+源码)
    huggingface无法下载模型的实战代码
    使用腾讯云cos搭建图片服务器
    java之《图书管理系统》庖丁解牛
    新课标、新考法,猿辅导创新教育研究院全面拆解新课标
    基于springboot+vue共享充电宝管理系统
    低成本实现webhook接收端[python]
    xxis not in the sudoers file. This incident will be reported.
    Swift依赖注入:解锁代码解耦与测试的大门
    Pyhon-每日一练(1)
  • 原文地址:https://blog.csdn.net/TT1024167802/article/details/126918017