digoal
2016-10-30
postgresql , ha , zookeeper , etcd , haproxy , pacemaker , corosync , 高可用 , governor , stolon
数据库的ha是一个比较经典的话题,几乎所有的生产环境都会考虑给数据库部署ha。
postgresql 的ha方案也很多,在我的git里有两个自定义的ha脚本,有兴趣的童鞋可以参考一下原理。
<a href="https://github.com/digoal/sky_postgresql_cluster">单个虚拟ip, 自动failover, 手动failback, 需fence设备</a>
<a href="https://github.com/digoal/postgresql_ha_with_primary_standby_2vip">双虚拟ip, 自动failover, 自动failback, 需fence设备</a>
市面上也有很多成熟的pg ha方案,本文收集了一些,仅供参考。
1. 流复制,同步复制/自动降级,pacemaker , corosync
<a href="http://clusterlabs.org/wiki/pgsql_replicated_cluster">http://clusterlabs.org/wiki/pgsql_replicated_cluster</a>
2. postgresql failover managed by zookeeper
<a href="http://www.openscg.com/2013/04/postgresql-clustering/">http://www.openscg.com/2013/04/postgresql-clustering/</a>
<a href="https://github.com/jinty/zgres">https://github.com/jinty/zgres</a>
3. 仲裁使用etcd, stolon,仲裁很强壮
<a href="http://zhangwensheng.cn/blog/post/vincent/postgresql_ha_stolon_etcd">http://zhangwensheng.cn/blog/post/vincent/postgresql_ha_stolon_etcd</a>
<a href="https://github.com/sorintlab/stolon">https://github.com/sorintlab/stolon</a>
<a href="https://sgotti.me/post/stolon-introduction/">https://sgotti.me/post/stolon-introduction/</a>
4. 仲裁使用etcd, governor,仲裁很强壮
<a href="https://github.com/compose/governor">https://github.com/compose/governor</a>
5. 其他,还有比如基于drbd,或者基于共享存储的就不在罗列了。
如果没有fence设备,或者fence设备不可信的话,又或者需要大面积的部署pg节点,建议考虑etcd的方案,仲裁节点比较强壮,可以信任。
同时根据需求部署同步,或异步的流复制备节点,pg_rewind处理时间线分歧等。