docker安装xxl-job-admin
- 下载镜像
docker pull xuxueli/xxl-job-admin
- 查看镜像
- 初始化对应的数据库脚本
https://github.com/xuxueli/xxl-job/blob/2.3.0/doc/db/tables_xxl_job.sql
docker-compose.yml
[root@localhost www]# more docker-compose.yml
version: '3'
services:
mysql: #服务名称(不是容器名,名称最好不要含有特殊字符,碰到过用下划线时运行出错)
image: mysql:5.7
container_name: mysql59 #容器名称
restart: always
environment:
- "MYSQL_ROOT_PASSWORD=123456"
- "MYSQL_DATABASE=xxl_job"
ports:
- "3306:3306"
networks: #加入指定网络
- xxl_job_net
xxljob:
image: xuxueli/xxl-job-admin:2.3.0
container_name: xxljob59
ports:
- "8666:8080"
environment:
PARAMS: '--spring.datasource.url=jdbc:mysql://mysql:3306/xxl_job?Unicode=true&characterEncoding=UTF-8 --spring.datasource.username=root --spring.datasource.password=123456'
networks:
- xxl_job_net
depends_on:
- mysql
networks:
xxl_job_net:
driver: bridge
[root@localhost www]#
- 执行
docker-compose up
- 访问地址 192.168.212.123:8080/xxl-job-admin/
- admin/123456
6.客户端任务管理代码
/**
* @author zhangxiao
* @qq 490433117
* @create_date 2022/6/17 14:25
*/
package com.example.democlient.taskhandler;
import com.xxl.job.core.handler.annotation.XxlJob;
import org.springframework.stereotype.Component;
/**
*
* @author zhangxiao
* @date 2022/6/17 14:25
*/
@Component
public class DemoTaskHandler {
@XxlJob("demoTaskHandler")
public void execute() throws Exception {
try {
System.out.println("democlient开始执行demoTask...");
} catch (Exception e) {
e.printStackTrace();
}
}
}
/**
* @author zhangxiao
* @qq 490433117
* @create_date 2022/6/17 14:24
*/
package com.example.democlient.taskhandler;
import com.xxl.job.core.executor.impl.XxlJobSpringExecutor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
*
* @author zhangxiao
* @date 2022/6/17 14:24
*/
@Configuration
public class XxlJobConfig {
private Logger logger = LoggerFactory.getLogger(XxlJobConfig.class);
@Value("${xxl.job.admin.addresses}")
private String adminAddresses;
@Value("${xxl.job.accessToken}")
private String accessToken;
@Value("${xxl.job.executor.appname}")
private String appname;
@Value("${xxl.job.executor.address}")
private String address;
@Value("${xxl.job.executor.ip}")
private String ip;
@Value("${xxl.job.executor.port}")
private int port;
@Value("${xxl.job.executor.logpath}")
private String logPath;
@Value("${xxl.job.executor.logretentiondays}")
private int logRetentionDays;
@Bean
public XxlJobSpringExecutor xxlJobExecutor() {
logger.info(">>>>>>>>>>> xxl-job config init.");
XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor();
xxlJobSpringExecutor.setAdminAddresses(adminAddresses);
logger.info("adminAddresses:{}",adminAddresses);
xxlJobSpringExecutor.setAppname(appname);
xxlJobSpringExecutor.setAddress(address);
xxlJobSpringExecutor.setIp(ip);
xxlJobSpringExecutor.setPort(port);
xxlJobSpringExecutor.setAccessToken(accessToken);
xxlJobSpringExecutor.setLogPath(logPath);
xxlJobSpringExecutor.setLogRetentionDays(logRetentionDays);
return xxlJobSpringExecutor;
}
}
# web port
### xxl-job admin address list, such as "http://address" or "http://address01,http://address02"
#填写你自己的xxl-job-admin项目
xxl.job.admin.addresses=http://192.168.212.123:8666/xxl-job-admin
### xxl-job, access token
xxl.job.accessToken=
### xxl-job executor appname
#与新增的执行器名称一致
xxl.job.executor.appname=xxl-job-executor-sample
### xxl-job executor registry-address: default use address to registry , otherwise use ip:port if address is null
xxl.job.executor.address=
### xxl-job executor server-info
#我写的内网地址
xxl.job.executor.ip=192.168.212.123
xxl.job.executor.port=9999
### xxl-job executor log-path
xxl.job.executor.logpath=E:\\gluesource
### xxl-job executor log-retention-days
#日志保留天数
xxl.job.executor.logretentiondays=30