app suddenly cannot connect to local database - java

A spring mvc application using hibernate on CentOS 7 is suddenly not able to create a database connection when I restart tomcat 8. This means I cannot log into the application. The database connection was working perfectly for a long time. The only change I made recently was to follow the instructions in this OpenVPN tutorial, with the exception of using firewalld instead of iptables as in the tutorial. I am not certain that the OpenVPN changes caused this problem, but I reversed almost all the steps in the tutorial just to check: yum remove openvpn easy-rsa -y, remove firewalld changes, etc) But the problem still persists.
How can I get my app to successfully connect to the database again?
My database connection string is:
jdbc.url=jdbc:mysql://localhost:3306/atest?autoReconnect=true
The relevant message during tomcat startup is:
INFO ConnectionProviderInitiator - HHH000130: Instantiating explicit connection provider: org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider
WARN JdbcServicesImpl - HHH000342: Could not obtain connection to query metadata : Could not create connection to database server. Attempted reconnect 3 times. Giving up.
INFO Dialect - HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
INFO LobCreatorBuilder - HHH000422: Disabling contextual LOB creation as connection was null
I also checked other things like confirming the password is correct, logging into the database using the shell to confirm it is working, etc.
EDIT
I checked the contents of /etc by doing cd /etc and then ls -al and the results included the following: host.conf, hostname, hosts, hosts.allow, hosts.deny. I checked each of the files just now, and their contents do not seem to have changed since the last time I modified them, long before this problem emerged.
As per #shinjw's request, /etc/hosts contains the following, but the following has not changed since long before this problem emerged:
127.0.0.1 localhost.localdomain localhost
# Auto-generated hostname. Please do not remove this comment.
abc.de.fgh.ij mydomain.com mydomain
::1 ip6-localhost ip6-loopback

Related

Error when trying to connect to H2 database

Did any of you had this below error when trying to connect to H2?
The release I'm using is 1.4.199, on windows, with TAFJFuctions.
First I run this command:
java -server -cp h2-1.4.199.jar;C:\Users\...\H2\TAFJFunctions.jar org.h2.tools.Server -web -tcp -tcpPort 9092 -tcpAllowOthers -baseDir C:\Users\...\H2\bin
and I've got connected with TCP server running and Web Console server running as well.
Then I've run this command:
SET H2URL=jdbc:h2:tcp://locaLhost/t24db;DB_CLOSE_ON_EXIT=FALSE;MODE=Oracle;TRACE_LEVEL_FILE=0;TRACE_LEVEL_SYSTEM_OUT=0;FILE_LOCK=NO;IFEXISTS=TRUE;CACHE_SIZE=8192;MVCC=TRUE;LOCK_TIMEOUT=60000
And then this command:
java -server -cp h2-1.4.199.jar;C:\Users\...\H2\TAFJFunctions.jar org.h2.tools.Shell -url %H2URL% -driver org.h2.Driver -user t24 -password t24
And here I've got the below error:
"Exception in thread "main" org.h2.jdbc.JdbcSQLNonTransientConnectionException: Database "C:/Users/.../H2/bin/t24db" not found, and IFEXISTS=true, so we cant auto-create it [90146-199]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:617)
at org.h2.message.DbException.getJdbcSQLException(DbException.java:427)
at org.h2.message.DbException.get(DbException.java:205)
at org.h2.message.DbException.get(DbException.java:181)
at org.h2.engine.Engine.openSession(Engine.java:67)
at org.h2.engine.Engine.openSession(Engine.java:201)
at org.h2.engine.Engine.createSessionAndValidate(Engine.java:178)
at org.h2.engine.Engine.createSession(Engine.java:161)
at org.h2.server.TcpServerThread.run(TcpServerThread.java:160)
at java.lang.Thread.run(Unknown Source)
at org.h2.message.DbException.getJdbcSQLException(DbException.java:617)
at org.h2.engine.SessionRemote.done(SessionRemote.java:607)
at org.h2.engine.SessionRemote.initTransfer(SessionRemote.java:143)
at org.h2.engine.SessionRemote.connectServer(SessionRemote.java:431)
at org.h2.engine.SessionRemote.connectEmbeddedOrServer(SessionRemote.java:317)
at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:169)
at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:148)
at org.h2.Driver.connect(Driver.java:69)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at org.h2.tools.Shell.runTool(Shell.java:148)
at org.h2.tools.Shell.main(Shell.java:81)"
Any idea how to get this working?
Thank you,
Carina
With IFEXISTS=TRUE the problem is oblivious, but without this parameter or with attempt to set it to FALSE situation is not going to be changed.
All recent versions of H2 database don't allow remote (including local TCP connections) database creation by default any more due to security reasons. When it is allowed, everyone who can connect to your port can create a new database, get ADMIN privileges in it and therefore get the same access to your system as your JVM and your user account allows.
Unfortunately, H2 1.4.199 throws a confusing error message, it was improved only in 1.4.200 and in this version (when IFEXISTS=TRUE wasn't used) the error message is “Database … not found, either pre-create it or allow remote database creation (not recommended in secure environments)”.
If you use a TCP (or Pg/ODBC) server you need to create your databases in some other way before you try to connect to them with networked protocol.
For example, you can open the JDBC connection (DriverManager.getConnection()) with embedded URL and close it immediately.
You can replace org.h2.tools.Server with org.h2.tools.Console and you'll see another http connection URL (if you start it from the command line), something like http://127.0.0.2:8082?key=12c58e1c5f9ce1ae88a2921f74e7655ed91a80746730cc6bfa8d4bbb464f69ee; with this URL you will be able to create the database from the web interface (only if remove web interface is not enabled).
You can also add the -tool parameter (only to Console, the Server doesn't support it) to get H2 Console icon in the system tray, its context menu has a command to create a new database and this icon can also open the web interface with the same security key. Don't share this key with anyone. It will be different on each restart, however.
You can also use the command-line Shell tool.
https://h2database.com/html/tutorial.html#creating_new_databases
In the worst case you can enable the remove database creation, but it is not really secure even with local connections and it is completely insecure when remote connections are enabled as in your case. You will have a well-known remote security hole in your system, I don't think that it is your intention.
The problem here is that there is no database called t24db already.
In the property spring.datasource.url property which you use to connect to h2, remove the parameter IFEXISTS=TRUE.
This will ensure that the database is created if it does not exist.

h2 server mode or mixed mode : data are updated from app1 but not visible from app2

I'm new to h2, but I read a lot of documentation,
I successfully created embeded H2 mem or file database.
But I'm still not able to use server mode or mixed mode :
I launch my Web server and tcp server like this :
java -jar h2-1.4.196.jar -web -webAllowOthers -tcp -tcpAllowOthers -browser -tcpPort 9092
Trying server mode :
I create file database like this :
I open H2 console and enter following :
jdbc:h2:~/maBaseH2FichierTCP
username: sa
password:
Database is created, and I see a lock file
In my java application
url: jdbc:h2:tcp://localhost:9092/~/maBaseH2FichierTCP
same username and pwd
--> When I launch my java application properties file, it stays sticked at the phase of datasource creation.
I tried to change url: jdbc:h2:tcp://localhost:9092/~/maBaseH2FichierTCP
to jdbc:h2:tcp://localhost/~/maBaseH2FichierTCP, but no effect.
Trying mixed mode :
In H2 console, I created jdbc:h2:C:/data/maBaseFichierAutoServeur;AUTO_SERVER=TRUE
In java, url: jdbc:h2:tcp://192.168.1.152:55000/file:c:/data/maBaseFichierAutoServeur;AUTO_SERVER=TRUE
--> Behaviour is the same, application start, but when at datasource creation, it waits, and nothing more happen ...
Does someone take has a idea to make one of orther server mode work ?
I solved this first problem : It was caused by a incompatibility between h2 version of h2 console, and my h2 client in application. 1.4.196 vs 1.4.192; when debuging, we can see an exception is launched, but nothing is writen on debug or even trace I think, and programme try to execute a rollback on a connection. It ended in a infinite loop here, even if I don't understand why. When changing version, I can connect my remote base.
Howerver now, when application update the database, the updated data cannot been seen in h2 console. Does someone know why ?

Connect Metabase to Sql Server

I installed Java on my Windows 10 machine and downloaded Metabase.jar, and ran it.
Now I could access metabase at localhost:3000
But I'm unable to setup my SQL Server Database as Data reference.
I'm either getting:
Couldn't connect to the database. Please check the connection details.
or
Timed out after 5000 milliseconds.
Anyone who has done Metabase - SQL Server connection successfully?
Currently, as of Metabase version 0.30.x the answer depends on if you can use a user configured directly on SQL Server or not:
The easier option to setup is with a user configured directly on SQL Server. Then config is just Name: (anything), Host: (full name), Database Name, Username, Password as you would expect. (I believe you should NOT fill in the Windows domain).
On Windows only you can also use native integrated authentication with sqljdbc_auth.dll, just specify integratedSecurity=true connection property (and optionally authenticationScheme=NativeAuthentication). I found if I dropped the x64 sqljdbc_auth.dll in my <java path>\jre\bin folder it was picked up. Metabase config as in the screenshot below, apart from dropping authenticationScheme=JavaKerberos
The cross platform authenticationScheme=JavaKerberos option to use Windows Authentication with a domain user is still doable, but harder. It's these steps:
Create a krb.conf and verify login works with <Java path>\bin\kinit.exe [user]. Here's a template edited to match the Metabase database setup in the screenshot below.
Start the Metabase.jar file with parameters to load the krb.conf. It works for me with java -Djava.security.krb5.conf=c:/<path>/kerberos/krb.conf -jar metabase.jar.
Now configure the database settings in Metabase according to the screenshot below
Moment of truth! ...
Optional: Still not working? Maybe your SQL Server isn't configured for Kerberos? Maybe you need SPN setup? Maybe you need to specify a java.security.auth.login.config (I have not experienced any of that myself, only thing I can offer is you scroll to the bottom of this post and dive in then edit your question with where you got to and what config you have)
Metabase SQL Server setup using Kerberos:
For background, current (August 2018) very long :| sum up with lots of links of how to connect to SQL Server is here in a Metabase discussion topic Note: In v0.30.0 an issue with dynamic port handling (particularly for people using named instances) was fixed.
Related: A neat StackOverflow answer on Kerberos on a Mac
If you are connecting to a "Named Instance" ({SERVER_NAME}/{INSTANCE_NAME}) instead of "Default Instance" ({SERVER_NAME}), your server may be configured to use Dynamic Port.
A quick dirty fix is you can find the current port with below scripts and then use it on Metabase connection parameters. But this port most probably will change when service restart occurs.
SELECT DISTINCT
local_tcp_port
FROM sys.dm_exec_connections
WHERE local_tcp_port IS NOT NULL
or
USE master
GO
Xp_readerrorlog
(look for "Server is listening on ..." line)
A Cleaner way is setting port for your instance by "SQL Server Configuration Manager" - "SQL Server Network Configuration" - "TCP/IP" - Right Click properties - "TCP Dynamic Ports" (There should be 0 and it should be deleted) and "TCP Port" (New default port should be set here). And also "SQL Server Browser" service should run. A more detailed explanation is here

Weblogic 11g: Managed Server is not starting from Weblogic console

i have some strange situation:
When i am trying to start managed server on the console i get the following error on Nodemanager:
PM weblogic.nodemanager.server.Handler run
WARNING: I/O error while closing socket connection
java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:135)
at java.net.SocketInputStream.read(SocketInputStream.java:122)
at weblogic.utils.io.ChunkedInputStream.read(ChunkedInputStream.java:159)
at weblogic.security.SSL.jsseadapter.JaSSLEngineRunner$Context.fillBufferNetIn(JaSSLEngineRunner.java:323)
at weblogic.security.SSL.jsseadapter.JaSSLEngineRunner$Transition_NeedUnwrap.getNextState(JaSSLEngineRunner.java:822)
at weblogic.security.SSL.jsseadapter.JaSSLEngineRunner.doTransitions(JaSSLEngineRunner.java:763)
at weblogic.security.SSL.jsseadapter.JaSSLEngineRunner.closeInbound(JaSSLEngineRunner.java:1279)
at weblogic.security.SSL.jsseadapter.JaSSLEngineRunner.close(JaSSLEngineRunner.java:1365)
at weblogic.security.SSL.jsseadapter.JaAbstractSSLSocket.close(JaAbstractSSLSocket.java:245)
at weblogic.nodemanager.server.Handler.run(Handler.java:85)
at java.lang.Thread.run(Thread.java:745)
But when i am trying to start Managed Servers from command-line then it works correctly:
nohup ./startManagedWebLogic.sh server1 t3://xx.xx.xx.xx:7001 >/dev/null 2>&1 &
In oracle Documentation i found that this issue can happen when in nodemanager.properties file the following line is set to false:
NativeVersionEnabled=false
After i set it to true the issue is still persists.
The issue started after i did an Upgrade for Java from java jrockit to java JDK 1.80. I have also changed the certificates from Demo to custom.
Did someone had this issue before and knows how to fix it?
In the nodemanager.properties file set the SecureListener attribute to false.
In the weblogic server admin console, configure the machine to not use a secured connection with the node manager (Node Manager tab)
These 2 options configure a non secured connection between the admin server and the node manager.

Apache Tez configuration with hadoop

Here is what I have done in a nutshell:
STEP1: I have successfully configured hadoop 2.6 on my laptop (single node) and ran a sample mapreduce job.
STEP2: I cloned tez repository and successfully built the 0.8.0 version and copied the jarfiles into HDFS and exports the required variables. I also changed the value of variable mapreduce.framework.name to yarn-tez in the mapred-site.xml.
But when I want to run a tez orderedwordcount job, I got this error:
15/07/04 18:45:03 INFO ipc.Client: Retrying connect to server: hostname/hostIP:57339.
Already tried 9 time(s); retry policy is RetryUpToMaximumCountWithFixedSleep(maxRetries=10, sleepTime=1000 MILLISECONDS)
15/07/04 18:45:12 INFO client.DAGClientImpl: DAG completed. FinalState=FAILED
I have checked resource manager and it is listening on port 8030.
But it seems the client tries to connect to a random port. is it correct?
What can I do to get it work correctly?
It seems that it was the problem of this version (0.8.0) connecting to the resource manager. I compiled and integrated the previous stable release (0.7.0) and everything is good to go now. I hope that they will figure the problem out.
From your logs it seems a Firewall issue rather than issue with Tez version. And it is irrespective of Tez, even if you run Hadoop only you can face this.
Hadoop uses multiple ports for communication with clients and between service components. To enable Hadoop communication, open the specific ports that Hadoop uses.
To open specific ports, you can set the access rules in Windows. For example, the following command will open up port 80 in the active Windows Firewall:
netsh advfirewall firewall add rule name=AllowRPCCommunication dir=in action=allow protocol=TCP localport=80
For more see here http://docs.hortonworks.com/HDPDocuments/HDP2/HDP-2.3.0-Win/bk_HDP_Install_Win/content/ref-79239257-778e-42a9-9059-d982d0c08885.1.html

Categories

Resources