xxljob ha 参考配置以及使用说明

官方已经明确了调度中心的ha部署说明

  • db 配置一样
  • 集群机器时间一致
  • 基于nginx 进行la以及使用域名,对于执行器以及api的访问都走域名(lb ip)

参考环境部署

基于docker-compose 运行

  • docker-compose 文件
version: "3"
services: 
  ingress:
    build: ./
    ports: 
    - "80:80"
  job:
    image: xuxueli/xxl-job-admin:2.3.0
    ports: 
    - "8080:8080"
    volumes: 
    - "./tmp:/data/applogs"
    - "./application.properties:/application.properties"
  job2:
    image: xuxueli/xxl-job-admin:2.3.0
    ports: 
    - "8081:8080"
    volumes: 
    - "./tmp2:/data/applogs"
    - "./application.properties:/application.properties"
  mysql:
    image: mysql:5.7
    volumes:
      - ./mysql:/var/lib/mysql
    ports:
      - 3316:3306
    command:  --sql_mode=STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION --lower_case_table_names=1
    environment:
      MYSQL_ROOT_PASSWORD: demoapp
      TZ: Asia/Shanghai

nginx lb 配置

worker_processes 1;
user root;  
events {
    worker_connections 1024;
}
http {
    include mime.types;
    default_type application/octet-stream;
    sendfile on;
    keepalive_timeout 65;
    lua_code_cache off;
    gzip on;
    resolver 127.0.0.11;          
    real_ip_header X-Forwarded-For;
    real_ip_recursive on;
    lua_package_path '/opt/app/?.lua;;';
    upstream jobs {
        server job:8080 weight=20 max_fails=2 fail_timeout=5s;
        server job2:8080 weight=20 max_fails=2 fail_timeout=5s;
    }
    server {
        listen 80;
        server_name localhost;
        charset utf-8;
        root html;
        default_type text/html;
        location / {
           default_type text/html;
           index index.html;
           proxy_set_header Host $http_host;
           proxy_set_header X-Forwarded-For $remote_addr;
           client_body_buffer_size 10M;
           client_max_body_size 10G;
           proxy_buffers 1024 4k;
           proxy_read_timeout 300;
           proxy_next_upstream error timeout http_404;
           proxy_pass http://jobs;
        }
        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
            root html;
        }
    }
}

xxljob 配置 (此文件属于demo,实际自己修改)

### 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
 
### xxl-job, datasource
spring.datasource.url=jdbc:mysql://mysql:3306/xxl_job?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&serverTimezone=Asia/Shanghai
spring.datasource.username=root
spring.datasource.password=demoapp
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

说明

对于实际的lb 并不是一个简单的调度中心的ha,还需要执行器的ha(至少两个节点的,多个更好)同时db的ha 也是比较重要的,后边应用
的配置都需要使用nginx 的入口

参考资料

https://www.xuxueli.com/xxl-job/#%E6%AD%A5%E9%AA%A4%E4%B8%89%EF%BC%9A%E8%B0%83%E5%BA%A6%E4%B8%AD%E5%BF%83%E9%9B%86%E7%BE%A4%EF%BC%88%E5%8F%AF%E9%80%89%EF%BC%89%EF%BC%9A

posted on 2021-09-02 21:34  荣锋亮  阅读(594)  评论(0编辑  收藏  举报

导航