Skip to content

Commit

Permalink
extra: refactor 3nodes-vip vagrant file
Browse files Browse the repository at this point in the history
  • Loading branch information
ioguix committed Sep 23, 2020
1 parent 7ac317d commit 0134f91
Show file tree
Hide file tree
Showing 10 changed files with 375 additions and 357 deletions.
21 changes: 7 additions & 14 deletions extra/vagrant/3nodes-vip/Makefile
Original file line number Diff line number Diff line change
@@ -1,25 +1,18 @@
export VAGRANT_BOX_UPDATE_CHECK_DISABLE=1
export VAGRANT_CHECKPOINT_DISABLE=1

.PHONY: all create_vm pgsql-primary pgsql-replicas pacemaker cts prov clean validate
.PHONY: all up pgsql pacemaker cts clean check validate pcmk-stop

all: up

all: create_vm pgsql-replicas pacemaker

create_vm:
up:
vagrant up

pgsql-replicas: pcmk-stop pgsql-primary
vagrant up --provision-with=pgsql-replicas
pgsql: pcmk-stop
vagrant provision --provision-with=pgsql

pacemaker:
vagrant up --provision-with=pacemaker

pgsql-primary: pcmk-stop
vagrant up --provision-with=pgsql-primary

prov:
vagrant up --provision
vagrant provision --provision-with=pacemaker

clean:
vagrant destroy -f
Expand All @@ -34,7 +27,7 @@ validate:
fi

cts:
vagrant up --provision-with=cts
vagrant provision --provision-with=cts

pcmk-stop:
vagrant ssh -c 'if [ -f "/etc/corosync/corosync.conf" ]; then sudo pcs cluster stop --all --wait; fi'
Expand Down
110 changes: 59 additions & 51 deletions extra/vagrant/3nodes-vip/Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,28 @@ require 'ipaddr'
require 'yaml'

#ENV['VAGRANT_NO_PARALLEL'] = 'yes' # uncomment to forbid parallel execution
ENV["LANG"] = "C"
ENV["LC_ALL"] = "C"

boxname = 'centos/7' # vagrant box to use
pgver = '11' # pg version to use
hapass = 'hapass' # password for sys user hacluster
ssh_login = 'root' # ssh login to connect to the host when fencing a VM.
# put "./provision/id_rsa.pub" in your "~<ssh_login>/.ssh/authorized_keys"
master_ip = '10.20.30.5' # vIP assigned to master
pg_nodes = 'srv1', 'srv2', 'srv3' # first will be primary
log_node = 'log-sink' # name of the node receiving logs
vm_prefix = 'paf_vm' # VM prefix in libvrit
rhel_user = '' # RHEL user account
rhel_pass = '' # RHEL user account password
ENV["LANG"] = "C"
ENV["LC_ALL"] = "C"

boxname = 'centos/7' # vagrant box to use
pgver = '12' # pg version to use
hapass = 'hapass' # password for sys user hacluster
ssh_login = 'root' # ssh login to connect to the host when fencing a VM.
# put "./provision/id_rsa.pub" in your "~<ssh_login>/.ssh/authorized_keys"
base_ip = '10.20.30.50' # vIP assigned to master
vm_prefix = 'paf_3nvIP' # VM prefix in libvrit
rhel_user = '' # RHEL user account
rhel_pass = '' # RHEL user account password
pg_nodes = 'srv1', 'srv2', 'srv3' # first will be primary
log_node = 'log-sink' # name of the node receiving logs


if File.file?('vagrant.yml') and ( custom = YAML.load_file('vagrant.yml') )
boxname = custom['boxname'] if custom.has_key?('boxname')
pgver = custom['pgver'] if custom.has_key?('pgver')
hapass = custom['hapass'] if custom.has_key?('hapass')
ssh_login = custom['ssh_login'] if custom.has_key?('ssh_login')
master_ip = custom['master_ip'] if custom.has_key?('master_ip')
base_ip = custom['base_ip'] if custom.has_key?('base_ip')
pg_nodes = custom['pg_nodes'] if custom.has_key?('pg_nodes')
log_node = custom['log_node'] if custom.has_key?('log_node')
vm_prefix = custom['vm_prefix'] if custom.has_key?('vm_prefix')
Expand All @@ -32,16 +33,29 @@ end

