Giter VIP home page Giter VIP logo

ansible-pgpool's Introduction


An ansible note



PostgreSQL-11 高可用主从模式 基于pgpool官方exampleansible工具实现自动化

Cluster System Configuration


支持离线安装

一、将postgresql-11 rpm包下载至down/postgres-11,目录自行创建

二、将pgpool-ii rpm包下载至down/pgpool-ii,目录自行创建


快速指南

  • 拉取仓库
git clone https://github.com/shensw4/ansible-pgpool.git /root/ansible && cd /root/ansible
  • 安装pip
# 已安装的请跳过
curl -sSl https://bootstrap.pypa.io/get-pip.py | python -
  • 安装ansible, sshpass
pip install ansible==2.8.7
# 国内用户建议用aliyun镜像加速
pip install ansible==2.8.7 -i https://mirrors.aliyun.com/pypi/simple/

# 如果已经对节点分发好SSH Key的请跳过
yum install -y sshpass
  • 设置ansible配置文件变量
export ANSIBLE_CONFIG=/root/ansible/ansible_pgsql.cfg
  • 分发SSH Key
# 如果主备服务器密码一致,使用如下
ansible-playbook -k generate-key-use-password.yaml

# 如果主备节点密码不一致,则为每台节点手动生成
ssh-keygen -t rsa -b 2048
ssh-copy-id -i ~/.ssh/id_rsa.pub root@server1
ssh-copy-id -i ~/.ssh/id_rsa.pub root@server2
ssh-copy-id -i ~/.ssh/id_rsa.pub root@server3 # ...
  • 编辑ansible inventory文件
# 修改pgsqlPrimary,pgsqlStandby 的IP地址,端口
# 修改pgsqlHA的CIDR,VIP,密码等
cp -a hosts-pgsql-ha.example hosts-pgsql-ha
vim hosts-pgsql-ha
  • 开始部署
ansible-playbook postgresql-ha.yaml
  • 查看节点状态
psql -h 'yourVIP' -p 'yourPgpoolPort' -U pgpool postgres -c "show pool_nodes"
  • 恢复指定node
# 因为第一次部署,除主节点外其他节点都未启动,需要同步数据到其他节点
# 节点故障也可使用该命令恢复启动节点,恢复时间随数据容量增大

su - postgres
pcp_recovery_node -h 'yourVIP' -p 9898 -U pgpool -n 1
  • 热添加节点
# 查看ansible inventory文件
cat hosts-pgsql-ha
#...... # 此处省略
[pgsqlStandby]
172.16.0.33 pgport=5432 pgpool_port=5433 pcp_port=9898 watchdog_port=9000 wd_heartbeat_port=9694 isnew=false
172.16.0.34 pgport=5432 pgpool_port=5433 pcp_port=9898 watchdog_port=9000 wd_heartbeat_port=9694 isnew=false
#..... # 此处省略

# 编辑inventory文件添加新节点, 新节点依赖ansible inventory文件的isnew字段,需设置'isnew'=true
vim hosts-pgsql-ha

cat hosts-pgsql-ha
#...... # 此处省略
[pgsqlStandby]
172.16.0.33 pgport=5432 pgpool_port=5433 pcp_port=9898 watchdog_port=9000 wd_heartbeat_port=9694 isnew=false
172.16.0.34 pgport=5432 pgpool_port=5433 pcp_port=9898 watchdog_port=9000 wd_heartbeat_port=9694 isnew=false
172.16.0.35 pgport=5432 pgpool_port=5433 pcp_port=9898 watchdog_port=9000 wd_heartbeat_port=9694 isnew=true
#..... # 此处省略

# 执行
ansible-playbook pgsqlStandby.yaml

ansible-pgpool's People

Contributors

shensw4 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.