简体   繁体   中英

Error opening socket to server while connecting to database

When my application server is running, Jboss is not able to connect to DB. I am running docker DB2 image and not using local DB. I am running Docker on Virtual Box. Application is opening socket to VirtualBox IP instead of localhost. Error says:

Error says: Cannot create PoolableConnectionFactory: Exception java.net.ConnectException: Error opening socket to server /192.168.56.1 on port 50,000 with message: Connection refused: connect. ERRORCODE=-4499, SQLSTATE=08001 Cannot create PoolableConnectionFactory: Exception java.net.ConnectException: Error opening socket to server /192.168.56.1 on port 50,000 with message: Connection refused: connect. ERRORCODE=-4499, SQLSTATE=08001 ....Where 192.168.56.1 is my Virtual Box Ip. I can connect my DB2 docker image through DB2 client running on local but not with my application.

Logs:

2019-02-11 18:20:16,806  INFO [ost-startStop-1 ation.ConfigurationClassParser] - Properties location [/opt/demandtec/common/conf/jms.properties] not resolvable: class path resource [opt/demandtec/common/conf/jms.properties] cannot be opened because it does not exist
2019-02-11 18:20:17,877  INFO [ost-startStop-1 redAnnotationBeanPostProcessor] - JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
2019-02-11 18:20:18,683  INFO [ost-startStop-1 dtec.message.DestReserverBeans] - Loading defalt queue topic definitions
2019-02-11 18:20:18,736  INFO [ost-startStop-1 mandtec.global.DTServiceConfig] - init jndi template
2019-02-11 18:20:18,764  INFO [ost-startStop-1 dtec.global.DTRemotingServices] - Start Locate Registry with port: 3099
2019-02-11 18:20:22,685  INFO [ost-startStop-1 ssage.activemq.DTAMQJmsService] - amq connect meta data created
2019-02-11 18:20:22,691  INFO [ost-startStop-1 .message.InitConnectionFactory] - export: QueueConnectionFactory as interface com.ibm.demandtec.mq.RemoteConnectFactory
2019-02-11 18:20:22,697  INFO [ost-startStop-1 .message.InitConnectionFactory] - export: TopicConnectionFactory as interface com.ibm.demandtec.mq.RemoteConnectFactory
2019-02-11 18:20:22,698  INFO [ost-startStop-1 .message.InitConnectionFactory] - export: PromoCPQueueConnectionFactory as interface com.ibm.demandtec.mq.RemoteConnectFactory
2019-02-11 18:20:22,698  INFO [ost-startStop-1 .message.InitConnectionFactory] - export: PerishableQueueConnectionFactory as interface com.ibm.demandtec.mq.RemoteConnectFactory
2019-02-11 18:20:22,698  INFO [ost-startStop-1 .message.InitConnectionFactory] - export: AMEQueueConnectionFactory as interface com.ibm.demandtec.mq.RemoteConnectFactory
2019-02-11 18:20:22,698  INFO [ost-startStop-1 .message.InitConnectionFactory] - export: FarmQueueConnectionFactory as interface com.ibm.demandtec.mq.RemoteConnectFactory
2019-02-11 18:20:22,720  INFO [ost-startStop-1 .message.InitConnectionFactory] - export: IAMTopicConnectionFactory as interface com.ibm.demandtec.mq.RemoteConnectFactory
2019-02-11 18:20:22,720  INFO [ost-startStop-1 .message.InitConnectionFactory] - export: CTSQueueConnectionFactory as interface com.ibm.demandtec.mq.RemoteConnectFactory
2019-02-11 18:20:22,721  INFO [ost-startStop-1 .message.InitConnectionFactory] - export: GlobalQueueConnectionFactory as interface com.ibm.demandtec.mq.RemoteConnectFactory
2019-02-11 18:20:22,722  INFO [ost-startStop-1 .message.InitConnectionFactory] - export: GlobalTopicConnectionFactory as interface com.ibm.demandtec.mq.RemoteConnectFactory
2019-02-11 18:20:22,731  INFO [ost-startStop-1 ndtec.mq.DTMQConnectionFactory] - Init class: org.apache.activemq.ActiveMQConnectionFactory, with: {brokerURL=tcp://IBM217-PC0BY3X9:61616, trustAllPackages=true}
2019-02-11 18:20:22,992  INFO [ost-startStop-1 ndtec.mq.DTMQConnectionFactory] - Init class: org.apache.activemq.ActiveMQConnectionFactory, with: {brokerURL=tcp://IBM217-PC0BY3X9:61616, clientID=IBM217-PC0BY3X9.IAM, trustAllPackages=true}
2019-02-11 18:20:23,357  WARN [ost-startStop-1 .commons.dbcp2.BasicDataSource] - The requested JMX name [demandtec.com_optimization] was not valid and will be ignored.
2019-02-11 18:20:53,117  INFO [pool-2-thread-1 .demandtec.global.DTMDBService] - Startup AdminMDB
2019-02-11 18:20:54,241  INFO [pool-2-thread-1 .demandtec.global.DTMDBService] - Startup IAM as clientid:IBM217-PC0BY3X9_appiam
2019-02-11 18:30:31,001  WARN [ost-startStop-1 emandtec.dal.ConnectionHandler] - JBossPoolException! Failed getting connection to Optimization for demandtec.com
2019-02-11 18:30:31,001  WARN [ost-startStop-1 emandtec.dal.ConnectionHandler] - cause: Cannot create PoolableConnectionFactory ([jcc][t4][2043][11550][4.22.29] Exception java.net.ConnectException: Error opening socket to server /192.168.56.1 on port 50,000 with message: Connection refused: connect. ERRORCODE=-4499, SQLSTATE=08001)
2019-02-11 18:30:31,001  WARN [ost-startStop-1 emandtec.dal.ConnectionHandler] - will attempt one more time.
2019-02-11 18:30:31,001  WARN [ost-startStop-1 .commons.dbcp2.BasicDataSource] - The requested JMX name [demandtec.com_optimization] was not valid and will be ignored.

Database: DB2; OS: Windows7/ Docker running on Oracle VirtualBox; Framework: J2EE; App-Server: Jboss

I think I have the same problem using ibmcom/db2 community edition image. It works well when I start the container on MacOS. Then if I start the container in virtualbox environment, jdbc connection fails.

[jcc][10521][13706]Command : java com.ibm.db2.jcc.DB2Jcc -user db2inst1 -password ******** -url jdbc:db2://0.0.0.0:50000/testdb


[jcc][10512][13714]Failed to create connection.
  SQLCODE: -4499
  SQLSTATE: 08001
  Message: [jcc][t4][2030][11211][4.12.55] A communication error occurred during operations on the connection's underlying socket, socket input stream,
or socket output stream.  Error location: Reply.fill() - insufficient data (-1).  Message: Insufficient data. ERRORCODE=-4499, SQLSTATE=08001

Someone suspect it is because of ipv6. So I run docker run -itd --name mydb2 --privileged=true -p 50000:50000 -e LICENSE=accept -e DB2INST1_PASSWORD=test123 -e DBNAME=testdb -v /home/vagrant/database:/database ibmcom/db2 to start a container. Then get into container with docker exec -it mydb2 bash . Remove serveral ipv6 lines and keep only following in /etc/hosts file.

127.0.0.1       localhost
172.17.0.2      def55f9a8b0f

Quit and remove this container. Restart container with command docker run -itd --name mydb2 --privileged=true -p 0.0.0.0:50000:50000 -e LICENSE=accept -e DB2INST1_PASSWORD=test123 -e DBNAME=testdb -v /home/vagrant/database:/database ibmcom/db2 .

CONTAINER ID   IMAGE        COMMAND                  CREATED         STATUS         PORTS                                                          NAMES
4fbaec4a46ac   ibmcom/db2   "/var/db2_setup/lib/…"   7 minutes ago   Up 7 minutes   22/tcp, 55000/tcp, 60006-60007/tcp, 0.0.0.0:50000->50000/tcp   mydb2

Wait for a few moments, JDBC connection works.

[jcc][10516][13709]Test Connection Successful.

DB product version = SQL11056
DB product name = DB2/LINUXX8664
DB URL = jdbc:db2://127.0.0.1:50000/testdb
DB Drivername = IBM Data Server Driver for JDBC and SQLJ
DB OS Name = Linux

对于在 podman 上遇到此问题的任何人,只需将 rootfull 设置为 true 并重复设置过程

podman machine set --rootful=true

In our scenario we solved just adding the option

privileged: true

to the db2 service in the docker-compose.yml file

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM