Modelagem de cluster de failover com PostgreSQL e Pacemaker

Introdução



Há algum tempo, recebi a tarefa de desenvolver um cluster de failover para PostgreSQL que opera em vários data centers, unidos por fibra dentro da mesma cidade, e pode resistir a uma falha (por exemplo, falta de energia) de um data center. Escolhi o Pacemaker como o software responsável pela tolerância a falhas, pois esta é a solução oficial da RedHat para a criação de clusters de failover. A boa notícia é que a RedHat fornece suporte para isso, e essa solução é universal (modular). Com sua ajuda, será possível fornecer tolerância a falhas não só para o PostgreSQL, mas também para outros serviços, seja usando módulos padrão, seja criando-os para necessidades específicas.



Uma questão razoável surgiu para esta decisão: quão resiliente será um cluster de failover? Para investigar isso, desenvolvi uma bancada de teste que simula várias falhas nos nós do cluster, aguarda uma recuperação, recupera o nó com falha e continua o teste em um loop. Inicialmente, esse projeto se chamava hapgsql, mas com o tempo fiquei entediado com o nome, que tem apenas uma vogal. Portanto, comecei a chamar bancos de dados tolerantes a falhas (e IPs flutuantes apontando para eles) krogan (um personagem de um jogo de computador, em que todos os órgãos importantes são duplicados) e nós, clusters e o próprio projeto - tuchanka (o planeta onde vivem os krogan).



open source- MIT. README ( , Pacemaker PostgreSQL), README () .



Krogan em tuchanka



VirtualBox. 12 ( 36GiB), 4 ( ). PostgreSQL, -, witness c quorum device ( -), 50%/50%, . -: , , quorum device. PostgreSQL, -: , , witness c quorum device. -. , , .



ntpd , ntpd (orphan mode). witness NTP-, , . witness , ( ). HTTP proxy witness, Yum-. , , , witness .





v0. CentOS 7 PostgreSQL 11 VirtualBox 6.1.





-, -. split-brain Pacemaker, STONITH (Shoot The Other Node In The Head) fencing. : , - , , «» , , IPMI UPS. , IPMI UPS . , ( ) -. stonith- (IPMI, UPS ..) .



. , , . «+1» . , , , .. split-brain. , , , watchdog, , IPMI.



( -), 50%/50% (-), . quorum device — , -. ( ), 50%/50%. , quorum device, witness ( repmgr, ).



, , , . , ( ?), IP (float IP). IP, Pacemaker ( ). () , , ( ).



Tuchanka1 ( )





Tuchanka1



, , slave- hot standby read only- ( ).



- . PostgreSQL ( PostgreSQL , ( ), Pacemaker). , ( float IP). -, . Ě’ ( ) (), ( shared_buffers ..), , ( ) -. ( read only-) , .



, .



witness



testemunha de falha



witness (quorum device) Tuchanka1, . witness , , . 2 3, . .



Tuchanka1



falha Tuchanka1



- Tuchanka1. witness -. , float IP.



Tuchanka2 ()





Tuchanka2



. , . ( read only), float IP: krogan2 — , krogan2s1 — . , .



, .



Tuchanka2



falha Tuchanka2



- witness . - , float IP: . , , ( connection ..) float IP. .



Tuchanka4 ( )





Tuchanka4



. , read-only ( ). Tuchanka4 — , , . . ( ) - , PostgreSQL.



, . , , , -, -, . float IP. , - sql proxy, , . sql proxy, , . , (connection pool), .. ( SQL proxy , ).



Tuchanka4



falha Tuchanka4



- (.. ) witness . - : , float IP ( read-write ); , float IP ( read only-).



, : float IP , . , sql proxy float IP; sql proxy , float IP URL . libpq IP, . , , , JDBC, sql proxy. , float IP , , .



: - . , - , , , ( ).



Tuchanka3 (3 -)





Tuchanka3



, -, . quorum device . - , — . , ANY (slave1, slave2), , , . float IP . Tuchanka4 float IP . read-only SQL- sql proxy ( ), float IP, — .



Tuchanka3



falha Tuchanka3



- . float IP , — float IP ( , float IP). . ( ) - ( ).



. , README. .





. test/failure. , . , :



test/failure 2 3


. , . , tmux. Tmux tmux , - default tmux, tmux. . setup.



captura de tela de `teste / falha`



, ( ) . Tuchanka2. :



  1. . :

    • failure — ( ), .
    • reaction — , . , , , . , , ( (Tuchanka3 Tuchanka4)), , , .
    • deviation — () reaction « ».
    • count — .
  2. , . (), Ě’ . (> 5 ) - .
  3. heart () — . float IP . .
  4. beat () — « », heart , float IP. . Tuchanka1 float IP ( , ), (), beat, heart .
  5. pcs mon. , .
  6. . — . CPU Load ( ), , System Load ( Load Average, 5, 10 15 ), .
  7. , . — — .


. , , . , . ( ) - (> 5 , ) , - .



:



  1. , .
  2. Ready? — ( ).
  3. (reaction).
  4. Fix — «». .


, :



  • ForkBomb: "Out of memory" -.
  • OutOfSpace: . , , , , , PostgreSQL .
  • Postgres-KILL: PostgreSQL killall -KILL postgres.
  • Postgres-STOP: PostgreSQL killall -STOP postgres.
  • PowerOff: «» VBoxManage controlvm "" poweroff.
  • Reset: VBoxManage controlvm "" reset.
  • SBD-STOP: SBD killall -STOP sbd.
  • ShutDown: SSH systemctl poweroff, .
  • UnLink: , VBoxManage controlvm "" setlinkstate1 off.


tmux "kill-window" Ctrl-b &, "detach-client" Ctrl-b d: , tmux , .





  • watchdog sbd , . , , , Corosync Pacemaker, sbd. Corosync PR#83 ( GitHub sbd), master. ( PR#83), Pacemaker - , , RedHat 8 . «» , , , killall -STOP corosync, .



  • Pacemaker CentOS 7 sync_timeout quorum device, , . sync_timeout quorum device ( setup/setup1). Pacemaker, ( ), .



  • , LC_MESSAGES ( ) , , ru_RU.UTF-8, postgres , locale UTF-8, , ( pacemaker+pgsqlms(paf) postgres), UTF-8 . PostgreSQL , . , LC_MESSAGES=en_US.UTF-8 () .



  • wal_receiver_timeout ( 60s), PostgreSQL-STOP tuchanka3 tuchanka4 . , , . wal_receiver_timeout=0 PostgreSQL.



  • PostgreSQL ForkBomb ( ). ForkBomb . tuchanka3 tuchanka4, - , , . , - ( ). , . , , .





Deviant Art c :



PermissĂŁo Noosborn




All Articles