我遵循本教程:https://linode.com/docs/databases/postgresql/create-a-highly-available-postgresql-cluster-using-patroni-and-haproxy/,以便使用Patroni和HAProxy设置高度可用的PostgreSQL集群。
但是当我尝试启动patroni时,我收到了这个错误:
ubuntu@sudo patroni /etc/patroni.yml
2018-05-31 09:49:37,159 INFO: Failed to import patroni.dcs.consul
2018-05-31 09:49:37,166 INFO: Selected new etcd server http://privateetcdIP:2379
2018-05-31 09:49:37,173 INFO: Lock owner: None; I am postgresqlm
2018-05-31 09:49:37,175 INFO: trying to bootstrap a new cluster
pg_ctl: cannot be run as root
Please log in (using, e.g., "su") as the (unprivileged) user that will
own the server process.
2018-05-31 09:49:37,185 INFO: removing initialize key after failed attempt to bootstrap the cluster
2018-05-31 09:49:37,673 INFO: Lock owner: None; I am postgresqlm
Traceback (most recent call last):
File "/usr/local/bin/patroni", line 9, in <module>
load_entry_point('patroni==1.4.4', 'console_scripts', 'patroni')()
File "/usr/local/lib/python2.7/dist-packages/patroni/__init__.py", line 176, in main
return patroni_main()
File "/usr/local/lib/python2.7/dist-packages/patroni/__init__.py", line 145, in patroni_main
patroni.run()
File "/usr/local/lib/python2.7/dist-packages/patroni/__init__.py", line 114, in run
logger.info(self.ha.run_cycle())
File "/usr/local/lib/python2.7/dist-packages/patroni/ha.py", line 1164, in run_cycle
info = self._run_cycle()
File "/usr/local/lib/python2.7/dist-packages/patroni/ha.py", line 1077, in _run_cycle
return self.post_bootstrap()
File "/usr/local/lib/python2.7/dist-packages/patroni/ha.py", line 976, in post_bootstrap
self.cancel_initialization()
File "/usr/local/lib/python2.7/dist-packages/patroni/ha.py", line 971, in cancel_initialization
raise PatroniException('Failed to bootstrap cluster')
/etc/patroni.yml
的配置是:
scope: postgres
namespace: /db/
name: postgresqlm
restapi:
listen: privateIPoffirstnode:8008
connect_address: privateIPoffirstnode:8008
etcd:
host: privateIPofetcd:2379
bootstrap:
dcs:
ttl: 30
loop_wait: 10
retry_timeout: 10
maximum_lag_on_failover: 1048576
postgresql:
use_pg_rewind: true
max_connections: 100
initdb:
- encoding: UTF8
- data-checksums
pg_hba:
- host replication replicator 127.0.0.1/32 md5
- host replication replicator privateIPoffirstnode/0 md5
- host replication replicator privateIPofsecondnode/0 md5
- host replication replicator privateIPofthirdnode/0 md5
- host all all 0.0.0.0/0 md5
users:
admin:
password: admin
options:
- createrole
- createdb
postgresql:
listen: privateIPoffirstnode:5432
connect_address: privateIPoffirstnode:5432
data_dir: /data/patroni
pgpass: /tmp/pgpass
bin_dir: /usr/lib/postgresql/9.5/bin
authentication:
replication:
username: replicator
password: rep-pass
superuser:
username: postgres
password: '12345'
parameters:
unix_socket_directories: '.'
tags:
nofailover: false
noloadbalance: false
clonefrom: false
nosync: false
/etc/systemd/system/patroni.service
的配置是:
[Unit]
Description=Runners to orchestrate a high-availability PostgreSQL
After=syslog.target network.target
[Service]
Type=simple
User=postgres
Group=postgres
ExecStart=/usr/local/bin/patroni /etc/patroni.yml
KillMode=process
TimeoutSec=30
Restart=no
[Install]
WantedBy=multi-user.targ
etcd congiguration:
ETCD_LISTEN_PEER_URLS="http://privateIPofetcd:2380"
ETCD_LISTEN_CLIENT_URLS="http://localhost:2379,http://privateIPofetcd:2379"
ETCD_INITIAL_ADVERTISE_PEER_URLS="http://privateIPofetcd:2380"
ETCD_INITIAL_CLUSTER="etcd0=http://privateIPofetcd:2380,"
ETCD_ADVERTISE_CLIENT_URLS="http://privateIPofetcd:2379"
ETCD_INITIAL_CLUSTER_TOKEN="cluster1"
ETCD_INITIAL_CLUSTER_STATE="new"
当然,我在privateIPoffirstnode,privateIPofsecondnode等中拥有真正的ips。
那么,有谁知道这个错误意味着什么?
答案 0 :(得分:1)
我认为答案很明显。如果您使用sudo
启动patroni,它将以root身份运行,这正是您收到的错误消息。
为什么不通过systemctl
启动它?您的/etc/systemd/system/patroni.service
已正确配置了User
的{{1}}。
答案 1 :(得分:0)
按照this指南配置高可用性Postgresql集群。
它已经过全面测试并且可以正常工作。