xxl-job 服务端安装

1
2
3
4
5
6
7
8
9
10
11
12
13
14
docker run -d -e PARAMS="--spring.datasource.url=jdbc:mysql://192.168.2.90:3306/xxl_job?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&serverTimezone=UTC \
--spring.datasource.username=root \
--spring.datasource.password=obcijV6j5BjvLLB8gJZpUC6aho \
--spring.datasource.driver-class-name=com.mysql.jdbc.Driver" \
-p 9088:8080 \
-v /data/xxl-job:/data/applogs \
--name xxl-job \
-d xuxueli/xxl-job-admin:2.3.0

# --xxl.job.accessToken=csml3ewi3al1oehxmo68pqxer" \
# 执行期鉴权所需的配置

# 浏览器访问
IP:9088/xxl-job-admin

xxl-job 执行器部署

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# 本地下载安装包
wget https://github.com/xuxueli/xxl-job/archive/refs/tags/2.3.0.zip
unzip 2.3.0.zip

# 使用 IDEA 打开编辑 (需要修改的点)
# logback.xml
<property name="log.path" value="/Users/macbook/Software/log/xxl-job-executor-sample-springboot.log"/>

# application.properties
server.port=9088
xxl.job.admin.addresses=http://192.168.2.93:9088/xxl-job-admin
# xxl.job.accessToken= # 如果服务端有加 token 验证,这条需要添加
xxl.job.executor.appname=test-admin-api-cron-executor-sample # 与xxl服务端创建项目名需相同
xxl.job.executor.logpath=/opt

# mvn package 打成 jar 包,rz 到代码对应目录

将执行器打入容器中

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# 修改 Dockerfile
FROM csm.io/php:apache-composer-v1
RUN mkdir -p /var/www/csm/runtime/log && mkdir /var/www/csm/runtime/session && mkdir /var/www/csm/runtime/tmp && chown -R www-data. /var/www/csm/runtime/

WORKDIR /var/www/csm

ADD ./xxl-job-executor.jar /opt/
ADD ./jdk-8u311-linux-i586.tar.gz /opt/
#COPY ./xxl-job-config /opt/config #此处将application.properties已经打入jar包中了

ADD ./test-admin-api-cron.tar.gz /var/www/csm
ADD ./\.env /var/www/csm
ADD ./000-default.conf /etc/apache2/sites-enabled/000-default.conf
RUN composer config -g secure-http false && composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/ && composer config -g -l
RUN echo "Asia/Shanghai" > /etc/timezone && composer update

RUN apt-get update && \
apt-get install -y libc6-i386 && \
/opt/jdk1.8.0_311/bin/java -version

#CMD [ "bash", "/var/www/csm/crontab/cron.sh" ]
CMD [ "/opt/jdk1.8.0_311/bin/java", "-jar" ,"xxl-job-executor.jar" ]

#----------------------------------------------
# cron.sh 文件
cat cron.sh
#!/bin/bash
/opt/jdk1.8.0_311/bin/java -jar xxl-job-executor.jar

xxl-job 服务端配置执行器与任务

AppName 需与 jar 打入的配置相同,查看执行器是否自动注册

在这里插入图片描述

编写执行任务

管理任务