PostgreSQL replicare sclavi multi

De la Ro Ikoula wiki
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

en:PostgreSQL replication slaves multi he:PostgreSQL שכפול עבדים רב ru:PostgreSQL репликации рабы multi pl:PostgreSQL replikacji niewolników multi ja:PostgreSQL のレプリケーション スレーブ マルチ ar:كيو النسخ المتماثل العبيد متعددة zh:PostgreSQL 复制奴隶多 de:PostgreSQL Replikation Sklaven multi nl:PostgreSQL replicatie slaven multi it:PostgreSQL replica schiavi multi pt:Multi de escravos de replicação PostgreSQL es:PostgreSQL replicación esclavos multi fr:Replication PostgreSQL multi slaves

Acest articol este rezultatul unei traduceri automate efectuate de către software-ul. Puteți vizualiza sursa articol aici.

Introducerea | _. _. Aceasta pagina se ocupa cu punerea în aplicare a o asincron streaming PostgreSQL replicare cu un maestru si doi sclavi. Noastre slave va fi configurat ca hot standby, care este să spun că va fi posibil pentru a ecuta interogări | _. _. doar-în-citire | _. _. pe acestea.

Contextul punerii acest | _. _. Avem | _. _. Serverele Debian | _. _. actualizat | _. _. Apoi am conectaţi la ql | _. _. Activam ecran extinsă şi putem verifica noastre replicare | _. _. Avem atât de mult noştri | _. _. replicare cu serverele noastre două slave | _. _. | _. _. şi | _. _. Întotdeauna conectat ql pe maestru, crearea unei baze de testare | _. _. ex | _. _. | _. _. pentru a confirma că reproducerea este funcţional | _. _. Verificați că baza de date este bine reprodus pe noastre | _. _. Slave | _. _. Baza de date ce ne-am creat pe stăpânul nostru este atât de bine automat reprodus pe noastre două slave. | _. _. va fi stăpânul nostru | _. _. | _. _. va fi un sclav | _. _. Postgres | _. _. va fi un sclav al doilea | _. _. Indicate comenzi va fi de a rădăcină atunci când acestea sunt precedate de | _. _. şi ca utilizator de sistem atunci când acestea sunt precedate de | _. _. Instalarea de PostgreSQL şi pre-configurare de toate trei servere: _! _ | Toate comenzile din această parte se face pe fiecare dintre serverele. (Într-o primă etapă, este recomandat să aveţi un fişier | _. _. populat cu conexiuni la fiecare server, ca acest lucru: _! _ | prin adaptarea cu nume de host şi ip adrese de propriile servere | _. _. Adauga depunerea APT PostgreSQL | _. _. Importam cheia publică a acestui depozit | _. _. Vom actualiza memoria cache APT pentru a se ține cont de depozit | _. _. Putem instala pachetul de ql | _. _. instalaţi cea mai recentă versiune stabilă este | _. _. la momentul scrierii acestui | _. _. Setează o parolă | _. _. ales de el dar sigure | _. _. şi generează o ssh-cheie pereche | _. _. fără parolă | _. _. pentru utilizator sistem postgres | _. _. Am copie postgres utilizator din şi între fiecare server public ssh cheie | _. _. Deoarece primul server | _. _. Postgres | _. _. în cazul nostru: _! _ | la al doilea | _. _. Postgres | _. _. pentru noi | _. _. şi troisiseme | _. _. Postgres | _. _. La a doua la prima și a treia server | _. _. La a treia la primul şi al doilea server | _. _. Configurare master: _! _ | Fac numai master: _! _ | Postgres | _. _. în cazul nostru: _! _ | Putem crea rolul | _. _. replicare de utilizator: _! _ | Notă: _! _ | Vom defini o unire limită de | _. _. pentru că avem | _. _. Slave | _. _. Vom edita fişierul de configurare principal al postgresql | _. _. pentru a parametriza următoarele linii directoare: _! _ | Notă: _! _ | Vom activa Arhivarea nostru al doilea server | _. _. personaliza IP a serverului | _. _. pentru şi mai multe măsuri de precauţie, dar acest lucru nu este o obligaţie. Putem defini, de asemenea, parametrii hot_standby, bine că a ignorat-o pe un maestru, caz în care ar trebui să fie retrogradat pentru a slave în viitor. ) Acum se publică fişierul de autentificare postgresql | _. _. pentru a adăuga noastre autorizaţie de utilizator de replicare pentru a vă conecta la noastre slave sau următoarea linie la sfârşitul fişierului: _. _ | Vă rugăm să se adapteze această linie în funcţie de numele de utilizator replicare şi reţea | _. _. sau adresele respective ip: _! _ | a ta slavă | _. _. Reporniți serviciul de postgresql pentru a ține seama de configurare noastre | _. _. în rădăcină | _. _. Acest lucru asigură că serviciul a început cu succes | _. _. Configurare a slave | _. _. Pe prima sclav | _. _. Hai să ne oprim la serviciu postgresql | _. _. Vom edita fişierul de configurare principal al postgresql | _. _. să configuraţi aceleaşi linii directoare ca maestru, de croitorie doar adresa IP de sclav primul de cel de al doilea sclav în arhiva rsync comanda dacă doriţi să activaţi-l fie | _. _. Acum se publică fişierul de autentificare postgresql | _. _. pentru a adăuga autorizare a utilizatorul nostru de replicare să se conecteze la serverele noastre alte: _! _ | Se va face că, în cazul în care acest sclav ar trebui promovat maestru | _. _. Notă: _! _ | Cu această configuraţie similară cu cea a Învăţătorului nostru permite cu uşurinţă promova acest sclav ca un maestru in caz de nevoie.


