在Docker中用Sqoop导入PostgreSQL

我的本地机器上有一个PostgreSQL数据库(Windows),我想用Apache Sqoop把它导入我的Hortonworks Sandbox。 虽然这听起来不错,但是复杂的因素是我的沙盒坐在Docker容器中,所以像sqoop list-tables --connect jdbc:postgresql://127.0.0.1/ambari --username ambari -P这样的语句似乎遇到身份validation错误。 我相信这个问题来自于试图从docker容器内部连接到本地主机。

我在一个容器内部连接到一个MySQL数据库的时候看了这个post ,而这个尝试使用PostgreSQL来代替,但是到目前为止一直没有成功。 我试图连接到“127.0.0.1”和“172.17.0.1”(主机的IP),以便连接到我的本地主机从docker。 我也调整了PostgreSQL的configuration文件来侦听所有IP地址上的连接。 但是,当我运行sqoop list-tables --connect jdbc:postgresql://<ip>:5432/<db_name> --username postgres -P时,我仍然得到以下错误信息sqoop list-tables --connect jdbc:postgresql://<ip>:5432/<db_name> --username postgres -P (其中<ip>127.0.0.1172.17.0.1<db_name>是我的数据库的名称)

用于连接127.0.0.1

 ERROR sqoop.Sqoop: Got exception running Sqoop: java.lang.RuntimeException: org.postgresql.util.PSQLException: FATAL: Ident authentication failed for user "postgres" 

用于连接172.17.0.1

 Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections. 

任何build议将是非常有益的!

如果仅用于本地testing而不用于生产级别编码,则可以通过更新pg_hba.conf文件来启用到数据库的所有可信连接

  1. 在你的postgres data目录中find你的pg_hba.conf文件
  2. Vim文件并用下面的行更新它:

    #TYPE DATABASE USER ADDRESS METHOD local all all trust host all all 0.0.0.0/0 trust host all all ::1/128 trust

  3. 重新启动你的postgres服务

如果你这样做,你的第一个用例(使用127.0.0.1 )应该工作