Repmgr
== DRAFT ==
Installation
1 | # echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list |
Configuration
On echange les clefs des users postgres entre les differents serveurs
- Set des autorisations postgres
1 | # tail -3 /etc/postgresql/9.5/main/pg_hba.conf |
- Conf Postgres
1 | # diff /etc/postgresql/9.5/main/postgresql.conf /tmp/postgresql.conf.ori |
- Conf Repmgr
toute les commande repmgr sont a lancer en postgres
1 | # cat /etc/repmgr.conf |
1 | $ createuser -s repmgr |
Replication
- Initialise the master server
1 | repmgr -f /etc/repmgr.conf primary register |
On check
1 | =# \c repmgr |
- Clone the standby server (stop postgresql ; purge /var/lib/postgresql/9.5/main/ first)
1 | repmgr -h node1 -U repmgr -d repmgr -D /var/lib/postgresql/9.5/main/ -f /etc/repmgr.conf standby clone |
On check (depuis le master)
1 | =# SELECT * FROM pg_stat_replication; |
- Register the standby
1 | repmgr -f /etc/repmgr.conf standby register |
On check
1 | =# \c repmgr |
Recovery
node1 est dead
1 | $ repmgr cluster show |
on stop ses services
1 | # /etc/init.d/postgresql stop |
on resync & register
1 | # repmgr -h node3 -U repmgr -d repmgr -D /var/lib/postgresql/9.5/main/ -f /etc/repmgr.conf standby clone |
node1 is back
1 | $ repmgr cluster show |
Lancement de repmgrd
pour quand le script d’init marchera :
1
2
3
4# sed -i 's/REPMGRD_ENABLED=no/REPMGRD_ENABLED=yes/' /etc/default/repmgrd
# sed -i 's/\#REPMGRD_CONF\=\"\/path\/to\/repmgr.conf\"/REPMGRD_CONF\=\"\/etc\/repmgr.conf\"/' /etc/default/repmgrd
# sed -i 's/\#REPMGRD_OPTS=\"\"/REPMGRD_OPTS="-m -d"/' /etc/default/repmgrd
# sed -i 's/\#REPMGR_PIDFILE\=\/var\/run\/repmgrd.pid/REPMGR_PIDFILE\=\/var\/run\/postgresql\/repmgrd.pid/' /etc/default/repmgrdmon script d’init de remplacement :
1
# cat /etc/init.d/repmgrd.init #!/bin/bash ### BEGIN INIT INFO # Provides: repmgrd # Required-Start: $remote_fs $all # Should-Start: # Required-Stop: # Default-Start: 2 3 5 # Default-Stop: 0 6 # Description: Starts and stops repmgrd. ### END INIT INFO REPMGRD=/usr/bin/repmgrd REPMGR_PIDFILE=/var/run/postgresql/repmgrd.pid REPMGRD_CONF=/etc/repmgr.conf case $1 in # Startup repmgrd servers. start) su postgres -c "$REPMGRD -m -d -p $REPMGR_PIDFILE -f $REPMGRD_CONF" #renice -5 -p `cat $REPMGR_PIDFILE` echo "starting..." ;; # Stop repmgrd servers. stop) if [ -f $REPMGR_PIDFILE ] then if ps auxww | grep `cat $REPMGR_PIDFILE` | grep -v grep then kill `cat $REPMGR_PIDFILE` echo "stopping..." else echo "Repmgrd is not running, but $REPMGR_PIDFILE is present" fi else echo "Repmgrd is not running" fi ;; # status status) if ps auxww | grep `cat $REPMGR_PIDFILE` | grep -v grep then echo "Repmgrd is running" else echo "Repmgrd is stopped" fi ;; *) echo "Init de Repmgrd: stop / start ou status" ;; esac
Notif
repmgr.conf
%n - node ID
%e - event type
%s - success (1 or 0)
%t - timestamp
%d - details
event_notification_command=’/path/to/some/script %n %e %s “%t” “%d”‘
event_notifications=master_register,standby_register,witness_create
https://github.com/2ndQuadrant/repmgr/blob/master/README.md#generating-event-notifications-with-repmgrrepmgrd
Gestion de la vip avec heartbeat dans le cas d’un master/slave
Install1
# apt-get install heartbeat
conf de la vip1
# cat <<EOF >> /etc/network/interfaces
#auto ens160:pg # nonauto
iface ens160:pg inet static
address 10.0.69.0.120
netmask 255.255.255.0
EOF
# echo "net.ipv4.ip_nonlocal_bind=1" >> /etc/sysctl.conf
# sysctl -p
commande heartbeat utiles
/usr/share/heartbeat/hb_standby
/usr/share/heartbeat/hb_takeoverconf heartbeat
1
# cat /etc/ha.d/ha.cf ############################### # logging logfile /var/log/ha/ha-log debugfile /var/log/ha/ha-debug ############################### # communication autojoin none udpport 694 ucast ens160 10.0.69.100 bcast ens160 ############################### # thresholds warntime 5 deadtime 15 initdead 60 keepalive 2 ############################### # nodes node bdd1 node bdd2 auto_failback off
1 | # cat /etc/ha.d/haresources # VIP bdd1 IPaddr::10.0.69.120/24/ens160:pg #MailTo::moi@pouet.fr::HA_Postgresql |
on adapte la conf /etc/repmgr.conf
1
# diff /etc/repmgr.conf_heartbeat /etc/repmgr.conf_ori - promote_command='repmgr standby promote -f /etc/repmgr.conf' - follow_command='repmgr standby follow -f /etc/repmgr.conf' + promote_command='sudo /usr/share/heartbeat/hb_takeover && repmgr standby promote -f /etc/repmgr.conf' + follow_command='sudo /usr/share/heartbeat/hb_standby && repmgr standby follow -f /etc/repmgr.conf'
conf sudo
postgres ALL=(root) NOPASSWD:/usr/share/heartbeat/hb_takeover