xuxueli / xxl-job

A distributed task scheduling framework.(分布式任务调度平台XXL-JOB)
http://www.xuxueli.com/xxl-job/
GNU General Public License v3.0
27.66k stars 10.94k forks source link

docker-compose启动xxl-job-admin失败,无法连接MySQL #2101

Closed yinlijun2004 closed 3 years ago

yinlijun2004 commented 3 years ago

Please answer some questions before submitting your issue. Thanks!

Which version of XXL-JOB do you using?

V2.2.0

Expected behavior

docker-compose启动xxl-job-admin成功

Actual behavior

启动失败,

Steps to reproduce the behavior

  1. docker部署mysql 8.0,用navicat可以连接成功,xxl_job数据库与表已经创建。

  2. 创建xxl-job-admin的docker-compose-

    version: '3'
    services:
    xxl-job-admin:
    image: xuxueli/xxl-job-admin:2.2.0
    restart: always
    container_name: xxl-job-admin
    environment:
       PARAMS: '--spring.datasource.url=jdbc:mysql://localhost:3306/xxl_job?useSSL=false&useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&serverTimezone=Asia/Shanghai --spring.datasource.username=root --spring.datasource.password=root --spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver'
    ports:
      - 8081:8080
    volumes:
      - ./data/applogs:/data/applogs
  3. PARAMS已经设置成功了,进入容器,可以打印出PARAMS环境变量。

    lijundeMacBook-Pro:xxl-job lijunyin$ docker ps -l
    CONTAINER ID        IMAGE                         COMMAND                  CREATED             STATUS              PORTS                    NAMES
    522ed6bebd76        xuxueli/xxl-job-admin:2.2.0   "sh -c 'java -jar $J…"   11 minutes ago      Up 2 minutes        0.0.0.0:8081->8080/tcp   xxl-job-admin
    lijundeMacBook-Pro:xxl-job lijunyin$ docker exec -it 522ed6bebd76 /bin/bash
    root@522ed6bebd76:/# echo $PARAMS
    --spring.datasource.url=jdbc:mysql://localhost:3306/xxl_job?useSSL=false&useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&serverTimezone=Asia/Shanghai --spring.datasource.username=root --spring.datasource.password=root --spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
  4. docker-compose up 提示报错信息:

    xxl-job-admin    | 11:54:08.966 logback [xxl-job, admin JobScheduleHelper#scheduleThread] INFO  c.x.j.a.c.thread.JobScheduleHelper - >>>>>>>>> init xxl-job admin scheduler success.
    xxl-job-admin    | 11:54:09.511 logback [xxl-job, admin JobFailMonitorHelper] ERROR com.zaxxer.hikari.pool.HikariPool - HikariCP - Exception during pool initialization.
    xxl-job-admin    | java.sql.SQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.
    xxl-job-admin    |  at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:110)
    xxl-job-admin    |  at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
    xxl-job-admin    |  at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:89)
    xxl-job-admin    |  at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:63)
    xxl-job-admin    |  at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:73)
    xxl-job-admin    |  at com.mysql.cj.jdbc.ConnectionImpl.connectWithRetries(ConnectionImpl.java:906)
    xxl-job-admin    |  at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:831)
    xxl-job-admin    |  at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:456)
    xxl-job-admin    |  at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:246)
    xxl-job-admin    |  at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:197)
    xxl-job-admin    |  at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:138)
    xxl-job-admin    |  at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:354)
    xxl-job-admin    |  at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:202)
    xxl-job-admin    |  at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:473)
    xxl-job-admin    |  at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:554)
    xxl-job-admin    |  at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:115)
    xxl-job-admin    |  at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112)
    xxl-job-admin    |  at org.springframework.jdbc.datasource.DataSourceUtils.fetchConnection(DataSourceUtils.java:158)
    xxl-job-admin    |  at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:116)
    xxl-job-admin    |  at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:79)
    xxl-job-admin    |  at org.mybatis.spring.transaction.SpringManagedTransaction.openConnection(SpringManagedTransaction.java:80)
    xxl-job-admin    |  at org.mybatis.spring.transaction.SpringManagedTransaction.getConnection(SpringManagedTransaction.java:67)
    xxl-job-admin    |  at org.apache.ibatis.executor.BaseExecutor.getConnection(BaseExecutor.java:336)
    xxl-job-admin    |  at org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:86)
    xxl-job-admin    |  at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:62)
    xxl-job-admin    |  at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:324)
    xxl-job-admin    |  at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156)
    xxl-job-admin    |  at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:109)
    xxl-job-admin    |  at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:83)
    xxl-job-admin    |  at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:147)
    xxl-job-admin    |  at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:140)
    xxl-job-admin    |  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    xxl-job-admin    |  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    xxl-job-admin    |  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    xxl-job-admin    |  at java.lang.reflect.Method.invoke(Method.java:498)
    xxl-job-admin    |  at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:426)
    xxl-job-admin    |  at com.sun.proxy.$Proxy80.selectList(Unknown Source)
    xxl-job-admin    |  at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:223)
    xxl-job-admin    |  at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:147)
    xxl-job-admin    |  at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:80)
    xxl-job-admin    |  at org.apache.ibatis.binding.MapperProxy$PlainMethodInvoker.invoke(MapperProxy.java:144)
    xxl-job-admin    |  at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:85)
    xxl-job-admin    |  at com.sun.proxy.$Proxy83.findFailJobLogIds(Unknown Source)
    xxl-job-admin    |  at com.xxl.job.admin.core.thread.JobFailMonitorHelper$1.run(JobFailMonitorHelper.java:41)
    xxl-job-admin    |  at java.lang.Thread.run(Thread.java:748)
    xxl-job-admin    | Caused by: com.mysql.cj.exceptions.CJCommunicationsException: Communications link failure
    xxl-job-admin    | 
    xxl-job-admin    | The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
    xxl-job-admin    |  at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    xxl-job-admin    |  at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    xxl-job-admin    |  at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    xxl-job-admin    |  at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    xxl-job-admin    |  at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:61)
    xxl-job-admin    |  at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:105)
    xxl-job-admin    |  at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:151)
    xxl-job-admin    |  at com.mysql.cj.exceptions.ExceptionFactory.createCommunicationsException(ExceptionFactory.java:167)
    xxl-job-admin    |  at com.mysql.cj.protocol.a.NativeSocketConnection.connect(NativeSocketConnection.java:91)
    xxl-job-admin    |  at com.mysql.cj.NativeSession.connect(NativeSession.java:144)
    xxl-job-admin    |  at com.mysql.cj.jdbc.ConnectionImpl.connectWithRetries(ConnectionImpl.java:850)
    xxl-job-admin    |  ... 39 common frames omitted
    xxl-job-admin    | Caused by: java.net.ConnectException: Connection refused (Connection refused)
    xxl-job-admin    |  at java.net.PlainSocketImpl.socketConnect(Native Method)
    xxl-job-admin    |  at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
    xxl-job-admin    |  at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
    xxl-job-admin    |  at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
    xxl-job-admin    |  at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    xxl-job-admin    |  at java.net.Socket.connect(Socket.java:607)
    xxl-job-admin    |  at com.mysql.cj.protocol.StandardSocketFactory.connect(StandardSocketFactory.java:155)
    xxl-job-admin    |  at com.mysql.cj.protocol.a.NativeSocketConnection.connect(NativeSocketConnection.java:65)
    xxl-job-admin    |  ... 41 common frames omitted
    xxl-job-admin    | 11:54:09.513 logback [xxl-job, admin JobScheduleHelper#scheduleThread] INFO  com.zaxxer.hikari.HikariDataSource - HikariCP - Starting...
    xxl-job-admin    | 11:54:09.520 logback [xxl-job, admin JobFailMonitorHelper] ERROR c.x.j.a.c.t.JobFailMonitorHelper - >>>>>>>>>>> xxl-job, job fail monitor thread error:{}
    xxl-job-admin    | org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException: 
    xxl-job-admin    | ### Error querying database.  Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is java.sql.SQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.
    xxl-job-admin    | ### The error may exist in class path resource [mybatis-mapper/XxlJobLogMapper.xml]
    xxl-job-admin    | ### The error may involve com.xxl.job.admin.dao.XxlJobLogDao.findFailJobLogIds
    xxl-job-admin    | ### The error occurred while executing a query
    xxl-job-admin    | ### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is java.sql.SQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.
    xxl-job-admin    |  at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:92)
    xxl-job-admin    |  at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:440)
    xxl-job-admin    |  at com.sun.proxy.$Proxy80.selectList(Unknown Source)
    xxl-job-admin    |  at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:223)
    xxl-job-admin    |  at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:147)
    xxl-job-admin    |  at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:80)
    xxl-job-admin    |  at org.apache.ibatis.binding.MapperProxy$PlainMethodInvoker.invoke(MapperProxy.java:144)
    xxl-job-admin    |  at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:85)
    xxl-job-admin    |  at com.sun.proxy.$Proxy83.findFailJobLogIds(Unknown Source)
    xxl-job-admin    |  at com.xxl.job.admin.core.thread.JobFailMonitorHelper$1.run(JobFailMonitorHelper.java:41)
    xxl-job-admin    |  at java.lang.Thread.run(Thread.java:748)
    xxl-job-admin    | Caused by: org.apache.ibatis.exceptions.PersistenceException: 
    xxl-job-admin    | ### Error querying database.  Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is java.sql.SQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.

    用源码代码直接修改spring.datasource配置,编译运行可以连接数据库