Vagrant.configure(2) do |config|

############################################################################
# computes IPs

pgdata = "/var/lib/pgsql/#{pgver}/data"
next_ip = IPAddr.new(master_ip).succ
host_ip = (IPAddr.new(master_ip) & "255.255.255.0").succ.to_s
next_ip = IPAddr.new(base_ip).succ
host_ip = (IPAddr.new(base_ip) & "255.255.255.0").succ.to_s
nodes_ips = {}

( pg_nodes + [ log_node ] ).each do |node|
nodes_ips[node] = next_ip.to_s
next_ip = next_ip.succ
end

############################################################################
# general vagrant setup

# RHEL registration when needed
if Vagrant.has_plugin?('vagrant-registration')
config.registration.unregister_on_halt = false
config.registration.username = rhel_user
config.registration.password = rhel_pass
end

# don't mind about insecure ssh key
config.ssh.insert_key = false

Expand All @@ -57,62 +71,56 @@ Vagrant.configure(2) do |config|
lv.qemu_use_session = false
end

# disable default share
# sync the root of sources
config.vm.synced_folder ".", "/vagrant", disabled: true

config.vm.synced_folder "../../..", "/vagrant", type: "rsync",
rsync__exclude: [ ".git/" ]

config.vm.define pg_nodes.first, primary: true

############################################################################
# system setup for all nodes

config.vm.provision 'file', source: 'provision/id_rsa', destination: '/home/vagrant/.ssh/id_rsa'
config.vm.provision 'file', source: 'provision/id_rsa.pub', destination: '/home/vagrant/.ssh/id_rsa.pub'

(pg_nodes + [log_node]).each do |node|
config.vm.define node do |conf|
conf.vm.network 'private_network', ip: nodes_ips[node]
conf.vm.provision 'system-setup', type: 'shell', path: 'provision/system.bash',
args: [ node, rhel_user, rhel_pass ] + nodes_ips.keys.map {|n| "#{n}=#{nodes_ips[n]}"},
conf.vm.provision 'system', type: 'shell',
path: 'provision/system.bash',
args: [ node, pgver, base_ip, hapass, log_node ] +
nodes_ips.keys.map {|n| "#{n}=#{nodes_ips[n]}"},
preserve_order: true
end
end

# setup rsyslog to collect logs from other node on log-sink
config.vm.define log_node do |conf|
conf.vm.provision 'rsyslog-setup', type: 'shell', path: 'provision/log_sink.bash'
end

# common postgresql+pacemaker installation and setup
############################################################################
# build pgsql instances
pg_nodes.each do |node|
config.vm.define node do |conf|
conf.vm.provision 'cluster-common', type: 'shell', path: 'provision/cluster-common.bash',
args: [ pgver, hapass, master_ip ],
conf.vm.provision 'pgsql', type: 'shell',
path: 'provision/pgsql.bash',
args: [ node, pgver, pgdata, base_ip, pg_nodes.first ],
preserve_order: true
end
end

# build primary pgsql instance
config.vm.define pg_nodes.first, primary:true do |conf|
conf.vm.provision 'pgsql-primary', type: 'shell',
path: 'provision/pgsql-primary.bash',
args: [ pgver, pgdata, master_ip, pg_nodes.first ],
run: 'never'
end

# replicas setup. Use "vagrant up --provision-with=pgsql-replicas"
pg_nodes[1..-1].each do |node|
config.vm.define node do |conf|
conf.vm.provision 'pgsql-replicas', type: 'shell', path: 'provision/pgsql-replicas.bash',
args: [ pgver, pgdata, master_ip, node ], run: 'never'
end
end

