From a9efe8e1daf92e113b899605e1e2a9489917cc40 Mon Sep 17 00:00:00 2001 From: jcesario Date: Mon, 16 May 2016 15:13:29 -0700 Subject: [PATCH] Vagrant: Discover Cluster with Orchestrator * Remove constant prompting of ssh-keygen * Only forward port for admin box * Admin box will discover 4 node cluster * Fix replication on 4 node --- Vagrantfile | 6 +++--- vagrant/admin-build.sh | 12 ++++++++++++ vagrant/base-build.sh | 17 +++++++---------- vagrant/db1-build.sh | 14 ++------------ vagrant/db1-my.cnf | 1 + vagrant/db2-build.sh | 16 +++------------- vagrant/db2-my.cnf | 1 + vagrant/db3-build.sh | 16 +++------------- vagrant/db3-my.cnf | 1 + vagrant/db4-build.sh | 16 +++------------- vagrant/db4-my.cnf | 1 + 11 files changed, 37 insertions(+), 64 deletions(-) mode change 100644 => 100755 vagrant/admin-build.sh mode change 100644 => 100755 vagrant/base-build.sh mode change 100644 => 100755 vagrant/db1-build.sh mode change 100644 => 100755 vagrant/db2-build.sh mode change 100644 => 100755 vagrant/db3-build.sh mode change 100644 => 100755 vagrant/db4-build.sh diff --git a/Vagrantfile b/Vagrantfile index 74df4fcc..6abe9c12 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -7,8 +7,8 @@ BOX = ENV['VAGRANT_BOX'].nil? || ENV['VAGRANT_BOX'].empty? ? 'nrel/CentOS-6.6-x8 VAGRANTFILE_API_VERSION = "2" system(" - if [ #{ARGV[0]} = 'up' ]; then - ssh-keygen -t rsa -b 768 -N '' -q -f vagrant/vagrant-ssh-key + if [[ #{ARGV[0]} = 'up' ]] && [[ ! -e 'vagrant/vagrant-ssh-key' ]]; then + ssh-keygen -t rsa -b 768 -N '' -q -f vagrant/vagrant-ssh-key fi ") @@ -32,7 +32,7 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| db.vm.network "private_network", ip: "192.168.57.20" + n.to_s db.vm.provision "shell", path: "vagrant/base-build.sh" if name == "admin" - config.vm.network "forwarded_port", guest:3000, host:3000 + db.vm.network "forwarded_port", guest:3000, host:3000 end end end diff --git a/vagrant/admin-build.sh b/vagrant/admin-build.sh old mode 100644 new mode 100755 index e69de29b..395a023f --- a/vagrant/admin-build.sh +++ b/vagrant/admin-build.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +# Install orchestrator +rpm -i /tmp/orchestrator-release/orchestrator*.rpm +/sbin/chkconfig orchestrator on +cp /usr/local/orchestrator/orchestrator-sample.conf.json /etc/orchestrator.conf.json +/sbin/service orchestrator start + +echo '* * * * * root /usr/bin/orchestrator -c discover -i db1' > /etc/cron.d/orchestrator-discovery + +# Discover instances +/usr/bin/orchestrator -c discover -i localhost \ No newline at end of file diff --git a/vagrant/base-build.sh b/vagrant/base-build.sh old mode 100644 new mode 100755 index 20c82ad0..ff0ce4d3 --- a/vagrant/base-build.sh +++ b/vagrant/base-build.sh @@ -25,9 +25,15 @@ if [[ -e /etc/redhat-release ]]; then # Setup mysql /sbin/chkconfig mysql on + + if [[ -e "/orchestrator/vagrant/${HOSTNAME}-my.cnf" ]]; then + rm -f /etc/my.cnf + cp /orchestrator/vagrant/${HOSTNAME}-my.cnf /etc/my.cnf + fi + /sbin/service mysql start cat <<-EOF | mysql -u root - CREATE DATABASE orchestrator; + CREATE DATABASE IF NOT EXISTS orchestrator; GRANT ALL PRIVILEGES ON orchestrator.* TO 'orc_client_user'@'%' IDENTIFIED BY 'orc_client_password'; GRANT SUPER, PROCESS, REPLICATION SLAVE, RELOAD ON *.* TO 'orc_client_user'@'%'; GRANT ALL PRIVILEGES ON orchestrator.* TO 'orc_client_user'@'localhost' IDENTIFIED BY 'orc_client_password'; @@ -35,15 +41,6 @@ if [[ -e /etc/redhat-release ]]; then GRANT ALL PRIVILEGES ON orchestrator.* TO 'orc_server_user'@'localhost' IDENTIFIED BY 'orc_server_password'; EOF - # Install orchestrator - rpm -i /tmp/orchestrator-release/orchestrator*.rpm - /sbin/chkconfig orchestrator on - cp /usr/local/orchestrator/orchestrator-sample.conf.json /etc/orchestrator.conf.json - /sbin/service orchestrator start - - # Discover instances - /usr/bin/orchestrator -c discover -i localhost - elif [[ -e /etc/debian_version ]]; then sudo echo exit 101 > /usr/sbin/policy-rc.d sudo chmod +x /usr/sbin/policy-rc.d diff --git a/vagrant/db1-build.sh b/vagrant/db1-build.sh old mode 100644 new mode 100755 index 8b876983..947d7a95 --- a/vagrant/db1-build.sh +++ b/vagrant/db1-build.sh @@ -1,18 +1,8 @@ -if [[ -e /etc/redhat-release ]]; then - sudo rm -rf /etc/my.cnf - sudo cp /orchestrator/vagrant/db1-my.cnf /etc/my.cnf - sudo service mysql start -elif [[ -e /etc/debian_version ]]; then +if [[ -e /etc/debian_version ]]; then sudo cp /orchestrator/vagrant/db1-my.cnf /etc/mysql/my.cnf sudo /etc/init.d/mysql restart - -sudo cat <<-EOF >> /root/.my.cnf - [client] - user = root - password = vagrant -EOF fi /usr/bin/mysql -uroot -ss -e 'GRANT REPLICATION SLAVE ON *.* TO "repl"@"192.168.57.%" IDENTIFIED BY "vagrant_repl"' -/usr/bin/mysql -uroot -ss -e 'CHANGE MASTER TO MASTER_HOST="192.168.57.202", MASTER_USER="repl", MASTER_PASSWORD="vagrant_repl"' +/usr/bin/mysql -uroot -ss -e 'CHANGE MASTER TO MASTER_HOST="192.168.57.202", MASTER_USER="repl", MASTER_PASSWORD="vagrant_repl", MASTER_CONNECT_RETRY=10, MASTER_RETRY_COUNT=36' /usr/bin/mysql -uroot -ss -e 'START SLAVE' diff --git a/vagrant/db1-my.cnf b/vagrant/db1-my.cnf index 29d4950d..7a5e5125 100644 --- a/vagrant/db1-my.cnf +++ b/vagrant/db1-my.cnf @@ -6,6 +6,7 @@ symbolic-links=0 server_id=1 log_bin log-slave-updates +report-host=db1 [mysqld_safe] log-error=/var/log/mysqld.log diff --git a/vagrant/db2-build.sh b/vagrant/db2-build.sh old mode 100644 new mode 100755 index 969148df..38c05186 --- a/vagrant/db2-build.sh +++ b/vagrant/db2-build.sh @@ -1,18 +1,8 @@ -if [[ -e /etc/redhat-release ]]; then - sudo rm -rf /etc/my.cnf - sudo cp /orchestrator/vagrant/db2-my.cnf /etc/my.cnf - sudo service mysql start -elif [[ -e /etc/debian_version ]]; then - sudo cp /orchestrator/vagrant/db2-my.cnf /etc/mysql/my.cnf +if [[ -e /etc/debian_version ]]; then + sudo cp /orchestrator/vagrant/db1-my.cnf /etc/mysql/my.cnf sudo /etc/init.d/mysql restart - -sudo cat <<-EOF >> /root/.my.cnf - [client] - user = root - password = vagrant -EOF fi /usr/bin/mysql -uroot -ss -e 'GRANT REPLICATION SLAVE ON *.* TO "repl"@"192.168.57.%" IDENTIFIED BY "vagrant_repl"' -/usr/bin/mysql -uroot -ss -e 'CHANGE MASTER TO MASTER_HOST="192.168.57.201", MASTER_USER="repl", MASTER_PASSWORD="vagrant_repl"' +/usr/bin/mysql -uroot -ss -e 'CHANGE MASTER TO MASTER_HOST="192.168.57.201", MASTER_USER="repl", MASTER_PASSWORD="vagrant_repl", MASTER_CONNECT_RETRY=10, MASTER_RETRY_COUNT=36' /usr/bin/mysql -uroot -ss -e 'START SLAVE' diff --git a/vagrant/db2-my.cnf b/vagrant/db2-my.cnf index 95af40e3..d9bc94b3 100644 --- a/vagrant/db2-my.cnf +++ b/vagrant/db2-my.cnf @@ -6,6 +6,7 @@ symbolic-links=0 server_id=2 log_bin log-slave-updates +report-host=db2 [mysqld_safe] log-error=/var/log/mysqld.log diff --git a/vagrant/db3-build.sh b/vagrant/db3-build.sh old mode 100644 new mode 100755 index 98fcef9a..38c05186 --- a/vagrant/db3-build.sh +++ b/vagrant/db3-build.sh @@ -1,18 +1,8 @@ -if [[ -e /etc/redhat-release ]]; then - sudo rm -rf /etc/my.cnf - sudo cp /orchestrator/vagrant/db3-my.cnf /etc/my.cnf - sudo service mysql start -elif [[ -e /etc/debian_version ]]; then - sudo cp /orchestrator/vagrant/db3-my.cnf /etc/mysql/my.cnf +if [[ -e /etc/debian_version ]]; then + sudo cp /orchestrator/vagrant/db1-my.cnf /etc/mysql/my.cnf sudo /etc/init.d/mysql restart - -sudo cat <<-EOF >> /root/.my.cnf - [client] - user = root - password = vagrant -EOF fi /usr/bin/mysql -uroot -ss -e 'GRANT REPLICATION SLAVE ON *.* TO "repl"@"192.168.57.%" IDENTIFIED BY "vagrant_repl"' -/usr/bin/mysql -uroot -ss -e 'CHANGE MASTER TO MASTER_HOST="192.168.57.201", MASTER_USER="repl", MASTER_PASSWORD="vagrant_repl"' +/usr/bin/mysql -uroot -ss -e 'CHANGE MASTER TO MASTER_HOST="192.168.57.201", MASTER_USER="repl", MASTER_PASSWORD="vagrant_repl", MASTER_CONNECT_RETRY=10, MASTER_RETRY_COUNT=36' /usr/bin/mysql -uroot -ss -e 'START SLAVE' diff --git a/vagrant/db3-my.cnf b/vagrant/db3-my.cnf index 0a743892..01995bfa 100644 --- a/vagrant/db3-my.cnf +++ b/vagrant/db3-my.cnf @@ -6,6 +6,7 @@ symbolic-links=0 server_id=3 log_bin log-slave-updates +report-host=db3 [mysqld_safe] log-error=/var/log/mysqld.log diff --git a/vagrant/db4-build.sh b/vagrant/db4-build.sh old mode 100644 new mode 100755 index cbe784cf..947d7a95 --- a/vagrant/db4-build.sh +++ b/vagrant/db4-build.sh @@ -1,18 +1,8 @@ -if [[ -e /etc/redhat-release ]]; then - sudo rm -rf /etc/my.cnf - sudo cp /orchestrator/vagrant/db4-my.cnf /etc/my.cnf - sudo service mysql start -elif [[ -e /etc/debian_version ]]; then - sudo cp /orchestrator/vagrant/db4-my.cnf /etc/mysql/my.cnf +if [[ -e /etc/debian_version ]]; then + sudo cp /orchestrator/vagrant/db1-my.cnf /etc/mysql/my.cnf sudo /etc/init.d/mysql restart - -sudo cat <<-EOF >> /root/.my.cnf - [client] - user = root - password = vagrant -EOF fi /usr/bin/mysql -uroot -ss -e 'GRANT REPLICATION SLAVE ON *.* TO "repl"@"192.168.57.%" IDENTIFIED BY "vagrant_repl"' -/usr/bin/mysql -uroot -ss -e 'CHANGE MASTER TO MASTER_HOST="192.168.57.202", MASTER_USER="repl", MASTER_PASSWORD="vagrant_repl"' +/usr/bin/mysql -uroot -ss -e 'CHANGE MASTER TO MASTER_HOST="192.168.57.202", MASTER_USER="repl", MASTER_PASSWORD="vagrant_repl", MASTER_CONNECT_RETRY=10, MASTER_RETRY_COUNT=36' /usr/bin/mysql -uroot -ss -e 'START SLAVE' diff --git a/vagrant/db4-my.cnf b/vagrant/db4-my.cnf index ed35ff48..3814d8a5 100644 --- a/vagrant/db4-my.cnf +++ b/vagrant/db4-my.cnf @@ -6,6 +6,7 @@ symbolic-links=0 server_id=4 log_bin log-slave-updates +report-host=db4 [mysqld_safe] log-error=/var/log/mysqld.log