如果通过 systemctl 启动 postgres 数据库,则访问该数据库的权限将被拒绝

如果通过 systemctl 启动 postgres 数据库,则访问该数据库的权限将被拒绝

我在 CentOS 服务器上运行的 postgres 数据库出现问题,但只有通过 systemctl 启动它时才会出现问题。

我的服务配置:

Description=Nakama server


[Service]
ExecStart=/etc/nakama/nakama --config /etc/nakama/config.yml
KillMode=process


[Install]
WantedBy=multi-user.target

我收到的服务错误:

[xxx@xxx] [/dev/pts/0] [03:38@2022/09/02]
[~]> sudo systemctl restart nakama.service
[xxx@xxx] [/dev/pts/0] [03:38@2022/09/02]
[~]> sudo systemctl status nakama.service -l
× nakama.service - Nakama server
     Loaded: loaded (/usr/lib/systemd/system/nakama.service; enabled; vendor preset: disabled)
     Active: failed (Result: exit-code) since Fri 2022-09-02 03:38:32 CEST; 3s ago
   Duration: 19ms
    Process: 28216 ExecStart=/etc/nakama/nakama --config /etc/nakama/config.yml (code=exited, status=1/FAILURE)
   Main PID: 28216 (code=exited, status=1/FAILURE)
        CPU: 15ms

Sep 02 03:38:32 pserZUR01 systemd[1]: Started Nakama server.
Sep 02 03:38:32 pserZUR01 nakama[28216]: {"level":"info","ts":"2022-09-02T03:38:32.275+0200","caller":"server/config.go:86","msg":"Successfully loaded config file","path":"/etc/nakama/config.yml"}
Sep 02 03:38:32 pserZUR01 nakama[28216]: {"level":"info","ts":"2022-09-02T03:38:32.276+0200","caller":"v3/main.go:104","msg":"Nakama starting"}
Sep 02 03:38:32 pserZUR01 nakama[28216]: {"level":"info","ts":"2022-09-02T03:38:32.277+0200","caller":"v3/main.go:105","msg":"Node","name":"nw-nakama-node1","version":"3.13.1+2000e4b8","runtime":"go1.19","cpu":2,"proc":2}
Sep 02 03:38:32 pserZUR01 nakama[28216]: {"level":"info","ts":"2022-09-02T03:38:32.277+0200","caller":"v3/main.go:106","msg":"Data directory","path":"/etc/nakama/data/"}
Sep 02 03:38:32 pserZUR01 nakama[28216]: {"level":"info","ts":"2022-09-02T03:38:32.277+0200","caller":"v3/main.go:125","msg":"Database connections","dsns":["postgres:[email protected]:5432"]}
Sep 02 03:38:32 pserZUR01 nakama[28216]: {"level":"fatal","ts":"2022-09-02T03:38:32.277+0200","caller":"server/db.go:73","msg":"Error pinging database","error":"failed to connect to `host=127.0.0.1 user=postgres database=nakama`: dial error (dial tcp 127.0.0.1:5432: connect: permission de>
Sep 02 03:38:32 pserZUR01 systemd[1]: nakama.service: Main process exited, code=exited, status=1/FAILURE
Sep 02 03:38:32 pserZUR01 systemd[1]: nakama.service: Failed with result 'exit-code'.

如果我手动启动它,它会成功:

[xxx@xxx] [/dev/pts/0] [130][03:49@2022/09/02]
[~]> sudo /etc/nakama/nakama --config /etc/nakama/config.yml
{"level":"info","ts":"2022-09-02T03:50:01.798+0200","caller":"server/config.go:86","msg":"Successfully loaded config file","path":"/etc/nakama/config.yml"}
{"level":"info","ts":"2022-09-02T03:50:01.798+0200","caller":"v3/main.go:104","msg":"Nakama starting"}
{"level":"info","ts":"2022-09-02T03:50:01.798+0200","caller":"v3/main.go:105","msg":"Node","name":"nw-nakama-node1","version":"3.13.1+2000e4b8","runtime":"go1.19","cpu":2,"proc":2}
{"level":"info","ts":"2022-09-02T03:50:01.798+0200","caller":"v3/main.go:106","msg":"Data directory","path":"/etc/nakama/data/"}
{"level":"info","ts":"2022-09-02T03:50:01.798+0200","caller":"v3/main.go:125","msg":"Database connections","dsns":["postgres:[email protected]:5432"]}
{"level":"info","ts":"2022-09-02T03:50:01.803+0200","caller":"v3/main.go:131","msg":"Database information","version":"PostgreSQL 13.7 on x86_64-redhat-linux-gnu, compiled by gcc (GCC) 11.3.1 20220421 (Red Hat 11.3.1-2), 64-bit"}
{"level":"info","ts":"2022-09-02T03:50:01.806+0200","caller":"server/leaderboard_rank_cache.go:117","msg":"Initializing leaderboard rank cache"}
{"level":"info","ts":"2022-09-02T03:50:01.806+0200","caller":"server/leaderboard_rank_cache.go:240","msg":"Leaderboard rank cache initialization completed successfully","cached":[],"skipped":[]}

User=root Group=root我也尝试了和的服务Group=wheel

我的系统信息:

[~]> cat /etc/centos-release
CentOS Stream release 9

[~]> sudo su - postgres
[xxx@xxx ~]$ psql
psql (13.7)

相关内容