PostgreSQL,通常称为 Postgres,是一种开源关系数据库管理系统 (RDBMS)。它以其可扩展性、对 SQL 标准的遵守以及对各种数据类型的支持而闻名。
在 Fedora 39 上安装 PostgreSQL
步骤 1。在开始安装之前,请确保您的 Fedora 39 系统是最新的。执行以下命令:
<span class="pln">sudo dnf clean all sudo dnf update</span>
第2步。在 Fedora 39 上安装 PostgreSQL。
添加 PostgreSQL 存储库对 Fedora 39 用户至关重要。请按照下列步骤操作:
<span class="pln">sudo dnf install https</span><span class="pun">:</span><span class="com">//download.postgresql.org/pub/repos/yum/reporpms/F-39-x86_64/pgdg-fedora-repo-latest.noarch.rpm</span>
此命令将安装存储库配置包,这对于将 PostgreSQL 包拉入系统至关重要。
现在存储库已经设置好了,是时候安装 PostgreSQL 了。用于安装 PostgreSQL 服务器和客户端软件包:dnf
<span class="pln">sudo dnf install postgresql16</span><span class="pun">-</span><span class="pln">server</span>
安装后,初始化 PostgreSQL 数据库:
<span class="pln">sudo </span><span class="pun">/</span><span class="pln">usr</span><span class="pun">/</span><span class="pln">pgsql</span><span class="pun">-</span><span class="lit">16</span><span class="pun">/</span><span class="pln">bin</span><span class="pun">/</span><span class="pln">postgresql</span><span class="pun">-</span><span class="lit">16</span><span class="pun">-</span><span class="pln">setup initdb</span>
接下来,启动并启用 PostgreSQL 服务:
<span class="pln">sudo systemctl enable postgresql</span><span class="pun">-</span><span class="lit">16</span><span class="pln"> sudo systemctl start postgresql</span><span class="pun">-</span><span class="lit">16</span>
第 3 步。安装设置。
保护 PostgreSQL 安装涉及创建超级用户帐户和密码。访问 PostgreSQL 提示符:
<span class="pln">sudo </span><span class="pun">-</span><span class="pln">i </span><span class="pun">-</span><span class="pln">u postgres psql</span>
在 PostgreSQL 提示符下,创建一个新的超级用户:
<span class="pln">CREATE ROLE your_user WITH SUPERUSER LOGIN PASSWORD </span><span class="str">'your_strong_password'</span><span class="pun">;</span>
将“”和“”替换为所需的用户名和密码。your_user
your_password
为确保安装成功,请尝试连接到 PostgreSQL 服务器:
<span class="pln">psql </span><span class="pun">-</span><span class="pln">U your_user </span><span class="pun">-</span><span class="pln">d postgres</span>
第 4 步。配置防火墙。
在 Fedora 上为 PostgreSQL 设置防火墙涉及允许 PostgreSQL 端口(通常为 5432)上的流量,同时阻止未经授权的访问。以下是配置防火墙的步骤:
<span class="pln">sudo firewall</span><span class="pun">-</span><span class="pln">cmd </span><span class="pun">--</span><span class="pln">zone</span><span class="pun">=</span><span class="kwd">public</span> <span class="pun">--</span><span class="kwd">add</span><span class="pun">-</span><span class="pln">port</span><span class="pun">=</span><span class="lit">5432</span><span class="pun">/</span><span class="pln">tcp </span><span class="pun">--</span><span class="pln">permanent</span>
此命令为公共区域上的 TCP 流量打开端口 5432。该标志使规则在重新启动后保持不变。--permanent
重新加载防火墙以应用更改:
<span class="pln">sudo firewall</span><span class="pun">-</span><span class="pln">cmd </span><span class="pun">--</span><span class="pln">reload</span>
检查规则是否添加成功:
<span class="pln">sudo firewall</span><span class="pun">-</span><span class="pln">cmd </span><span class="pun">--</span><span class="pln">zone</span><span class="pun">=</span><span class="kwd">public</span> <span class="pun">--</span><span class="pln">list</span><span class="pun">-</span><span class="pln">ports</span>
感谢您使用本教程在 Fedora 39 系统上安装 PostgreSQL 数据库。有关其他 Apache 或有用信息,我们建议您查看 PostgreSQL 官方网站。