X-Git-Url: http://git.rot13.org/?p=edozvola;a=blobdiff_plain;f=edozvola-dpavlin.txt;h=b8ab38b18b7842dfb62d142dce70fe79be3caf15;hp=c6877e02a7845d50262e3ccd3724285180e244d3;hb=3fd8e6627e01f259fdeeef08ba4b764780a79e98;hpb=a4bd3c62f64524aea3ef82cf443455b546931f03;ds=sidebyside diff --git a/edozvola-dpavlin.txt b/edozvola-dpavlin.txt index c6877e0..b8ab38b 100644 --- a/edozvola-dpavlin.txt +++ b/edozvola-dpavlin.txt @@ -1,10 +1,15 @@ -yum install etckeeper +# instalirati etckeeper da čuva /etc/ direktorij u git-u +# (nije na produkcijskom enviromentu) + +yum install etckeeper cd /etc/ git config --global user.email "dpavlin@rot13.org" git config --global user.name "Dobrica Pavlinusic" git commit -m base +PostgreSQL replikacija, wal shipping, streaming, host standby + https://www.postgresql.org/docs/9.6/static/warm-standby.html @@ -26,7 +31,7 @@ bash-4.2$ cp -v .ssh/id_rsa.pub .ssh/authorized_keys ‘.ssh/id_rsa.pub’ -> ‘.ssh/authorized_keys’ -prekopirati isti kljuc i authoriorized keys na slave: +## prekopirati isti kljuc i authoriorized keys na slave: [root@edozvola-db-01 pgsql]# rsync -rav .ssh edozvola-db-02:`pwd` @@ -107,41 +112,28 @@ https://www.postgresql.org/docs/9.6/static/continuous-archiving.html [root@edozvola-db-01 ~]# vi /var/lib/pgsql/9.6/data/postgresql.conf -wal_level = replica -archive_mode = on -max_wal_senders = 3 -max_replication_slots = 3 -archive_command = 'test ! -f /shared/pgsql/%f && cp %p /shared/pgsql/%f' -hot_standby = on - - +wal_level = replica # same as hot_standby +# https://www.postgresql.org/docs/9.6/static/runtime-config-wal.html#GUC-SYNCHRONOUS-COMMIT +synchronous_commit = on +archive_mode = on +archive_command = 'test ! -f /shared/pgsql/%f && cp %p /shared/pgsql/%f' +max_wal_senders = 3 +max_replication_slots = 3 +hot_standby = on [root@edozvola-db-01 ~]# systemctl restart postgresql-9.6.service +# kreirati replication korisnika - - - - - - - - - - - - -kreirati replication korisnika [root@edozvola-db-01 ~]# sudo -u postgres psql - postgres=# create user replication with password 'replication123' login replication ; CREATE ROLE @@ -151,15 +143,13 @@ CREATE ROLE host replication replication 10.200.1.62/24 md5 +## netmask je /24 da mozemo imati istu konfiguraciju na oba node-a -netmask je /24 da mozemo imati istu konfiguraciju na oba node-a - - -testirati replikaciju +# testirati replikaciju [root@edozvola-db-01 ~]# sudo -u postgres psql test test=# insert into test1 (a,b) values ('baz',3); INSERT 0 1 @@ -220,7 +210,7 @@ da bi svi podaci zavrsili na slave-u, na masteru je dobro izvrsiti komandu check - +# recovery.conf [root@edozvola-db-02 ~]# cat recovery.conf standby_mode = 'on' @@ -231,63 +221,49 @@ archive_cleanup_command = 'pg_archivecleanup /shared/pgsql %r' -skripte -promoviranje slave-a u master +# skripte [root@edozvola-db-01 pgsql]# pwd /var/lib/pgsql -[root@edozvola-db-01 pgsql]# cat promote-slave-to-master.sh -#!/bin/sh -xe - +## promoviranje slave-a u master +[root@edozvola-db-01 pgsql]# cat promote-slave-to-master.sh +#!/bin/sh -xe /usr/pgsql-9.6/bin/pg_ctl --pgdata=/var/lib/pgsql/9.6/data promote +## kreiranje slave instance od mastera - - - -kreiranje slave instance od mastera [root@edozvola-db-01 pgsql]# cat create-pgsql-slave.sh #!/bin/sh -e - # WARNING: this script depends that two database nodes have IPs which and in x1 and x2 # tr 12 21 does swap from currnet node number/ip to other one! - test "`whoami`" != "postgres" && echo "$0 needs to be run as postgres user!" && exit 1 - here=`hostname -s` there=`hostname -s | tr 12 21` - my_ip=`ip addr | grep 10.200.1. | sed 's/^.*\(10\.200\.1\.[0-9]*\)\/.*$/\1/'` other_ip=`echo $my_ip | tr 12 21` - echo "Create slave on $here $my_ip using data from master on $there $other_ip" echo "[enter] to start" read - #systemctl stop postgresql-9.6.service || true /usr/pgsql-9.6/bin/pg_ctl --pgdata=/var/lib/pgsql/9.6/data stop || true - echo "select pg_start_backup('slave')" | ssh $there psql - rsync -rav --delete --exclude pg_xlog $there:/var/lib/pgsql/9.6/data/ /var/lib/pgsql/9.6/data/ - echo "select pg_stop_backup()" | ssh $there psql - test -e /var/lib/pgsql/9.6/data/recovery.done || ( echo "ERROR: no recovery.done !" && exit 1 ) cat /var/lib/pgsql/9.6/data/recovery.done | sed -e s/$my_ip/$other_ip/ > /var/lib/pgsql/9.6/data/recovery.conf @@ -302,4 +278,3 @@ cat /var/lib/pgsql/9.6/data/recovery.done | sed -e s/$my_ip/$other_ip/ > /var/li -hot_standby?