postgresql_cluster icon indicating copy to clipboard operation
postgresql_cluster copied to clipboard

Support Consul for distributed consensus

Open RashadAnsari opened this issue 4 years ago • 4 comments

Can you please support Consul as a distributed consensus store?

RashadAnsari avatar Jan 04 '21 14:01 RashadAnsari

any update about supporting consul please

asobeeh avatar Mar 21 '21 13:03 asobeeh

I do not plan to implement and maintain code to deploy the Consul cluster, instead we can use this playbook https://github.com/ansible-community/ansible-consul I will add variables to configure interaction with the Consul. In addition, we need to configure the connection with Consul and test the operation of these components: confd for the [Type A] schema, vip-manager for the [Type B] schema (if variable cluster_vip is specified).

I'll do it right away as soon as I can allocate more time. I appreciate any help.

vitabaks avatar Mar 23 '21 11:03 vitabaks

Thanks For your update, and for your info i installed consul cluster manually and changed that in patroni.yml file the part of etcd: hosts with consul and changed with consul ports and restarted patroni and worked with no issues. as I faced an issues with etcd and could not solve it so I changed to consul

asobeeh avatar Mar 23 '21 11:03 asobeeh

as I faced an issues with etcd and could not solve it so I changed to consul

etcd is very reliable, usually there are no problems with it. If you encountered a problem, do not hesitate to open a new issue.

vitabaks avatar Mar 23 '21 13:03 vitabaks

I’m studying the work of Consul Service Discovery with DNS resolving and I’m starting to like it.

It is convenient to search for the master and replicas (without using vip-manager or haproxy) example: master.patroni.service.consul and replica.patroni.service.consul as a client access point. But it requires the installation of a consul in client mode on each application server for service DNS resolution (or check forward DNS to the remote consul server instead of installing a local consul client). Nevertheless, it can be useful for a distributed cluster across different data centers. We can specify in advance which data center the database server is located in and then use this for applications running in the same data center. Example:

  • replica.patroni.service.dc1.consul
  • replica.patroni.service.dc2.consul

And, we can add any custom checks so that the service is considered healthy and the DNS record for this service is active.

I'm thinking of adding a new type of schema: "[Type C] PostgreSQL High-Availability with Consul Service Discovery (DNS)" based on "Patroni" and "Consul".

I'm thinking of doing it!

vitabaks avatar Dec 28 '22 22:12 vitabaks

@RashadAnsari @gc-ss

PR: https://github.com/vitabaks/postgresql_cluster/pull/238

To test, follow these steps:

# 1. clone this repository from branch "consul"
git clone --branch consul --single-branch https://github.com/vitabaks/postgresql_cluster.git

# 2. Go to the playbook directory
cd postgresql_cluster/

# 3. Edit the inventory file
vim inventory
## Specify (non-public) IP addresses and connection settings (`ansible_user`, `ansible_ssh_pass` or `ansible_ssh_private_key_file` for your environment

# 4. Edit the variable file vars/main.yml
vim vars/main.yml
## Specify the variable: "dcs_type: consul"

# 5. install consul role requirements on the control node
ansible-galaxy install -r roles/consul/requirements.yml

# 6. Run playbook:
ansible-playbook deploy_pgcluster.yml

Client access point:

  • master.postgres-cluster.service.consul
  • replica.postgres-cluster.service.consul

vitabaks avatar Jan 04 '23 13:01 vitabaks

cc @askurihin

vitabaks avatar Jan 04 '23 20:01 vitabaks

Done.

vitabaks avatar Jan 17 '23 12:01 vitabaks