.pgpass似乎不起作用。你能检查一下我的pgagent设置吗?
OS : centos 7 ( I did NOT disable selinux )
Database : postgresql 9.6.5
pgagent : pgagent_96 3.4.0-9.rhel7 ( installed package using yum )
(几十秒后.)
[frank@web]$ systemctl status pgagent_96.service
● pgagent_96.service - PgAgent for PostgreSQL 9.6
Loaded: loaded (/usr/lib/systemd/system/pgagent_96.service; disabled; vendor preset: disabled)
Active: failed (Result: exit-code) since 2017-10-16 16:42:56 KST; 4min 9s ago
Process: 9507 ExecStart=/usr/bin/pgagent_96 -s ${LOGFILE} hostaddr=${DBHOST} dbname=${DBNAME} user=${DBUSER} port=${DBPORT} (code=exited, status=0/SUCCESS)
Main PID: 9510 (code=exited, status=1/FAILURE)
16 Oct 16:42:11 web.frank.net systemd[1]: Starting PgAgent for PostgreSQL 9.6...
16 Oct 16:42:11 web.frank.net systemd[1]: Started PgAgent for PostgreSQL 9.6.
16 Oct 16:42:56 web.frank.net systemd[1]: pgagent_96.service: main process exited, code=exited, status=1/FAILURE
16 Oct 16:42:56 web.frank.net systemd[1]: Unit pgagent_96.service entered failed state.
16 Oct 16:42:56 web.frank.net systemd[1]: pgagent_96.service failed.
pg_hba.conf含量
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
#local all all peer
local all all md5
# IPv4 local connections:
#host all all 127.0.0.1/32 ident
host all all 122.32.2.21/32 md5 (122.32.2.21 is my server's IP )
# IPv6 local connections:
#host all all ::1/128 ident
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
(1)尝试作为OS用户“root”启动
[root@web frank]# ls -al .pgpass
-rw-------. 1 postgres postgres 43 10월 16 17:08 .pgpass
[root@web frank]# ls -alZ .pgpass
-rw-------. postgres postgres unconfined_u:object_r:user_home_t:s0 .pgpass
[root@web frank]# cat .pgpass
localhost:5432:postgres:postgres:pwd
[root@web frank]# systemctl start pgagent_96 (Here, centos asked frank's OS password )
[root@web frank]# systemctl status pgagent_96
● pgagent_96.service - PgAgent for PostgreSQL 9.6
Loaded: loaded (/usr/lib/systemd/system/pgagent_96.service; disabled; vendor preset: disabled)
Active: failed (Result: exit-code) since 2017-10-16 23:33:15 KST; 3s ago
Process: 25928 ExecStart=/usr/bin/pgagent_96 -s ${LOGFILE} hostaddr=${DBHOST} dbname=${DBNAME} user=${DBUSER} port=${DBPORT} (code=exited, status=0/SUCCESS)
Main PID: 25930 (code=exited, status=1/FAILURE)
16 Oct 23:32:30 web.frank.net systemd[1]: Starting PgAgent for Postgre....
16 Oct 23:32:30 web.frank.net systemd[1]: Started PgAgent for PostgreS....
16 Oct 23:33:15 web.frank.net systemd[1]: pgagent_96.service: main pro...E
16 Oct 23:33:15 web.frank.net systemd[1]: Unit pgagent_96.service ente....
16 Oct 23:33:15 web.frank.net systemd[1]: pgagent_96.service failed.
Hint: Some lines were ellipsized, use -l to show in full.
(2)尝试以OS用户“坦率”的身份开始
[frank@web ~]$ systemctl start pgagent_96 (Here, centos asked frank's OS password )
[frank@web ~]$ systemctl status pgagent_96
● pgagent_96.service - PgAgent for PostgreSQL 9.6
Loaded: loaded (/usr/lib/systemd/system/pgagent_96.service; disabled; vendor preset: disabled)
Active: failed (Result: exit-code) since 월 2017-10-16 23:41:03 KST; 1min 21s ago
Process: 26531 ExecStart=/usr/bin/pgagent_96 -s ${LOGFILE} hostaddr=${DBHOST} dbname=${DBNAME} user=${DBUSER} port=${DBPORT} (code=exited, status=0/SUCCESS)
Main PID: 26533 (code=exited, status=1/FAILURE)
16 Oct 23:40:18 web.frank.net systemd[1]: Starting PgAgent for Postgre....
16 Oct 23:40:18 web.frank.net systemd[1]: Started PgAgent for PostgreS....
16 Oct 23:41:03 web.frank.net systemd[1]: pgagent_96.service: main pro...E
16 Oct 23:41:03 web.frank.net systemd[1]: Unit pgagent_96.service ente....
16 Oct 23:41:03 web.frank.net systemd[1]: pgagent_96.service failed.
Hint: Some lines were ellipsized, use -l to show in full.
(3)尝试以OS用户“postgres”的身份启动
-bash-4.2$ systemctl start pgagent_96 (Here, centos asked frank's OS password )
-bash-4.2$ systemctl status pgagent_96
● pgagent_96.service - PgAgent for PostgreSQL 9.6
Loaded: loaded (/usr/lib/systemd/system/pgagent_96.service; disabled; vendor preset: disabled)
Active: failed (Result: exit-code) since 월 2017-10-16 23:54:22 KST; 21s ago
Process: 27511 ExecStart=/usr/bin/pgagent_96 -s ${LOGFILE} hostaddr=${DBHOST} dbname=${DBNAME} user=${DBUSER} port=${DBPORT} (code=exited, status=0/SUCCESS)
Main PID: 27515 (code=exited, status=1/FAILURE)
(4)“根”、“弗兰克”和“postgres”的安全语境
(根)
[root@web ~]# id
uid=0(root) gid=0(root) groups=0(root) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
(弗兰克)
[frank@web ~]$ id
uid=1000(frank) gid=1000(frank) groups=1000(frank),10(wheel) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
( postgres )
-bash-4.2$ id
uid=26(postgres) gid=26(postgres) groups=26(postgres) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
(1)我在/etc/profile中设置了PGPASSFILE变量。
export PGDATA=/var/lib/pgsql/9.6/data
export PGPASSFILE=/var/lib/pgsql/.pgpass
(2)尝试启动pgagent_96,将.pgpass上下文类型从user_home_t改为postgresql_db_t、bin_t、usr_t,但我也遇到了同样的错误。
-bash-4.2$ echo $PGPASSFILE
/var/lib/pgsql/.pgpass
-bash-4.2$ ls -alZ .pgpass
-rw-------. postgres postgres unconfined_u:object_r:postgresql_db_t:s0 .pgpass
-bash-4.2$ systemctl start pgagent_96
====> failed to start pgAgent_96. same error.
-bash-4.2$ chcon --type bin_t .pgpass
-bash-4.2$ ls -alZ .pgpass
-rw-------. postgres postgres unconfined_u:object_r:bin_t:s0 .pgpass
-bash-4.2$ systemctl start pgagent_96
====> failed to start pgAgent_96. same error.
-bash-4.2$ chcon --type usr_t .pgpass
-bash-4.2$ ls -alZ .pgpass
-rw-------. postgres postgres unconfined_u:object_r:usr_t:s0 .pgpass
-bash-4.2$ systemctl start pgagent_96
====> failed to start pgAgent_96. same error.
pgagent_96、systemd、pg_hba.conf的安全上下文
[root@web frank]# ls -alZ /usr/bin/pgagent_96
-rwxr-xr-x. root root system_u:object_r:bin_t:s0 /usr/bin/pgagent_96
[root@web frank]# ls -alZ /usr/lib/systemd/systemd
-rwxr-xr-x. root root system_u:object_r:init_exec_t:s0 /usr/lib/systemd/systemd
[root@web frank]# ls -alZ /var/lib/pgsql/9.6/data/pg_hba.conf
-rw-------. postgres postgres unconfined_u:object_r:postgresql_db_t:s0 /var/lib/pgsql/9.6/data/pg_hba.conf
我不知道该试试什么。请帮帮我..。
更新
发布于 2018-02-07 16:28:53
我对CentOS 7也有同样的问题。我的解决方案是:
首先,检查服务脚本中的一些变量:
/usr/lib/systemd/system/pgagent_96.service 猫
1)默认情况下,User=pgagent和Group=pgagent --这是.pgpass文件的所有者/组,
你需要一套
chown pgagent:pgagent .pgpass
chmod 0600 .pgpass
2)接下来,将.pgpass文件移动到用户pgagent可以读取该文件的目录中。
(/home/frank对于用户pgagent是不可编辑的,例如,试试postgres安装dir /var/lib/pgsql/9.6或/var/lib/pgsql)
3)检查pgagent_96配置的位置变量,
默认情况下,EnvironmentFile=/etc/pgagent/pgagent_96.conf -您需要编辑这个文件。
下一步,在编辑器中打开pgagent_96.conf并进行更改:
( a)更改变量DBHOST=localhost的值(这很重要)
( b)添加变量PGPASSFILE=/path/your/pgpasfile/..pgpass(PGPASSFILE=/var/lib/pgsql/..pgpass)
在我的例子中,pgagent开始工作时没有问题。
https://stackoverflow.com/questions/46822553
复制相似问题