Pentru operaţiunile de mai jos, face log in ca utilizator sistem postgres | _. _. Putem crea directorul de destinaţie a wal arhivele maestru | _. _. Vom elimina directorul de date postgresql | _. _. It a face copie de rezervă bază | _. _. personaliza ip Stăpânul tău şi numele de utilizator de replicare :


, vi se va cere parola de utilizator de replicare | _. _. Configuraţi replicare prin crearea fişierului | _. _. cu următorii parametri: _! _ | Notă: _! _ | Fişierul de declanşare este fişierul pe care putem crea atunci cand dorim sa sclavi oprire replicare şi începe pentru a accepta scripturi că este atunci când vrem să-l promoveze ca maestru. Înainte de a promova un accident de sclav stăpânului său, vă rugăm să asiguraţi-vă că Maestrul iniţială venit nu pentru a evita orice corupţie. 3 Root, ne întoarcem şi pornim serviciul: _! _ | Acest lucru asigură că serviciul a început cu succes | _. _. În cazul în care ne conecta la Învăţătorului nostru, deja putem verifica noastre de replicare între master şi slave prima este funcţională | _. _. Se conecteaza la stăpân al nostru şi am conectaţi în utilizator de sistem postgres | _. _. Apoi am conectaţi la postgresql | _. _. Activam ecran extinsă şi putem verifica noastre replicare | _. _. Noastre replicarea streaming asincron cu nostru primul sclav este bine realizat. În acest moment avem un maestru de replicare | _. _. Clasic sclav | _. _. un singur sclav asincron de streaming | _. _. Pe al doilea sclav | _. _. Repetaţi acelaşi ceea ce a fost făcut pe slave prima adaptare evident hostname sale recovery.conf fişier, adresa de ip în ordinea check-in în fișierul de configurare principal, dacă doriţi să activaţi Arhivarea pe acest sclav al doilea. 8 (Audit şi de încercare a noastră multi maestru de replicare slavi | _. _. Se conecteaza la master şi sunteţi conectat în utilizator postgres) :

Postgres01 (10.1.1.75) : Pentru a elimina, deoarece master

Postgres02 (10.1.1.90) :

Postgres03 (10.1.1.199) :


"#"  "$".

/etc/hosts  ()  :
# cat /etc/hosts
127.0.0.1       localhost

10.1.1.75       postgres01
10.1.1.90       postgres02
10.1.1.199      postgres03


:
# echo "deb http://apt.postgresql.org/pub/repos/apt/ jessie-pgdg main" > /etc/apt/sources.list.d/postgres.list


