X-Git-Url: http://git.rot13.org/?p=edozvola;a=blobdiff_plain;f=edozvola-dpavlin.txt;h=b8ab38b18b7842dfb62d142dce70fe79be3caf15;hp=38ef4e668fb9ba672dabcf229f4e982e916718d9;hb=3fd8e6627e01f259fdeeef08ba4b764780a79e98;hpb=9378e506deedce3157ae710b2a543bea8e026338 diff --git a/edozvola-dpavlin.txt b/edozvola-dpavlin.txt index 38ef4e6..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` @@ -44,7 +49,8 @@ sending incremental file list -kreirati testnu bazu i tablicu +# kreirati testnu bazu i tablicu + [root@edozvola-db-01 ~]# sudo -u postgres createdb test [root@edozvola-db-01 ~]# sudo -u postgres psql test test=# create table test1 ( id serial, a text, b int ) ; @@ -54,106 +60,80 @@ test=# insert into test1 (a,b) values ('bar',1234) ; INSERT 0 1 -nfs share za wal fileove + +# nfs share za wal fileove + [root@edozvola-db-pgpool ~]# yum install nfs-utils nfs4-acl-tools [root@edozvola-db-pgpool ~]# systemctl enable nfs-server.service Created symlink from /etc/systemd/system/multi-user.target.wants/nfs-server.service to /usr/lib/systemd/system/nfs-server.service. [root@edozvola-db-pgpool ~]# systemctl start nfs-server.service - [root@edozvola-db-pgpool ~]# mkdir -p /shared/pgsql [root@edozvola-db-pgpool ~]# chown postgres /shared/pgsql/ - [root@edozvola-db-pgpool ~]# vi /etc/exports - [root@edozvola-db-pgpool ~]# cat /etc/exports /shared/pgsql edozvola-db-01(rw,no_root_squash) edozvola-db-02(rw,no_root_squash) - [root@edozvola-db-pgpool ~]# exportfs -va exporting edozvola-db-01:/shared/pgsql exporting edozvola-db-02:/shared/pgsql -mount na database serverima + +# mount na database serverima + [root@edozvola-db-01 ~]# yum install nfs-utils nfs4-acl-tools [root@edozvola-db-01 ~]# mkdir -p /shared/pgsql [root@edozvola-db-01 ~]# vi /etc/fstab - [root@edozvola-db-01 ~]# grep shared /etc/fstab edozvola-db-pgpool:/shared/pgsql /shared/pgsql nfs defaults 0 0 - [root@edozvola-db-01 ~]# mount /shared/pgsql/ - -provjeriti da li postgresql korisnik moze pisati po nfs share-u - +## provjeriti da li postgresql korisnik moze pisati po nfs share-u [root@edozvola-db-01 ~]# sudo -u postgres touch /shared/pgsql/test-01 [root@edozvola-db-01 ~]# ls -al /shared/pgsql/test-01 -rw-r--r-- 1 postgres postgres 0 Aug 18 13:57 /shared/pgsql/test-01 [root@edozvola-db-01 ~]# rm -f /shared/pgsql/test-01 - -isto ponoviti na edozvola-db-02! - +## isto ponoviti na edozvola-db-02! - - - - - - -podesiti wal archiving - +# podesiti wal archiving 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 = 1 -max_replication_slots = 1 -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 @@ -163,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 @@ -232,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' @@ -243,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 @@ -314,4 +278,3 @@ cat /var/lib/pgsql/9.6/data/recovery.done | sed -e s/$my_ip/$other_ip/ > /var/li -hot_standby?