PostgreSQL replica schiavi multi
ja:PostgreSQL のレプリケーション スレーブ マルチ
ar:كيو النسخ المتماثل العبيد متعددة
zh:PostgreSQL 复制奴隶多
de:PostgreSQL Replikation Sklaven multi
nl:PostgreSQL replicatie slaven multi
pt:Multi de escravos de replicação PostgreSQL
es:PostgreSQL replicación esclavos multi
fr:Replication PostgreSQL multi slaves
Il presente articolo è stato tradotto tramite un software di traduzione automatica. È possibile visualizzare l'origine articolo qui.
Introduzione | _. _. Questa pagina riguarda l'implementazione di una replica asincrona di PostgreSQL in streaming con un master e due schiavi. Nostro slavo sarà configurato come hot-standby, vale a dire che sarà possibile eseguire query | _. _. sola lettura | _. _. su questi.
Contesto di questa implementazione | _. _. Abbiamo | _. _. Server Debian | _. _. aggiornamento | _. _. Poi ci colleghiamo a ql | _. _. Attiviamo la visualizzazione estesa e controlliamo la nostra replica | _. _. Abbiamo così tanto il nostro | _. _. replica con i nostri due server slave | _. _. | _. _. e | _. _. Sempre connesso a ql sul master, creare un database di test | _. _. | _. _. | _. _. per confermare che la replica sia funzionale | _. _. Verificare che il database è ben replicati su nostro | _. _. Slava | _. _. Il database che abbiamo creato il nostro Maestro è così ben automaticamente replicato su nostri due slavi. | _. _. sarà il nostro Maestro | _. _. | _. _. sarà uno schiavo | _. _. Postgres | _. _. sarà un secondo slave | _. _. Indicato gli ordini saranno root quando sono precedute di | _. _. e come utente di sistema quando sono precedute di | _. _. Installazione di PostgreSQL e pre-configurazione di tutti i tre server: _! _ | Tutti gli ordini di questa parte sono da fare su ogni server. (Come primo passo, si consiglia di avere un file | _. _. popolato con connessioni a ogni server, come questo: _! _ | adattando con gli indirizzi ip e nomi host del vostro server | _. _. Aggiungere archiviazione APT PostgreSQL | _. _. Importiamo la chiave pubblica di questo deposito | _. _. Aggiorniamo la cache di APT per tenere conto il deposito | _. _. Installiamo il pacchetto ql | _. _. installare l'ultima versione stabile è il | _. _. al momento della stesura di questo articolo | _. _. Imposta una password | _. _. di sua scelta ma sicura | _. _. e genera una coppia di chiavi ssh | _. _. senza passphrase | _. _. per l'utente di sistema postgres | _. _. Copiamo l'utente postgres dal e tra il pubblico di ogni server ssh chiave | _. _. Dal primo server | _. _. Postgres | _. _. nel nostro caso: _! _ | alla seconda | _. _. Postgres | _. _. per noi | _. _. e troisiseme | _. _. Postgres | _. _. Dal secondo al primo e il terzo server | _. _. Dal terzo al primo e al secondo server | _. _. Configurazione del Master: _! _ | Solo la principale: _! _ | Postgres | _. _. nel nostro caso: _! _ | Creiamo il ruolo | _. _. la replica degli utenti: _! _ | Nota: _! _ | Definiamo un limite di connessioni di | _. _. perché abbiamo | _. _. Slava | _. _. Editiamo il file di configurazione principale di postgresql | _. _. per impostare le seguenti linee guida: _! _ | Nota: _! _ | Attiviamo l'archiviazione al nostro secondo server | _. _. personalizzare l'IP del tuo server | _. _. per precauzioni ancora di più, ma questo non è un obbligo. Definiamo anche la hot_standby di parametri, Beh questo ignorato su un master, nel qual caso dovrebbe essere abbassato di livello sullo slave in futuro. ) Pubblica ora il file di autenticazione postgresql | _. _. per aggiungere la nostra autorizzazione utente di replica per connettersi da nostro slavo o la riga seguente alla fine del file: _. _ | Si prega di adattare questa linea in base al nome del vostro utente replica e rete | _. _. o gli indirizzi ip rispettivi: _! _ | del tuo slava | _. _. Riavviare il servizio di postgresql per prendere in considerazione la nostra configurazione | _. _. nella radice | _. _. Questo assicura che il servizio è stato avviato correttamente | _. _. Configurazione di slava | _. _. Il primo slave | _. _. Let's stop il servizio postgresql | _. _. Editiamo il file di configurazione principale di postgresql | _. _. per configurare lo stesso linee guida come il Maestro, adattando solo l'indirizzo IP del primo slave da quella del secondo slave nell'archivio rsync comando se si desidera attivarla neanche | _. _. Pubblica ora il file di autenticazione postgresql | _. _. per aggiungere l'autorizzazione del nostro utente di replica per connettersi da altri nostri server: _! _ | Intende farlo nel caso in cui questo schiavo dovrebbe promosso maestro | _. _. Nota: _! _ | Con questa configurazione simile a quella del nostro Maestro permette di promuovere facilmente questo schiavo come un maestro in caso di necessità.
Per le operazioni di seguito, il login come utente di sistema postgres | _. _. Creiamo la directory di destinazione di wal degli archivi master | _. _. Rimuovere la directory di dati di postgresql | _. _. Fa il backup di base | _. _. personalizzare l'ip del tuo padrone e il nome del vostro utente di replica :
, vi verrà chiesto per la password del vostro utente di replica | _. _. È possibile configurare replica creando il file | _. _. con i seguenti parametri: _! _ | Nota: _! _ | Il file di trigger è il file che creiamo quando vogliamo sua replica di fermata di schiavo e inizia ad accettare le Scritture che è quando vogliamo promuoverla come master. Prima di promuovere un crash di schiavo del suo padrone, si prega di assicurarsi che il master iniziale venire no per evitare eventuali problemi di danneggiamento. 3 Radice, torniamo indietro e iniziamo il servizio: _! _ | Questo assicura che il servizio è stato avviato correttamente | _. _. Se ci colleghiamo al nostro Maestro, già possiamo controllare la nostra replica tra il master e lo slave primo è funzionale | _. _. Si connette al nostro maestro e ci colleghiamo in utente di sistema postgres | _. _. Poi ci colleghiamo a postgresql | _. _. Attiviamo la visualizzazione estesa e controlliamo la nostra replica | _. _. La nostra replica asincrona in streaming con il nostro primo slave è ben fatta. A questo punto abbiamo un Master replica | _. _. Classico schiavo | _. _. un singolo slave flusso asincrono | _. _. Il secondo slave | _. _. Ripetere la stessa cosa è stato fatto il primo slave ovviamente adattando il nome host nell'indirizzo ip e recovery.conf del file nell'ordine del check-nel file di configurazione principale, se anche voi volete abilitare l'archiviazione su questo secondo slave. 8 (Controllo e prova del nostro multi master replica slavi | _. _. Si collega al master e sei loggato utente postgres) :
Postgres01 (10.1.1.75) : Per rimuoverlo, dal Maestro
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;
Attivare l'aggiornamento automatico dei commenti