banner
keney

keney

remain optimistic
twitter

xxl-job of docker

xxl-job#

Pull the image:

docker pull xuxueli/xxl-job-admin:2.3.1

Start the container:

docker run -d --name=xxl-job-admin \
-p 8088:8080 \
-v /root/docker-data/xxl-job/application.properties:/application.properties \
-v /root/docker-data/xxl-job/applogs:/data/applogs \
xuxueli/xxl-job-admin:2.3.1

The application.properties file in /root/docker-data/xxl-job/ needs to be obtained from the xxl-job project, and the database connection username and password need to be modified, then it is

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://172.17.0.1: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
spring.datasource.hikari.validation-timeout=1000

### xxl-job, email
spring.mail.host=smtp.qq.com
spring.mail.port=25
[email protected]
[email protected]
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=default_token

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

xxl-job Database Connection Issues#

Background:

Scheduled task scheduling is required in the project, and xxl-job needs to be installed in the docker container.

Problems encountered:

After successful deployment, the xxl-job login interface can be accessed, but clicking login has no response, and after a while, a database connection refusal pops up, indicating that MyBatis connection user failed.

Reason:

In the docker container, different containers are isolated from each other, and using localhost or 127.0.0.1 will not work.

Solution:

Approach:

  1. First, check whether the database username and password to be connected are correct.

  2. If it is a connection access between different containers in docker, check the internal network address of the server.

  3. Check whether the mapped ports correspond.

Method:

Check the server's internal IP address:

Modify the application.properties configuration:

Database connection address and password

Or use: access via container name plus port number, for example, my MySQL database container name is n_mysql

Then

spring.datasource.url=jdbc:mysql://n_mysql:3306/xxl_job?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&serverTimezone=Asia/Shanghai

Note: These operations are all performed on the same server.

During these steps, there may be other reasons:

  1. Whether the operations are performed on the same server; if on different servers, the local area network IP address cannot be used directly, and the public IP must be used to connect to the database.

  2. Whether the mapped address is correct when creating the container (not limited to path names).

  3. Check whether the firewall allows the corresponding ports; however, since the backend address can be accessed, it should not be a firewall issue.

Extension:

Accessing MySQL and Redis on the host from applications inside docker
Background: The host deploys MySQL and Redis, and docker deploys tomcat and jdk
Requirement: Applications in tomcat access the host's MySQL and Redis
Method:

  1. The connection address must not use localhost and 127.0.0.1
    These addresses represent the system inside the container and do not access the host, resulting in continuous connection exceptions to MySQL/Redis.
  2. Use the docker virtual network card address
    Check the network card situation on the host------ifconfig
    The inet address of the docker0 virtual network card is the correct local IP (e.g., 172.17.0.1)
Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.