# cluster setup. Use "vagrant up --provision-with=pacemaker"
############################################################################
# cluster setup
pg_nodes.each do |node|
config.vm.define node do |conf|
conf.vm.provision 'pacemaker', type: 'shell', path:'provision/pacemaker.bash',
args: [ pgver, hapass, master_ip, ssh_login,
conf.vm.provision 'pacemaker', type: 'shell',
path: 'provision/pacemaker.bash',
args: [ pgver, hapass, base_ip, ssh_login,
vm_prefix, host_ip, pgdata ] + pg_nodes,
run: 'never'
preserve_order: true
end
end

# cluster test suite setup. Use "vagrant up --provision-with=cts"
config.vm.provision 'cts', type: 'shell', path: 'provision/cts.bash', run: 'never'
############################################################################
# cluster test suite setup. Use "vagrant provision --provision-with=cts"
config.vm.provision 'cts', type: 'shell',
path: 'provision/cts.bash',
run: 'never'
end
92 changes: 0 additions & 92 deletions extra/vagrant/3nodes-vip/provision/cluster-common.bash

This file was deleted.

20 changes: 0 additions & 20 deletions extra/vagrant/3nodes-vip/provision/log_sink.bash

This file was deleted.

35 changes: 21 additions & 14 deletions extra/vagrant/3nodes-vip/provision/pacemaker.bash
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,21 @@ set -o errexit
set -o nounset
set -o pipefail

PGVER="$1"
HAPASS="$2"
MASTER_IP="$3"
SSH_LOGIN="$4"
VM_PREFIX="$5"
HOST_IP="$6"
PGDATA="$7"
declare PCMK_VER
declare -a PGSQLD_RSC_OPTS
declare -r PGVER="$1"
declare -r HAPASS="$2"
declare -r PRIM_IP="$3"
declare -r SSH_LOGIN="$4"
declare -r VM_PREFIX="$5"
declare -r HOST_IP="$6"
declare -r PGDATA="$7"
shift 7
NODES=( "$@" )
declare -r -a NODES=( "$@" )

CUSTOMDIR="${PGDATA}/conf.d"
declare -r CUSTOMDIR="${PGDATA}/conf.d"

# extract pacemaker major version
PCMK_VER=$(yum info --quiet pacemaker|grep ^Version)
PCMK_VER="${PCMK_VER#*: }" # extract x.y.z
PCMK_VER="${PCMK_VER:0:1}" # extract x
Expand Down Expand Up @@ -66,6 +69,7 @@ done

PGSQLD_RSC_OPTS=(
"ocf:heartbeat:pgsqlms"

"bindir=/usr/pgsql-${PGVER}/bin"
"pgdata=${PGDATA}"
"recovery_template=${CUSTOMDIR}/recovery.conf.pcmk"
Expand Down Expand Up @@ -93,13 +97,16 @@ if [ "$PCMK_VER" -eq 1 ]; then
pcs -f cluster1.xml resource master pgsqld-clone pgsqld notify=true
fi

pcs -f cluster1.xml resource create pgsql-master-ip \
"ocf:heartbeat:IPaddr2" "ip=${MASTER_IP}" cidr_netmask=24 \
pcs -f cluster1.xml resource create pgsql-pri-ip \
"ocf:heartbeat:IPaddr2" "ip=${PRIM_IP}" cidr_netmask=24 \
op monitor interval=10s

pcs -f cluster1.xml constraint colocation add pgsql-master-ip with master pgsqld-clone INFINITY
pcs -f cluster1.xml constraint order promote pgsqld-clone "then" start pgsql-master-ip symmetrical=false
pcs -f cluster1.xml constraint order demote pgsqld-clone "then" stop pgsql-master-ip symmetrical=false
pcs -f cluster1.xml constraint colocation \
add pgsql-pri-ip with master pgsqld-clone INFINITY
pcs -f cluster1.xml constraint order \
promote pgsqld-clone "then" start pgsql-pri-ip symmetrical=false
pcs -f cluster1.xml constraint order \
demote pgsqld-clone "then" stop pgsql-pri-ip symmetrical=false

pcs cluster cib-push scope=configuration cluster1.xml --wait

Expand Down
Loading

0 comments on commit 0134f91

Please sign in to comment.