Sqoop如何使用SSL加密访问MySQL

How could Sqoop use SSL encryption to access MySQL

目前我们需要使用 Sqoop 建立基于 SSL 的连接,以将数据从 MySQL 提取到 HDFS。根据AWS和Sqoop的相关文档,我们完成了以下命令的拼接:

sqoop-import \
--connect "jdbc:mysql://remote-db.amazonaws.com.cn:3306/TSTWOWDB?verifyServerCertificate=false&useSSL=true&requireSSL=true&sslMode=VERIFY_IDENTITY&trustCertificateKeyStoreUrl=/home/etl/ivan/ssl/clientkeystore.jks&trustCertificateKeyStorePassword=xxxxxx" \
--username "TEST_USER" --password "xxxxxx" \
--table "t_wrong_qrcodes" \
--target-dir /tmp/ivan/t_wrong_qrcodes \
-m 1

属性中'/home/etl/ivan/ssl/clientkeystore.jks'为提交服务器的本地文件路径

任务启动后报如下错误:Caused by: java.io.FileNotFoundException: /mnt/home/etl/ivan/ssl/clientkeystore.jks (No such file or directory),好像是因为Sqoop启动了Map-Reduce任务,但是没有这个文件路径'/mnt/home/etl/ivan/ssl/clientkeystore .jks' 在每个计算节点上。

如何设置准确的属性,是否有操作丢失?

Sqoop 版本 - 1.4.7

参考文献:

  1. https://docs.amazonaws.cn/en_us/emr/latest/ReleaseGuide/emr-sqoop-considerations.html
  2. https://sqoop.apache.org/docs/1.4.7/SqoopUserGuide.html
  3. Warning about SSL connection when connecting to MySQL database

至此,我们已经解决了。注意以下三点:

  • 将名为jks 文件的信任存储文件同步到每个计算节点。如果您使用的是 Aws 或其他云服务,则应将信任存储文件放入所有节点,如果您使用的是实例队列,则包括任务节点。
  • 属性 trustCertificateKeyStoreUrl 应该是有效的 url 可以以 file:/ 开头,例如 trustCertificateKeyStoreUrl=file:/home/hadoop/ssl/clientkeystore.jks
  • 将属性 useSSL 设置为 true,否则不会使用 SSL 加密连接进行转换。