官方文档
一、下载源码
源码地址:见官方文档
二、初始化数据库
在初始化数据库中遇到了这个问题,博客有解决办法,我的解决办法是使用的mysql5.6,后来改成了mysql5.7成功。
Specified key was too long; max key length is 767 bytes问题解决
三、启动项目 & 访问
3.1 启动xxl-job-admin
1)添加日志路径,并修改文件权限
touch /data/applogs/xxl-job/xxl-job-admin.log
chmod 777 xxl-job-admin.log
2) 修改数据库的连接地址,用户名和端口号为步骤二数据库
3) 访问地址
http://localhost:8080/xxl-job-admin/
用户名/密码:admin/123456
3.2 启动xxl-job-executor-sample-springboot
1)添加日志路径,并修改文件权限
touch /data/applogs/xxl-job/xxl-job-executor-sample-springboot.log
chmod 777 /data/applogs/xxl-job/xxl-job-executor-sample-springboot.log
登录3.1中的xxl-admin地址
修改cron表达式为* * * * * ?
(每秒都执行)
可以通过xxl-job-admin平台看调度日志,查看任务调度情况
问题总结:
日志打印报错(原因是文件件不存在或者没有读写权限)
日志文件包括:
/data/applogs/xxl-job/xxl-job-executor-sample-springboot.log
/data/applogs/xxl-job/xxl-job-admin.log
/data/applogs/xxl-job/jobhandler/gluesource
四、xxl-job平台的使用
4.1 单机多执行配置
1,调度中心
在初始化数据库时会插入一条任务记录
2,执行器
复制module:拷贝xxl-job-executor-sample-springboot为xxl-job-executor-sample-springboot2
【注】只需要改配置文件中,和xxl-job-executor-sample-springboot module的区分开
# web port
server.port=8082
... ...
xxl.job.executor.port=9998
启动新建执行器
数据库中会在将新执行器的地址插入到数据库中
查看当前注册执行器地址
修改调度中心的路由策略为轮询
然后重启调度中心,可以发现会轮询的调度两个执行器
五、问题总结
5.1 执行器回调调度中心报Connection refused、Read timed out
1)错误日志
11:42:21.896 logback [Thread-117] ERROR c.x.job.core.util.XxlJobRemotingUtil - Connection refused (Connection refused)
java.net.ConnectException: Connection refused (Connection refused)
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at sun.net.NetworkClient.doConnect(NetworkClient.java:175)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:463)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:558)
at sun.net.www.http.HttpClient.<init>(HttpClient.java:242)
at sun.net.www.http.HttpClient.New(HttpClient.java:339)
at sun.net.www.http.HttpClient.New(HttpClient.java:357)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:1220)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1156)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:1050)
at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:984)
at com.xxl.job.core.util.XxlJobRemotingUtil.postBody(XxlJobRemotingUtil.java:95)
at com.xxl.job.core.biz.client.AdminBizClient.callback(AdminBizClient.java:37)
at com.xxl.job.core.thread.TriggerCallbackThread.doCallback(TriggerCallbackThread.java:167)
at com.xxl.job.core.thread.TriggerCallbackThread.retryFailCallbackFile(TriggerCallbackThread.java:242)
at com.xxl.job.core.thread.TriggerCallbackThread.access$400(TriggerCallbackThread.java:25)
at com.xxl.job.core.thread.TriggerCallbackThread$2.run(TriggerCallbackThread.java:112)
at java.lang.Thread.run(Thread.java:748)
11:47:04.364 logback [Thread-115] ERROR c.x.job.core.util.XxlJobRemotingUtil - Read timed out
java.net.SocketTimeoutException: Read timed out
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
at java.net.SocketInputStream.read(SocketInputStream.java:171)
at java.net.SocketInputStream.read(SocketInputStream.java:141)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:246)
at java.io.BufferedInputStream.read1(BufferedInputStream.java:286)
at java.io.BufferedInputStream.read(BufferedInputStream.java:345)
at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:735)
at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:678)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1587)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1492)
at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:480)
at com.xxl.job.core.util.XxlJobRemotingUtil.postBody(XxlJobRemotingUtil.java:115)
at com.xxl.job.core.biz.client.AdminBizClient.callback(AdminBizClient.java:37)
at com.xxl.job.core.thread.TriggerCallbackThread.doCallback(TriggerCallbackThread.java:167)
at com.xxl.job.core.thread.TriggerCallbackThread.retryFailCallbackFile(TriggerCallbackThread.java:242)
at com.xxl.job.core.thread.TriggerCallbackThread.access$400(TriggerCallbackThread.java:25)
at com.xxl.job.core.thread.TriggerCallbackThread$2.run(TriggerCallbackThread.java:112)
at java.lang.Thread.run(Thread.java:748)
执行器执行完成后回调调度中心,任务调度中心页面只有调度结果成功,执行结果有是成功,有是为空
2)错误定位、解决
XxlJobRemotingUtil类的postBody方法
由于公司发的电脑太破,导致读取和连接超时。
connection.setReadTimeout(timeout * 1000);
connection.setConnectTimeout(3 * 1000);
- 把读取超时时间设置长一点。
-
把调度中心的cron表达式执行的周期设置的长一点
可以解决问题。
5.2 调度中心的执行备注为“无”
添加代码
ReturnT<String> msg = new ReturnT<>(200,"【执行成功】" +
new Date());
如下图:
然后重新启动任务,点击查看可以查看执行备注信息