Patroni高可用读写分离方案

栏目:云苍穹知识作者:金蝶来源:金蝶云社区发布:2024-09-23浏览:1

Patroni高可用读写分离方案

一 机器和vip资源

PostgreSQL

pg1: 192.168.56.105

pg2: 192.168.56.106

etcd

etcd: 192.168.56.104

vip

读写vip: 192.168.56.111(请参考链接https://vip.kingdee.com/article/442624225686179840)

只读vip: 192.168.56.112

二 配置keepalived动态绑定只读vip

pg1和pg2实例上动态在从节点上绑定只读vip(192.168.56.112),当从节点故障时会将只读vip绑定在主节点上。

pg1和pg2实例上部署keepalived

yum install -y keepalived

配置keepalived参数文件

[root@localhost ~]# cat /etc/keepalived/keepalived.conf


global_defs {

    router_id LVS_DEVEL

}

vrrp_script check_leader {

    script "/usr/bin/curl -s http://127.0.0.1:8000/leader -v 2>&1|grep '200 OK' >/dev/null"

    interval 2

    weight 10

}

vrrp_script check_replica {

    script "/usr/bin/curl -s http://127.0.0.1:8000/replica -v 2>&1|grep '200 OK' >/dev/null"

    interval 2

    weight 5

}

vrrp_script check_can_read {

    script "/usr/bin/curl -s http://127.0.0.1:8000/read-only -v 2>&1|grep '200 OK' >/dev/null"

    interval 2

    weight 10

}

vrrp_instance VI_1 {

    state BACKUP

    interface enp0s8

    virtual_router_id 211

    priority 100

    advert_int 1

    track_script {

        check_can_read

        check_replica

    }

    virtual_ipaddress {

       192.168.56.112

    }

}


启动keepalived

systemctl start keepalived

keepalived状态检查

systemctl status keepalived



三 只读vip和读写vip发生可漂移实现读写分离

主从状态查看

-bash-4.2$ patronictl  list



读写vip信息查看



只读vip信息查看



执行switchover操作

-bash-4.2$ patronictl switchover



读写vip漂移查看



只读vip漂移查看















 

Patroni高可用读写分离方案

一 机器和vip资源PostgreSQLpg1: 192.168.56.105pg2: 192.168.56.106etcdetcd: 192.168.56.104vip读写vip: 192.168.56.111(请参考链接htt...
点击下载文档
确认删除?
回到顶部
客服QQ
  • 客服QQ点击这里给我发消息