LockiJiang commented 3 years ago

错误信息很明显,连接不上数据库 连接信息为啥要用localhost,你的容器里面有mysql? localhost改成正确的地址

yinlijun2004 commented 3 years ago

错误信息很明显,连接不上数据库 连接信息为啥要用localhost,你的容器里面有mysql? localhost改成正确的地址

谢谢!

clement-jiao commented 1 year ago

有可能是 xxl.job.accessToken 这个可选参数没加,所以你连不上数据库 [狗子]

Arthas217 commented 1 year ago

docker启动mysql后,连接数据库的ip地址有可能更改

wjs1995 commented 10 months ago

怎么解决的我也碰到了。。。

yuchao-wang commented 1 month ago

简直太坑了,用了各种方法都不行,最后把PARAMS=“”,引号里面写上所有的变量改动才行,而且多个-e换行都不行。 也就是说PARAMS的value里面是个所有的变量映射

clement-jiao commented 1 month ago

简直太坑了,用了各种方法都不行,最后把PARAMS=“”,引号里面写上所有的变量改动才行,而且多个-e换行都不行。 也就是说PARAMS的value里面是个所有的变量映射

-e 会分割 params,认为他是多个参数,所以不能这么做 ←_←

LockiJiang commented 1 month ago

简直太坑了,用了各种方法都不行,最后把PARAMS=“”,引号里面写上所有的变量改动才行,而且多个-e换行都不行。 也就是说PARAMS的value里面是个所有的变量映射

@clement-jiao @yuchao-wang 这个是docker镜像的封装问题,你可以按照你的需求改写Dockerfile啊,作者只是提供了一个最简单的镜像; 图片