官方已經明確了調度中心的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 的入口