How To Set Up An Active/Passive PostgreSQL Cluster With Pacemaker, Corosync, And DRBD (CentOS 5.5) - Page 2
|
This article explains how to set up (and monitor) an Active/Passive PostgreSQL Cluster, using Pacemaker with Corosync and DRBD. Prepared by Rafael Marangoni, from BRLink Servidor Linux Team. 4. Configuring DRBDFirst, we need to configure /etc/drbd.conf on both nodes: vi /etc/drbd.conf global {
usage-count no;
}
common {
syncer { rate 100M; }
protocol C;
}
resource postgres {
startup {
wfc-timeout 0;
degr-wfc-timeout
120;
}
disk { on-io-error detach; }
on node1.clusterbr.int {
device /dev/drbd0;
disk /dev/sdb;
address 172.16.0.1:7791;
meta-disk internal;
}
on node2.clusterbr.int {
device /dev/drbd0;
disk /dev/sdb;
address 172.16.0.2:7791;
meta-disk internal;
}
}
The main points of configuration are: Afterwards of that configuration, we can create the metadata on postgres resource. On both nodes do: drbdadm create-md postgres node1: drbdadm create-md postgres [root@node1 ~]# drbdadm create-md postgres node2: drbdadm create-md postgres [root@node2 ~]# drbdadm create-md postgres Next, we need to put the resource up, connecting to it. Again, on both nodes do: drbdadm up postgres Now we can make the initial sync between the nodes. This needs to be done only on the primary node, here we choose the node1. drbdadm -- --overwrite-data-of-peer primary postgres To check the progress of the sync, and status of DRBD resource, look at /proc/drbd: cat /proc/drbd [root@node1 ~]# cat /proc/drbd Now, we need to wait the end of the sync. This may take a long time, depends the size and performance of your disks. And of course, the speed of cluster network interfaces that is being used with the cross-over cable). When the sync process ends, we can take a look at the status of the resource postgres: node1: cat /proc/drbd [root@node1 ~]# cat /proc/drbd node2: cat /proc/drbd [root@node2 ~]# cat /proc/drbd To learn what means all the status information, take a look at: www.drbd.org/users-guide-emb/ch-admin.html#s-proc-drbd
5. Configuring PostgreSQLFirst, need to initiate the DRBD services, to create the initdb. On both nodes, do: /etc/init.d/drbd start As we choosed before, node1 will be the primary. To make sure, on node1: cat /proc/drbd [root@node1 ~]# cat /proc/drbd The Primary/Secondary info, means that the local server is the Primary, and the other one is Secondary. The UpToDate/UpToDate info, means that the resource is UptoDate on both nodes. Next, we need to format the DRBD device. Here we choosed ext3 as the filesystem. Only on node1, do: mkfs.ext3 /dev/drbd0 Afterwards, we can mount the device. The mountpoint that we use is the default PostgreSQL location (on Redhat based systems):
mount -t ext3 /dev/drbd0 /var/lib/pgsql Next, we change the owner and group of the mountpoint.
chown postgres.postgres /var/lib/pgsql Now, we need to initiate the postgresql database:
su - postgres I prefer to enable trusted authentication on the nodes and cluster IP's.
echo "host all all 10.0.0.191/32 trust" >> /var/lib/pgsql/data/pg_hba.conf Other config that we need to do, it's to enable PostgreSQL to listen on all interfaces.
vi /var/lib/pgsql/data/postgresql.conf Uncomment and change only the line: listen_addresses = '0.0.0.0' Now, we start postgres.
/etc/init.d/postgresql start Then, we can create an admin user to manage postgresql:
su - postgres You'll need to set a password to admpgsql. Afterwards, we create a database and populate it with pgbench.
su - postgres Pgbench populates the db with some info, the objetive is to test postgresql/ pgbench -i pgbench -bash-3.2$ pgbench -i pgbench Now, we'll access the database to check if everything is ok:
psql -U admpgsql -d pgbench psql -U admpgsql -d pgbench Afterwards, all postgres config is done.
Checking if PostgreSQL will work on node2Before we start to manage the services with Pacemaker, it's better to test if postgres will work on node2. node1: First, on node1, we need to stop postgresql: /etc/init.d/postgresql stop Then, we umount the DRBD device: umount /dev/drbd0 Now, we need to put node1 as Secondary on DRBD resource: drbdadm secondary postgres node2: First, on node2, we need to promote node2 as Primary on DRBD resource: drbdadm primary postgres Then, we mount the DRBD device: mount -t ext3 /dev/drbd0 /var/lib/pgsql/ Finally, we start postgresql /etc/init.d/postgresql start Let's check if we can access the pgbench db on node2:
psql -U admpgsql -d pgbench [root@node2 ~]# psql -U admpgsql -d pgbench Now, that everything is ok, we should stop all the services, to initiate the cluster config: node2:
/etc/init.d/postgresql stop node1:
drbdadm primary postgres We need to ensure that all the services are disabled at the initialization.
chkconfig --level 35 drbd off
|



Recent comments
1 day 6 hours ago
1 day 9 hours ago
1 day 10 hours ago
1 day 12 hours ago
1 day 13 hours ago
1 day 15 hours ago
1 day 16 hours ago
2 days 8 hours ago
2 days 9 hours ago
2 days 12 hours ago