【问题标题】:PostgreSQL - FATAL: Ident authentication failed for userPostgreSQL - 致命:用户的身份验证失败
【发布时间】:2018-10-09 15:36:06
【问题描述】:

我在数据库mytestdb 中创建了一个名为employees 的简单表

我想将此表导入 hdfs。

bin/sqoop import --connect 'jdbc:postgresql://127.0.0.1/mytestdb' --username user -P --table employees --target-dir /user/postgres

但是,我一直收到错误消息:

警告:连接到 127.0.0.1:5432 时发生 SQLException org.postgresql.util.PSQLException:致命:身份验证失败 对于用户“用户” org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:473)

/var/lib/pgsql/data/pg_hba.conf设置如下:

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     md5
# IPv4 local connections:
host    all             all             127.0.0.1/32            ident
# IPv6 local connections:
host    all             all             ::1/128                 ident
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local   replication     postgres                                peer
#host    replication     postgres        127.0.0.1/32            ident
#host    replication     postgres        ::1/128                 ident

【问题讨论】:

    标签: postgresql centos centos7 sqoop


    【解决方案1】:

    我从网络上几个不同来源的组合中找到了一个可行的解决方案。

    编辑配置文件

    nano /var/lib/pgsql/data/pg_hba.configuration
    

    将前两个ident 替换为 md5,如下所示:

    # TYPE  DATABASE        USER            ADDRESS                 METHOD
    
    # "local" is for Unix domain socket connections only
    local   all             all                                     md5
    # IPv4 local connections:
    host    all             all             127.0.0.1/32            md5
    # IPv6 local connections:
    host    all             all             ::1/128                 md5
    # Allow replication connections from localhost, by a user with the
    # replication privilege.
    #local   replication     postgres                                peer
    #host    replication     postgres        127.0.0.1/32            ident
    #host    replication     postgres        ::1/128                 ident
    

    保存文件。

    然后,重启服务器

    sudo systemctl restart postgresql
    

    最后,grant all privileges on database testdb to hduser;

    【讨论】:

    • 啊,谢谢。新用户的更新:您可能需要 sudo service postgresql-XX.service restart(其中 XX 是您的 Postgres 版本,在我的情况下为 11)而不是 sudo systemctl restart postgresql
    • 在某些版本中,该文件位于 nano /var/lib/pgsql/data/pg_hba.conf
    【解决方案2】:

    查看日志文件(对于 CentOS,可能在 /var/lib/pgsql/data/pg_log)以获取更多详细信息。

    如果用户不存在,则创建它。使用psql,您可以create a user 点赞:

    create role hduser with login, superuser;
    

    或来自command line

    createuser -s -e hduser
    

    如果identd没有安装,请安装:

    yum install authd xinetd
    

    然后编辑/etc/xinet.d/auth并将disable = yes更改为disable = no

    service auth 
    { 
            disable = no 
            socket_type = stream 
            ....
    }
    

    然后重启xinetd服务:

    systemctl restart xinetd
    

    【讨论】:

    • 您的服务器是否在 tcp 端口 113 上运行 identd? postgres 日志说什么(在 centos 上,可能是 /var/lib/pgsql/data/logs)?
    • 我怎么知道 identd 正在运行?我没有/var/lib/pgsql/data/logs,但是有/var/lib/pgsql/data/pg_log,然后是今天的日志:这个目录下的postgresql-Sun.log
    • 那是正确的日志,有什么有用的吗?检查 identd 是否使用 service identd statusps afx | grep identdtelnet localhost 113netstat -a 等命令运行
    • 我怎么知道 identd 正在运行? telnet localhost 113#ftfy
    猜你喜欢
    • 2013-07-23
    • 2013-02-24
    • 2021-10-21
    • 2015-02-17
    • 2011-02-25
    • 1970-01-01
    • 2018-02-04
    • 2016-09-20
    • 2016-03-01
    相关资源
    最近更新 更多