-- 两个不错的 ansible vagrant
# https://github.com/r-trigo/postgres-repmgr-vagrant
# https://github.com/2ndquadrant-it/ansible-postgresql-barman-playground
Vagrant.configure("2") do |config|
(1..2).each do |n|
config.vm.define "node#{n}" do |define|
define.ssh.insert_key = false
define.vm.box = "generic/centos7"
define.vm.hostname = "node#{n}"
# define.vm.network :private_network, ip: "192.168.56.1#{n}"
define.vm.network :public_network, ip: "192.168.56.1#{n}", virtualbox__hostonly: "vboxnet0"
# if you would like to use port forwarding, uncomment the line below
define.vm.network :forwarded_port, guest: 5432, host: "543#{n}"
define.vm.provider :virtualbox do |v|
v.cpus = 1
v.memory = 2048
v.name = "node#{n}"
end
#config.vm.synced_folder "./", "/vagrant_data"
end
config.vm.provision "shell", inline: <<-SHELL
echo -e "Stage 1"
echo redhat | passwd root --stdin ;
echo -e "192.168.56.11 node1 " >>/etc/hosts
echo -e "192.168.56.12 node2 " >>/etc/hosts
sed -i 's/vault.centos.org/mirrors.aliyun.com/g' /etc/yum.repos.d/CentOS*
echo -e "Stage 2"
sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
sudo yum -y install epel-release yum-utils
# Install PostgreSQL:
sudo yum-config-manager --enable pgdg14
sudo yum install postgresql14-server postgresql14 -y
# Optionally initialize the database and enable automatic start:
sudo /usr/pgsql-14/bin/postgresql-14-setup initdb
sudo systemctl enable postgresql-14
sudo systemctl start postgresql-14
echo -e "Stage 3"
sudo yum -y install repmgr_14*
echo -e " export PATH=/usr/pgsql-14/bin/:$PATH" >>/var/lib/pgsql/.bash_profile
SHELL
end
end