$net_base = "10.10.99" $num_nodes = 2 $hostfile = "" $hostlist1 = "" $hostlist2 = "" (1..$num_nodes).each do |i| $hostfile += "#{$net_base}.#{i+10} master-#{i}\n" $hostlist1 += "#{$net_base}.#{i+10}," end (1..$num_nodes).each do |i| $hostfile += "#{$net_base}.#{i+20} slave-#{i}\n" $hostlist2 += "#{$net_base}.#{i+20}," end $common_script= <> /etc/hosts export DEBIAN_FRONTEND=noninteractive apt-get update -y apt-get install -y apt-transport-https curl -sS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bash -s -- --mariadb-server-version=$4 apt-get install -y mariadb-server mariadb-backup mysql -e "CREATE USER sstuser@'localhost' IDENTIFIED BY 'secret'; GRANT ALL ON *.* TO sstuser@'localhost';" mysql -e "CREATE USER sstuser@'%.%.%.%' IDENTIFIED BY 'secret'; GRANT ALL ON *.* TO sstuser@'%.%.%.%';" systemctl stop mariadb sed -e "s/#server#/$2/g" \ -e "s/#ip#/#{$net_base}.$2/g" \ -e "s/#nodelist#/$3/g" \ -e "s/#cluster_num#/$5/g" \ < /vagrant/galera.cnf \ > /etc/mysql/mariadb.conf.d/z-galera.cnf if test "$1" = "1" then galera_new_cluster if test "$2" -lt 20 then mysql -e "CREATE USER repl@'%' IDENTIFIED BY 'secret'" mysql -e "GRANT ALL ON *.* TO repl@'%'" mysql -e "RESET MASTER" mysql -e "CREATE DATABASE test;" else mysql -e "CHANGE MASTER TO MASTER_HOST='master-1', MASTER_USER='repl', MASTER_PASSWORD='secret'" mysql -e "START SLAVE" fi else systemctl start mariadb fi END Vagrant.configure("2") do |config| config.vm.box = "ubuntu/bionic64" config.vm.provider "virtualbox" do |v| v.memory = 2048 v.cpus = 2 end (1..$num_nodes).each do |i| config.vm.define "master-#{i}" do |config| config.vm.network "private_network", ip: "#{$net_base}.#{i+10}" config.vm.hostname = "slave-#{i}" config.vm.provision "shell", inline: "hostnamectl set-hostname master-#{i}" config.vm.provision "shell", inline: $common_script, args: ["#{i}", "#{i+10}", "#{$hostlist1}", "10.5.9", 1] end end (1..$num_nodes).each do |i| config.vm.define "slave-#{i}" do |config| config.vm.network "private_network", ip: "#{$net_base}.#{i+20}" config.vm.hostname = "slave-#{i}" config.vm.provision "shell", inline: "hostnamectl set-hostname slave-#{i}" config.vm.provision "shell", inline: $common_script, args: ["#{i}", "#{i+20}", "#{$hostlist2}","10.5.9", 2] end end end