This time I'm going to do a small and quick walkthrough for a postgresql cluster install.
I assume you have a clean install of CentOS 7.3 with all updates. The configuration itself is surprisingly simple.
The enviroment I'm working with is:
Node1:
Hostname: pgsql01.archyslife.lan
IP: 172.31.10.31
Member of IPA-Domain
Selinux: enforcing
Node2:
Hostname: pgsql02.archyslife.lan
IP: 172.31.10.32
Member of IPA-Domain
Selinux: enforcing
Cluster:
Main Node: pgsql01.archyslife.lan
Replica: pgsql02.archyslife.lan
Virtual IP: 172.31.10.33
for the sake completeness I'll be adding a A-Record entry in the IPA-DNS.
Let's start with the configuration of each node. First I will completely setup the Master without restarting the services, afterwards the replica will follow.
Steps necessary for both nodes.
Add the pgsql-repo to yum.
Next we will have to install the necessary packages.
sudo yum -y install https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-7-x86_64/pgdg-centos96-9.6-3.noarch.rpm
[archy@pgsql01 ~]$
and enable the services for starting on boot.
sudo yum -y install postgresql96 postgresql96-server postgresql96-contrib pgpool-II-96
[archy@pgsql01 ~]$
Add the ports 5432/tcp, 9999/tcp, 9000/tcp and 9694/udp to your firewall.
sudo systemctl enable postgresql-9.6.service
[archy@pgsql01 ~]$
sudo systemctl enable pgpool-II-9.6.service
[archy@pgsql01 ~]$
Here a quick explanation of what these ports are used for:
sudo firewall-cmd --zone=internal --add-port={5432/tcp,9999/tcp,9000/tcp,9694/udp} --permanent
[archy@pgsql01 ~]$
sudo firewall-cmd --reload
[archy@pgsql01 ~]$
Port 5432: PGSQL Service
Port 9999: PGPool-II Service
Port 9000: PGPool-II Watchdog
Port 9694: PGPool-II Heartbeat
Master-config:
Postgresql:
Run the PGSQL-Setup by using the command
this will take a few seconds and sets the database up for basic usage. Now we will have to edit the pg_hba.conf to add replication hosts and trusts for our servers.
sudo -u postgres /usr/pgsql-9.6/bin/postgresql96-setup initdb
[archy@pgsql01 ~]$
edit the pg_hba.conf to look like the following. Change IP addresses to your needs.
sudo -u postgres vim /var/lib/pgsql/9.6/data/pg_hba.conf
[archy@pgsql01 ~]$
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 127.0.0.1/32 trust
# IPv6 local connections:
host all all ::1/128 trust
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local replication postgres peer
#host replication postgres 127.0.0.1/32 ident
#host replication postgres ::1/128 ident
host replication dbreplication 172.31.10.32/32 md5
host postgres dbreplication 172.31.10.32/32 md5
host postgres dbreplication 172.31.10.33/32 md5
host postgres dbreplication 172.31.10.31/32 md5
the pg_hba.conf is now ready. Next we will have to edit the postgresql.conf file.change the following values:
vim /var/lib/pgsql/9.6/data/postgresql.conf
[archy@pgsql01 ~]$ sudo -u postgres
listen_addresses = '*'
wal_level = replica
max_wal_senders = 6
With that done, we will have to switch to the user 'postgres' and add the user 'dbreplication'.as user postgres run the following commands:
su - postgres
[archy@pgsql01 ~]$ sudo
exit to your normal user again.
psql CREATE ROLE dbreplication LOGIN REPLICATION PASSWORD 'i_am_a_secret_password'; \q
[postgres@pgsql01 ~]$
Now we will setup the pgpool-II config.
This copies the sample-stream config to our standard pgpool.conf. Open the file in your favorite text editor
sudo cp /etc/pgpool-II-96/pgpool.conf.sample-stream /etc/pgpool-II-96/pgpool.conf
[archy@pgsql01 ~]$
and I'll edit the following values to my needs.
sudo vim /etc/pgpool-II-96/pgpool.conf
[archy@pgsql01 ~]$
listen_addresses = '*'
port = 9999
backend_hostname0 = '172.31.10.32'
pid_file_name = '/var/run/pgpool-II-96/pgpool-II-96.pid'
replication_mode = on
sr_check_user = 'dbreplication'
sr_check_password = 'i_am_a_secret_password'
sr_check_database = 'postgres'
health_check_period = 5
health_check_timeout = 0
recovery_user = 'dbreplication'
recovery_password = 'i_am_a_secret_password'
use_watchdog = on
wd_hostname = '172.31.10.31'
wd_port = 9000
delegate_IP = '172.31.10.33'
if_up_cmd = 'ip addr add $_IP/24 dev eth0 label eth0:cluster'
if_down_cmd = 'ip addr del $_IP/24 dev eth0'
heartbeat_destination0 = '172.31.10.32'
heartbeat_destination_port0 = 9694
wd_lifecheck_user = 'dbreplication'
wd_lifecheck_password = 'i_am_a_secret_password'
other_pgpool_hostname0 = '172.31.10.32'
other_pgpool_port0 = 9999
other_wd_port0 = 9000
Save and restart the services.The master's config is now complete. Next up, we will configure the slave.sudo systemctl restart postgresql-96.service
[archy@pgsql01 ~]$
sudo systemctl restart pgpool-II-96.service
[archy@pgsql01 ~]$
First we will copy the master's pgsql-data to the slave. We can achieve that by running the following:
That also copies our config files we edited on the master. Check the following values and edit them if needed.
su - postgres
[archy@pgsql02 ~]$
pg_basebackup --pgdata=/var/lib/pgsql/9.6/data --write-recovery-conf -U dbreplication -h 172.31.10.31 --progress
[archy@pgsql02 ~]$
/var/lib/pgsql/9.6/data/postgresql.conf
listen_addresses = '*'
wal_level = replica
max_wal_senders = 6
hot_standby = on
hot_standby_feedback = on
/var/lib/pgsql/9.6/data/pg_hba.conf
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 127.0.0.1/32 trust
# IPv6 local connections:
host all all ::1/128 trust
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local replication postgres peer
#host replication postgres 127.0.0.1/32 ident
#host replication postgres ::1/128 ident
host replication dbreplication 172.31.10.31/32 md5
host postgres dbreplication 172.31.10.31/32 md5
host postgres dbreplication 172.31.10.32/32 md5
host postgres dbreplication 172.31.10.33/32 md5
The pgsql-service is now configured on the replica. The last thing to do is configure pgpool on the slave.Here are the values that need to be configured to get the cluster to work.
listen_addresses = '*'
port = 9999
backend_hostname0 = '172.31.10.31'
pid_file_name = '/var/run/pgpool-II-96/pgpool-II-96.pid'
replication_mode = on
sr_check_user = 'dbreplication'
sr_check_password = 'i_am_a_secret_password'
sr_check_database = 'postgres'
health_check_period = 5
health_check_timeout = 0
recovery_user = 'dbreplication'
recovery_password = 'i_am_a_secret_password'
use_watchdog = on
wd_hostname = '172.31.10.32'
wd_port = 9000
delegate_IP = '172.31.10.33'
if_up_cmd = 'ip addr add $_IP/24 dev eth0 label eth0:cluster'
if_down_cmd = 'ip addr del $_IP/24 dev eth0'
heartbeat_destination0 = '172.31.10.31'
heartbeat_destination_port0 = 9694
wd_lifecheck_user = 'dbreplication'
wd_lifecheck_password = 'i_am_a_secret_password'
other_pgpool_hostname0 = '172.31.10.31'
other_pgpool_port0 = 9999
other_wd_port0 = 9000
The replica is now configured to work in the cluster.We can now restart the services on both nodes.
[archy@pgsql01 ~]$ sudo systemctl restart postgresql-96.service
[archy@pgsql01 ~]$ sudo systemctl restart pgpool-II-96.service
[archy@pgsql02 ~]$ sudo systemctl restart postgresql-96.service
[archy@pgsql02 ~]$ sudo systemctl restart pgpool-II-96.service
If we check the pgpool-II-96.service now
[archy@pgsql01 ~]$ sudo systemctl status pgpool-II-96.service
[archy@pgsql02 ~]$ sudo systemctl status pgpool-II-96.service
we can see that the cluster is successfully initialized.Feel free to comment and / or suggest a topic.
I've this errors:
ReplyDeleteWARNING: checking setuid bit of if_up_cmd
2019-01-16 11:01:17: pid 7494: DETAIL: ifup[/sbin/ip] doesn't have setuid bit
2019-01-16 11:01:17: pid 7494: WARNING: checking setuid bit of if_down_cmd
2019-01-16 11:01:17: pid 7494: DETAIL: ifdown[/sbin/ip] doesn't have setuid bit
2019-01-16 11:01:17: pid 7494: WARNING: checking setuid bit of arping command
2019-01-16 11:01:17: pid 7494: DETAIL: arping[/usr/sbin/arping] doesn't have setuid bit
Hi there,
Deletethe logs already tell you what's wrong. You've got to set the setuid bit to the /usr/bin/arping binary. You can do that by running the command:
'# chmod 4755 /usr/sbin/arping'. The special bits are set the same way as ugo/rwx.
4 is the setuid bit
2 is the setgid bit
1 is the sticky bit.
I'd recommend to read up on this here:
https://linuxconfig.org/how-to-use-special-permissions-the-setuid-setgid-and-sticky-bits
I'm running the following command in the master node:
ReplyDelete"createdb -U postgres -p 9999 bench_replication"
And then I receive the following error:
createdb: could not connect to database template1: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.9999"?
The interaction with the database is still done on port 5432/tcp. The port occupied by pgpool is only used for replication. Pgpool is not acting as a connection broker.
DeleteI also can't tell if your server is running locally or listening on a specific socket since I know neither your setup, nor your config.
Thanks for the very quick reply. I ran the command without the port, and the database creation worked. The services all appear to be running as they should, but is there a set of commands I can use on the cluster to verify that my configuration is correct and the replication is taking place?
DeleteWell, there is 'pcp_node_info' which can be run. You can also query the database using 'show pool nodes'. More information can be found here:
Deletehttps://www.pgpool.net/docs/latest/en/html/pcp-node-info.html
and here:
https://www.pgpool.net/docs/latest/en/html/sql-show-pool-nodes.html