:
# gpg --keyserver pgpkeys.mit.edu --recv-key 7FCC7D46ACCC4CF8 && gpg -a --export 7FCC7D46ACCC4CF8 | apt-key add -
gpg: directory `/root/.gnupg' created
gpg: new configuration file `/root/.gnupg/gpg.conf' created
gpg: WARNING: options in `/root/.gnupg/gpg.conf' are not yet active during this run
gpg: keyring `/root/.gnupg/secring.gpg' created
gpg: keyring `/root/.gnupg/pubring.gpg' created
gpg: requesting key ACCC4CF8 from hkp server pgpkeys.mit.edu
gpg: /root/.gnupg/trustdb.gpg: trustdb created
gpg: key ACCC4CF8: public key "PostgreSQL Debian Repository" imported
gpg: no ultimately trusted keys found
gpg: Total number processed: 1
gpg:               imported: 1  (RSA: 1)
OK


:
# apt-get update


( 9.5 ) :
# apt-get install postgresql


()  ()  :
# passwd postgres
# su - postgres
$ ssh-keygen


:


(postgres01 )  (postgres02 )  (postgres03) :
root@postgres01:~# su - postgres
postgres@postgres01:~$ ssh-copy-id postgres02
postgres@postgres01:~$ ssh-copy-id postgres03


:
root@postgres02:~# su - postgres
postgres@postgres02:~$ ssh-copy-id postgres01
postgres@postgres02:~$ ssh-copy-id postgres03


:
root@postgres03:~# su - postgres
postgres@postgres03:~$ ssh-copy-id postgres01
postgres@postgres03:~$ ssh-copy-id postgres02

(postgres01 ) :


/ :

# su - postgres
$ psql -c "CREATE USER repuser REPLICATION LOGIN CONNECTION LIMIT 2 ENCRYPTED PASSWORD '<mot de passe repuser>';"

 : 2 2


/etc/postgresql/9.5/main/postgresql.conf  :
listen_addresses = '*'
wal_level = hot_standby
archive_mode = on
archive_command = 'rsync -av %p postgres@<ip du premier slave>:/var/lib/postgresql/wal_archive/%f'
max_wal_senders = 2
wal_keep_segments = 256
hot_standby = on

: ()


/etc/postgresql/9.5/main/pg_hba.conf  :
hostssl replication     repuser <ip du réseau de vos serveurs>/24     md5

()


() :
# systemctl restart postgresql


:
root@postgres01:~# systemctl status postgresql
● postgresql.service - PostgreSQL RDBMS
   Loaded: loaded (/lib/systemd/system/postgresql.service; enabled)
   Active: active (exited) since Thu 2016-06-02 12:06:28 CEST; 22s ago
  Process: 77056 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
 Main PID: 77056 (code=exited, status=0/SUCCESS)


root@postgres01:~# ps -u postgres u
USER        PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
postgres  77038  0.0  4.4 227300 21836 ?        S    12:06   0:00 /usr/lib/postgresql/9.5/bin/postgres -D /var/lib/postgresql/9.
postgres  77040  0.0  0.8 227300  4160 ?        Ss   12:06   0:00 postgres: checkpointer process
postgres  77041  0.0  1.0 227300  4968 ?        Ss   12:06   0:00 postgres: writer process
postgres  77042  0.0  1.7 227300  8776 ?        Ss   12:06   0:00 postgres: wal writer process
postgres  77043  0.0  1.3 227728  6708 ?        Ss   12:06   0:00 postgres: autovacuum launcher process
postgres  77044  0.0  0.6  82244  3392 ?        Ss   12:06   0:00 postgres: archiver process
postgres  77045  0.0  0.8  82244  4244 ?        Ss   12:06   0:00 postgres: stats collector process

:
# systemctl stop postgresql


/etc/postgresql/9.5/main/postgresql.conf  :
listen_addresses = '*'
wal_level = hot_standby
archive_mode = on
archive_command = 'rsync -av %p postgres@<ip du second slave>:/var/lib/postgresql/wal_archive/%f'
max_wal_senders = 2
wal_keep_segments = 256
hot_standby = on


/etc/postgresql/9.5/main/pg_hba.conf  () :
hostssl replication     repuser <ip du réseau de vos serveurs>/24     md5

 :


:
# su – postgres


:
$ mkdir /var/lib/postgresql/wal_archive


:
$ rm -rf /var/lib/postgresql/9.5/main


() :
$ pg_basebackup -h <ip de votre master> -D /var/lib/postgresql/9.5/main -U repuser -v -P --xlog


/var/lib/postgresql/9.5/main/recovery.conf  :
standby_mode = on
primary_conninfo = 'host=<ip de votre master> port=5432 user=repuser password=<mot de passe de repuser> sslmode=require application_name=<hostname de votre slave>'
trigger_file = '/var/lib/postgresql/9.5/postgres.trigger'

 :


:
# systemctl start postgresql


:
# systemctl status postgresql
● postgresql.service - PostgreSQL RDBMS
   Loaded: loaded (/lib/systemd/system/postgresql.service; enabled)
   Active: active (exited) since Thu 2016-06-02 12:53:42 CEST; 1min 6s ago
  Process: 8894 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
 Main PID: 8894 (code=exited, status=0/SUCCESS)


# ps -u postgres u
USER        PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
postgres   8878  0.0  4.4 227308 21892 ?        S    12:53   0:00 /usr/lib/postgresql/9.5/bin/postgres -D /var/lib/postgresql/9.
postgres   8879  0.0  1.1 227376  5700 ?        Ss   12:53   0:00 postgres: startup process   recovering 00000001000000000000000
postgres   8880  0.0  0.8 227308  4140 ?        Ss   12:53   0:00 postgres: checkpointer process
postgres   8881  0.0  1.0 227308  5236 ?        Ss   12:53   0:00 postgres: writer process
postgres   8882  0.0  0.6  82252  3316 ?        Ss   12:53   0:00 postgres: stats collector process
postgres   8883  0.0  1.7 238064  8520 ?        Ss   12:53   0:00 postgres: wal receiver process   streaming 0/30003E0


:
:
# su - postgres


:
$ psql


:
postgres=# \x
Expanded display is on.
postgres=# select * from pg_stat_replication;
-[ RECORD 1 ]----+------------------------------
pid              | 78879
usesysid         | 16384
usename          | repuser
application_name | postgres02
client_addr      | 10.1.1.90
client_hostname  |
client_port      | 49009
backend_start    | 2016-06-02 12:53:36.641823+02
backend_xmin     |
state            | streaming
sent_CRElocation    | 0/30004C0
write_location   | 0/30004C0
flush_location   | 0/30004C0
replay_location  | 0/30004C0
sync_priority    | 0
sync_state       | async

/ ()

:
# su – postgres
:
$ psql


:
postgres=# \x
Expanded display is on.
postgres=# select * from pg_stat_replication;
-[ RECORD 1 ]----+------------------------------
pid              | 78879
usesysid         | 16384
usename          | repuser
application_name | postgres02
client_addr      | 10.1.1.90
client_hostname  |
client_port      | 49009
backend_start    | 2016-06-02 12:53:36.641823+02
backend_xmin     |
state            | streaming
sent_location    | 0/5000140
write_location   | 0/5000140
flush_location   | 0/5000140
replay_location  | 0/5000140
sync_priority    | 0
sync_state       | async
-[ RECORD 2 ]----+------------------------------
pid              | 82725
usesysid         | 16384
usename          | repuser
application_name | postgres03
client_addr      | 10.1.1.199
client_hostname  |
client_port      | 51754
backend_start    | 2016-06-02 14:31:43.759683+02
backend_xmin     |
state            | streaming
sent_location    | 0/5000140
write_location   | 0/5000140
flush_location   | 0/5000140
replay_location  | 0/5000140
sync_priority    | 0
sync_state       | async
2  (postgres02 03).


(ex : checkrep)  :
postgres=# CREATE DATABASE checkrep;


2  :
root@postgres02:~# su - postgres
postgres@postgres02:~$ psql
psql (9.5.3)
Type "help" for help.

postgres=# \l
                                  List of databases
   Name    |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
 checkrep  | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 |
 postgres  | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 |
 template0 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
 template1 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
(4 rows)


root@postgres03:~# su - postgres
postgres@postgres03:~$ psql
psql (9.5.3)
Type "help" for help.

postgres=# \l
                                  List of databases
   Name    |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
 checkrep  | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 |
 postgres  | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 |
 template0 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
 template1 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
(4 rows)



:
postgres=# DROP DATABASE checkrep;



Nu sunteți autorizat să publicați comentarii.