微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在 Windows 10 上打开 SSL 时 PostgreSQL 无法工作

如何解决在 Windows 10 上打开 SSL 时 PostgreSQL 无法工作

我不确定这个话题是否适合这里,但我不知道在哪里问。

我正在尝试在 Windows10 上打开 Postgresql 10.16 的 SSL。

我阅读了很多关于为 Postgresql 创建 SSL 证书的文档,但在 Windows 10 上花费的文档很少,也没有详细说明。

这些是我做的步骤:

步骤 1,我从

下载 Windows 的 OpenSSL 版本

https://slproweb.com/products/Win32OpenSSL.html

并使用路径 C:\OpenSSL-Win64 安装它,设置系统变量。

第 2 步,我使用 cmd run 作为管理员通过命令行创建服务器密钥:

genrsa -out server.key 4096

,对私钥文件设置适当的权限和所有者(此处https://stackoverflow.com/a/51463654

icacls server.key /reset
icacls server.key /inheritance:r /grant:r "CREATOR OWNER:F"

在这个命令行中得到了来自 cmd.exe 的响应

C:\WINDOWS\system32>icacls server.key /reset
processed file:  server.key
Successfully processed 1 file; Failed processing 0 files

C:\WINDOWS\system32>icacls server.key /inheritance:r /grant:r "CREATOR OWNER:F"
processed file:  server.key
Successfully processed 1 files; Failed processing 0 files

继续创建服务器证书:

req -new -x509 -days 1826 -key server.key -out server.crt

第三步,由于我是自签名的,所以我使用服务器证书作为受信任的根证书,所以我有3个文件:服务器密钥、服务器crt和根crt(这是一个服务器crt的副本)

我把这三个文件剪切到 C:\Program Files\Postgresql\10\data

第 4 步,我正在设置 postgresql.conf:

listen_addresses = '*'
port = 5432
ssl=on
ssl_cert_file = 'server.crt'
ssl_key_file = 'server.key'
ssl_ca_file = 'root.crt'

并在 pg_hba.conf 末尾添加命令行:

# IPv4 remote connections for authenticated users
hostssl   all     postgres             0.0.0.0/0            md5 clientcert=1

最后,当我重新启动 Postgresql 时出现如下错误

The Postgresql -x64-10 -Postgresql Server 10 service on the Local Computer started and then stopped. Some services stop automatically if they are not in use by other services or programs.

在我的 Postgresql 日志中:

2021-03-28 16:35:44.735 +07 [7624] LOG:  database system was shut down at 2021-03-28 16:34:51 +07

2021-03-28 16:35:45.099 +07 [7044] LOG:  database system is ready to accept connections

2021-03-28 17:39:37.827 +07 [7044] LOG:  received fast shutdown request

2021-03-28 17:39:37.834 +07 [7044] LOG:  aborting any active transactions

2021-03-28 17:39:37.839 +07 [7044] LOG:  worker process: logical replication launcher (PID 7972) exited with exit code 1

2021-03-28 17:39:37.843 +07 [7880] LOG:  shutting down

2021-03-28 17:39:37.877 +07 [7044] LOG:  database system is shut down

我怀疑 Postgresql 没有读取我放在其数据目录中的 3 个文件

我参考了这些文件

https://www.howtoforge.com/postgresql-ssl-certificates

chmod og-rwx server.key in windows

https://www.postgresql.org/docs/10/ssl-tcp.html

我已经被它弄乱了很多天,我不知道如何解决这个问题。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。