介绍
前一段时间,我的任务是为PostgreSQL开发故障转移群集,该群集在同一城市中通过光纤连接的多个数据中心中运行,并且能够承受一个数据中心的故障(例如,断电)。我选择Pacemaker作为负责容错的软件,因为这是RedHat用于创建故障转移群集的官方解决方案。很好是因为RedHat为此提供了支持,并且因为它是一种通用(模块化)解决方案。借助它的帮助,不仅可以为PostgreSQL提供容错能力,而且还可以为其他服务提供容错能力,无论是使用标准模块还是根据特定需求创建它们。
这个决定引起了一个合理的问题:故障转移群集的容错性如何?为了对此进行研究,我开发了一个测试台,可以模拟集群节点上的各种故障,等待恢复,重建故障节点,然后继续循环测试。最初,该项目被称为hapgsql,但是随着时间的流逝,我对名称只有一个元音感到无聊。因此,我开始将容错数据库(并指向它们的浮动IP)称为krogan(计算机游戏中的角色,在其中复制了所有重要器官),以及节点,群集和项目本身-tuchanka(krogan所在的星球)。
现在,管理层已允许根据MIT许可为开源社区开放该项目。 README很快将被翻译成英文(因为预计Pacemaker和PostgreSQL开发人员将是主要的使用者),因此我决定以本文的形式安排README的旧俄文版本(部分)。
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 ( )
, , slave- hot standby read only- ( ).
- . PostgreSQL ( PostgreSQL , ( ), Pacemaker). , ( float IP). -, . ̒ ( ) (), ( shared_buffers ..), , ( ) -. ( read only-) , .
, .
witness
witness (quorum device) Tuchanka1, . witness , , . 2 3, . .
Tuchanka1
- Tuchanka1. witness -. , float IP.
Tuchanka2 ()
. , . ( read only), float IP: krogan2 — , krogan2s1 — . , .
, .
Tuchanka2
- witness . - , float IP: . , , ( connection ..) float IP. .
Tuchanka4 ( )
. , read-only ( ). Tuchanka4 — , , . . ( ) - , PostgreSQL.
, . , , , -, -, . float IP. , - sql proxy, , . sql proxy, , . , (connection pool), .. ( SQL proxy , ).
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 -)
, -, . quorum device . - , — . , ANY (slave1, slave2), , , . float IP . Tuchanka4 float IP . read-only SQL- sql proxy ( ), float IP, — .
Tuchanka3
- . float IP , — float IP ( , float IP). . ( ) - ( ).
. , README. .
. test/failure
. , . , :
test/failure 2 3
. , . , tmux. Tmux tmux , - default tmux, tmux. . setup
.
, ( ) . Tuchanka2. :
- . :
- failure — ( ), .
- reaction — , . , , , . , , ( (Tuchanka3 Tuchanka4)), , , .
- deviation — () reaction « ».
- count — .
- , . (), ̒ . (> 5 ) - .
- heart () — . float IP . .
- beat () — « », heart , float IP. . Tuchanka1 float IP ( , ), (), beat, heart .
-
pcs mon
. , . - . — . CPU Load ( ), , System Load ( Load Average, 5, 10 15 ), .
- , . — — .
. , , . , . ( ) - (> 5 , ) , - .
:
- , .
- Ready? — ( ).
- (reaction).
- 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 :