AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / unix / 问题 / 744896
Accepted
Jérôme MEVEL
Jérôme MEVEL
Asked: 2023-05-04 17:24:25 +0800 CST2023-05-04 17:24:25 +0800 CST 2023-05-04 17:24:25 +0800 CST

使用 systemctl 启动 PostgreSQL 服务时权限被拒绝,但可与 postmaster 一起使用

  • 772

我之前按照此文档安装了 PostgreSQL ,然后使用以下命令卸载了它(我在 Fedora 上)

sudo rm -rf /var/lib/pgsql/
sudo dnf remove postgresql postgresql-server

之后我尝试重新安装它,但将默认端口从更改5432为5433:

sudo dnf install postgresql postgresql-server
sudo postgresql-setup --initdb --unit postgresql --port 5433

该/var/lib/pgsql/data/postgresql.conf文件确实没有port = 5433注释该行

但是当我尝试使用 启动服务时sudo systemctl start postgresql,出现以下错误

Job for postgresql.service failed because the control process exited with error code.
See "systemctl status postgresql.service" and "journalctl -xeu postgresql.service" for details.

以下是文件夹中的日志log:

2023-05-04 10:46:56.034 CEST [6340] LOG:  starting PostgreSQL 15.1 on x86_64-redhat-linux-gnu, compiled by gcc (GCC) 13.0.1 20230117 (Red Hat 13.0.1-0), 64-bit
2023-05-04 10:46:56.034 CEST [6340] LOG:  could not bind IPv6 address "::1": Permission denied
2023-05-04 10:46:56.034 CEST [6340] LOG:  could not bind IPv4 address "127.0.0.1": Permission denied
2023-05-04 10:46:56.034 CEST [6340] WARNING:  could not create listen socket for "localhost"
2023-05-04 10:46:56.034 CEST [6340] FATAL:  could not create any TCP/IP sockets
2023-05-04 10:46:56.036 CEST [6340] LOG:  database system is shut down

postmaster但是,当我在不使用它的情况下启动 PostgreSQL 时

sudo su - postgres
/usr/bin/postmaster -D /var/lib/pgsql/data

这是日志:

2023-05-04 11:08:18.997 CEST [9385] LOG:  starting PostgreSQL 15.1 on x86_64-redhat-linux-gnu, compiled by gcc (GCC) 13.0.1 20230117 (Red Hat 13.0.1-0), 64-bit
2023-05-04 11:08:18.998 CEST [9385] LOG:  listening on IPv6 address "::1", port 5433
2023-05-04 11:08:18.998 CEST [9385] LOG:  listening on IPv4 address "127.0.0.1", port 5433
2023-05-04 11:08:19.000 CEST [9385] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5433"
2023-05-04 11:08:19.002 CEST [9385] LOG:  listening on Unix socket "/tmp/.s.PGSQL.5433"
2023-05-04 11:08:19.009 CEST [9389] LOG:  database system was shut down at 2023-05-04 10:46:43 CEST
2023-05-04 11:08:19.030 CEST [9385] LOG:  database system is ready to accept connections

在/usr/lib/systemd/system我有两个与 PostgreSQL 相关的服务

-rw-r--r--. 1 root root 1546 20 janv. 01:00 postgresql.service
-rw-r--r--. 1 root root 1507 20 janv. 01:00 [email protected]

我检查了内容,对我来说似乎没有什么奇怪的。

在postgresql.conf文件中,如果我将端口更改为5432然后它可以工作,我可以成功启动服务!

我检查了是否有任何东西已经5433在命令中使用该端口netstat -aon | grep 5433,但似乎没有

知道更改默认端口时可能导致此问题的原因是什么吗?我是 Linux 的新手,对服务不熟悉。

谢谢你的回答

fedora
  • 1 1 个回答
  • 24 Views

