【问题标题】:Kettle, JDBC, MySQL, SSL: Could not Connetct to databaseKettle、JDBC、MySQL、SSL:无法连接到数据库
【发布时间】:2015-06-26 14:15:20
【问题描述】:

我正在尝试使用客户端证书通过 SSL 连接到 MySQL 数据库。我已经使用 CA 证书创建了一个信任库:

keytool -import -alias mysqlServerCACert -file ca.crt -keystore truststore

然后我用我的私钥和我的客户端证书创建了一个密钥库:

openssl pkcs12 -export -out bi.pfx -inkey bi.key -in bi.crt -certfile ca.crt
openssl x509 -outform DER -in bi.pem -out bi.der
keytool -importkeystore -file bi.der -keystore keystore -alias mysqlClientCertificate

我在 jdbc URL 中添加了 useSSL=true 和 requireSSL=true 并通过了

 -Djavax.net.ssl.keyStore=${db.keyStore}
 -Djavax.net.ssl.keyStorePassword=${db.keyStore.pwd}
 -Djavax.net.ssl.trustStore=${db.trustStore}
 -Djavax.net.ssl.trustStorePassword=${db.keyStore.pwd}

从周边工作到水壶改造。我仍然收到“无法创建与数据库服务器的连接”。

我可以使用命令行工具通过 SSL 连接:

 mysql --protocol=tcp -h myqlhost -P 3309 -u bi -p --ssl=on --ssl-ca=ca.crt --ssl-cert=bi.crt --ssl-key=bi.key db_name

因此,我目前的猜测是,SSL 证书存在问题。

有没有办法让 MySQL JDBC Driver 告诉我更多细节,出了什么问题?

我的假设是错误的,可以使用水壶参数设置系统属性吗?那我该怎么做呢?

【问题讨论】:

  • 您的 JDBC 代码在哪里?我看到 ${...}。不是真正的 JDBC 连接字符串。
  • @Norbert van Nobelin:这些是存在于作业中的水壶变量,作业将它们作为参数传递给转换,如我的问题中所述。
  • 这是一个 JDBC 连接字符串:jdbc:pdi://hostname:port/kettle?option=value&option=value 您此时显示的内容还不够清楚相关:您的语言是什么作业代码调用Java代码?您能否将您的 ${...} 变量回显到命令提示符或日志以查看它们是否包含正确的信息?
  • @Norbert van Nobelin:当然我已经多次重新检查了变量的内容。我不知道如何查看它们在转换中是否仍然正确,以及它们是否是我所期望的:命令行参数。在 Kettle 文档中,我找不到任何解释。它创建的 JDBC url 是“jdbc:mysql://mysqlhost:3309/dbname?useSSL=true&requireSSL=true”

标签: mysql ssl jdbc pentaho kettle


【解决方案1】:

建立从 Pentaho (PDI Kettle) 到 AWS (RDS) Aurora / MySQL 的安全连接 (SSL)

1. You need to create a new user id and Grant SSL rights to it. So this user id can connect to Aurora / MySQL only using Secured connection.
GRANT USAGE ON *.* TO 'admin'@'%' REQUIRE SSL
2. Download public RDS key (.pem fie) from AWS  (http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_Aurora.html#Aurora.Overview.Security.SSL)
3. Downloaded file contains certificates / keys for each region. 
4. Split certificates from .PEM file into different .PEM files 
5. Use JDK keytool command utility to import all these PEM files into a single truststore (xyz.jks) file
    a. keytool -import -alias xyz.jks -file abc1.pem -keystore truststore
6. Configure JNDI entry for your Aurora / MySQL instance in Pentaho Properties File "data-integration\simple-jndi\jdbc.properties"
    a. Sample JNDI configuration 
    -------------------------------------------------------------------------
    RDSSecured/type=javax.sql.DataSource
    RDSSecured/driver=com.mysql.jdbc.Driver
    RDSSecured/user=admin
    RDSSecured/password=password
    RDSSecured/url=jdbc:mysql://REPLACE_WITH_RDS_ENDPOINT_HERE:3306/DATABASE_NAME?verifyServerCertificate=true&useSSL=true&requireSSL=true
    -------------------------------------------------------------------------
7. Make sure you copied MySQL connector jar in "lib" directory of your pentaho installation. Use connector version 5.1.21 or higher.
8. 
9. Create a copy of Spoon.bat / Spoon.sh based on your operating system E.g. Spoon_With_Secured_SSL_TO_RDS.bat or Spoon_With_Secured_SSL_TO_RDS.sh
10. Now we need to pass the truststore details to Pentaho at startup, so edit the copied script and append below mentioned arguments to OPT variable 
    a. -Djavax.net.ssl.trustStore="FULL_PATH\xyz.jks"
    b. -Djavax.net.ssl.trustStorePassword="YOUR_TRUSTSTORE_PASSWORD"
11. Use new script to start Spoon here after to establish the secure connection
12. Open/create your Job / Transformation
13. Go To View Tab - Database Connections and create new connection
    a. Connection Type: MySQL
    b. Access: JNDI
    c. JNDI Name: RDSSecured 
        i. Same as name used in JDBC.properties file
14. Test Connection and you are ready…. :)

【讨论】:

    【解决方案2】:

    好的,这是我现在找到的解决方案:

    各种kettle 工具的启动脚本通过读取环境变量“OPT”将参数传递给JVM。所以我设置了

    export OPT="-Djavax.net.ssl.keyStore=/path/to/keystore -Djavax.net.ssl.keyStorePassword=private -Djavax.net.ssl.trustStore=/path/to/truststore -Djavax.net.ssl.trustStorePassword=private"
    

    现在 MySQL JDBC 驱动程序找到它的证书和私钥并可以建立连接。

    【讨论】:

      猜你喜欢
      • 2014-12-09
      • 1970-01-01
      • 1970-01-01
      • 2018-11-30
      • 2013-06-03
      • 2015-04-01
      • 1970-01-01
      • 2018-09-13
      • 1970-01-01
      相关资源
      最近更新 更多