xxl-job docker版分布式任务

使用这分布式任务原因:流行,灵活,稳定,配置简单

git地址:

https://github.com/xuxueli/xxl-job.git

 

我比较失败,尝试docker版本安装失败。

步骤1

下载配置文件

wget https://raw.githubusercontent.com/xuxueli/xxl-job/2.2.0/xxl-job-admin/src/main/resources/application.properties

下载sql脚本文件

wget https://raw.githubusercontent.com/xuxueli/xxl-job/2.2.0/doc/db/tables_xxl_job.sql

在创数据库后,修改application.properties配置文件,主要是修改数据库连接、用户、密码信息,其他信息基本可以不动

spring.datasource.url=jdbc:mysql://192.168.189:9205/xxl_job?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&serverTimezone=Asia/Shanghai
spring.datasource.username=root
spring.datasource.password=123456

然后就启动。

这个启动脚本大致意思是,对外访问端口更改为48080,将本地下的配置文件application.properties挂载到容器根目录下。

同事修改启动参数,启动时指定启动目录为映射的根目录的配置文件application.properties。

docker run -d --name xxljob  \
--restart always \
-p 48080:8080  \
-v /home/soft/xxljob/logs:/data/applogs \
-v /home/soft/xxljob/conf/application.properties:/application.properties   \
-e PARAMS='--spring.config.location=/application.properties'  \
xuxueli/xxl-job-admin:2.2.0

容器创建成功,但是提示连接不成功,后来查看发现是数据库连接地址没更改,还是127.0.0.1.。。

原因也就是启动命令中的下面这句话未生效。。

-e PARAMS='--spring.config.location=/application.properties'  \

 

后尝试修改启动命令如下,但是依旧没能连接上数据库

docker run -d --name xxljob  \
--restart always \
-p 48080:8080  \
-v /home/soft/xxljob/logs:/data/applogs \
-e PARAMS="spring.datasource.url=jdbc:mysql://192.168.189:9205/xxl_job?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&serverTimezone=Asia/Shanghai spring.datasource.username=root spring.datasource.password=123456"  \
xuxueli/xxl-job-admin:2.2.0

 

最终解决办法:

已经下载当前最新版本分支 xxl-job-admin 2.2.0到本地,修改配置文件,打jar包,然后上传jar包与dockerfile到服务器某目录,自己构建镜像,再运行镜像。

下载,修改文件

 

上传到服务器目录

/home/****/image

 

 其中Dockerfile内容为

[root@localhost images]# cat Dockerfile 
FROM openjdk:8-jre-slim
MAINTAINER cwx

ENV PARAMS=""

ENV TZ=PRC
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

ADD xxl-job-admin-*.jar /app.jar

ENTRYPOINT ["sh","-c","java -jar $JAVA_OPTS /app.jar $PARAMS"]

 

再执行构建镜像命令:

cd /home/****/image // 进入目录
// 构建镜像 当前文件件 docker build
-t xxljob .

构建成功,查看镜像

docker images | grep xxljob

得到如下信息。构建成功,接下来就是运行

[root@localhost images]# docker images | grep xxljob
xxljob                               latest              92363db8d4a3        26 minutes ago      223MB

再次运行镜像:

docker run -d --name xxljob  \
--restart always \
-p 48080:8080  \
-v /home/soft/xxljob/logs:/data/applogs \
xxljob:latest

访问:默认后缀这个xxl-job-admin 访问名称可以在application.properties配置中修改。

http://192.168.89.190:48080/xxl-job-admin

 

最终访问成功。

 

其中application.properties配置文件内容

### 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://192.168.3.252:3306/xxl_job?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&serverTimezone=Asia/Shanghai
spring.datasource.username=root
spring.datasource.password=123456
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

### xxl-job, email
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

### 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

 

posted on 2020-07-15 17:49  陈惟鲜的博客  阅读(762)  评论(0编辑  收藏  举报

导航