1 个回答

  • Voted
  1. Best Answer
    Jérôme MEVEL
    2023-05-04T18:36:13+08:002023-05-04T18:36:13+08:00

    好的,结果是 SELinux 阻止了它(又一次!)。

    这是我在 SELinux 日志文件中找到的日志:

    ~ $ sudo grep "postgre" /var/log/audit/audit.log | grep "5433"
    type=AVC msg=audit(1683186096.646:1250): avc:  denied  { name_bind } for  pid=56692 comm="postmaster" src=5433 scontext=system_u:system_r:postgresql_t:s0 tcontext=system_u:object_r:unreserved_port_t:s0 tclass=tcp_socket permissive=0
    

    只有 ports5432和9898SELinux 允许

    ~ $ sudo semanage port -l | grep postgresql
    postgresql_port_t              tcp      5432, 9898
    

    所以我只需要将端口添加5433到列表中:

    ~ $ sudo semanage port -a -t postgresql_port_t 5433 -p tcp
    ~ $ sudo semanage port -l | grep postgresql
    postgresql_port_t              tcp      5433, 5432, 9898
    

    来源

    之后启动服务工作:

    ~ $ sudo systemctl start postgresql
    ~ $ sudo cat /var/lib/pgsql/data/log/postgresql-Thu.log
    2023-05-04 12:34:30.786 CEST [14231] LOG:  starting PostgreSQL 15.1 on x86_64-redhat-linux-gnu, compiled by gcc (GCC) 13.0.1 20230117 (Red Hat 13.0.1-0), 64-bit
    2023-05-04 12:34:30.786 CEST [14231] LOG:  listening on IPv6 address "::1", port 5433
    2023-05-04 12:34:30.786 CEST [14231] LOG:  listening on IPv4 address "127.0.0.1", port 5433
    2023-05-04 12:34:30.788 CEST [14231] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5433"
    2023-05-04 12:34:30.791 CEST [14231] LOG:  listening on Unix socket "/tmp/.s.PGSQL.5433"
    2023-05-04 12:34:30.799 CEST [14235] LOG:  database system was shut down at 2023-05-04 12:34:05 CEST
    2023-05-04 12:34:30.824 CEST [14231] LOG:  database system is ready to accept connections
    
    • 2

相关问题

  • 无法使用 git 克隆 https 网址

  • VirtualBox 无法在 Fedora 26 中安装

  • 使用触摸屏时如何禁用屏幕键盘?

  • 如何找出 nmcli 中缺少的插件?

  • 如何正确分区 SSD 以进行双启动设置

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    模块 i915 可能缺少固件 /lib/firmware/i915/*

    • 3 个回答
  • Marko Smith

    无法获取 jessie backports 存储库

    • 4 个回答
  • Marko Smith

    如何将 GPG 私钥和公钥导出到文件

    • 4 个回答
  • Marko Smith

    我们如何运行存储在变量中的命令?

    • 5 个回答
  • Marko Smith

    如何配置 systemd-resolved 和 systemd-networkd 以使用本地 DNS 服务器来解析本地域和远程 DNS 服务器来解析远程域?

    • 3 个回答
  • Marko Smith

    dist-upgrade 后 Kali Linux 中的 apt-get update 错误 [重复]

    • 2 个回答
  • Marko Smith

    如何从 systemctl 服务日志中查看最新的 x 行

    • 5 个回答
  • Marko Smith

    Nano - 跳转到文件末尾

    • 8 个回答
  • Marko Smith

    grub 错误:你需要先加载内核

    • 4 个回答
  • Marko Smith

    如何下载软件包而不是使用 apt-get 命令安装它?

    • 7 个回答
  • Martin Hope
    user12345 无法获取 jessie backports 存储库 2019-03-27 04:39:28 +0800 CST
  • Martin Hope
    Carl 为什么大多数 systemd 示例都包含 WantedBy=multi-user.target? 2019-03-15 11:49:25 +0800 CST
  • Martin Hope
    rocky 如何将 GPG 私钥和公钥导出到文件 2018-11-16 05:36:15 +0800 CST
  • Martin Hope
    Evan Carroll systemctl 状态显示:“状态:降级” 2018-06-03 18:48:17 +0800 CST
  • Martin Hope
    Tim 我们如何运行存储在变量中的命令? 2018-05-21 04:46:29 +0800 CST
  • Martin Hope
    Ankur S 为什么 /dev/null 是一个文件?为什么它的功能不作为一个简单的程序来实现? 2018-04-17 07:28:04 +0800 CST
  • Martin Hope
    user3191334 如何从 systemctl 服务日志中查看最新的 x 行 2018-02-07 00:14:16 +0800 CST
  • Martin Hope
    Marko Pacak Nano - 跳转到文件末尾 2018-02-01 01:53:03 +0800 CST
  • Martin Hope
    Kidburla 为什么真假这么大? 2018-01-26 12:14:47 +0800 CST
  • Martin Hope
    Christos Baziotis 在一个巨大的(70GB)、一行、文本文件中替换字符串 2017-12-30 06:58:33 +0800 CST

热门标签

linux bash debian shell-script text-processing ubuntu centos shell awk ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve