Prerequirements
Requires vagrant 2.1.2+ due to bug: hashicorp/vagrant#10158 , I've used 2.1.5 from https://www.vagrantup.com/downloads.html (installed it on my ubuntu 18.04 from debian 64-bit package).
wget https://releases.hashicorp.com/vagrant/2.1.5/vagrant_2.1.5_x86_64.deb
dpkg -i vagrant_2.1.5_x86_64.deb
Do not forget to generate passwords for users!
update_passwords.sh
The script creates password hashes in files/passwords.yml and user/password list in passwords-unencrypted.txt
Access
- Change password from default 'dba': https://serversforhackers.com/c/create-user-in-ansible
- in virtualbox, connect to port 3622 with ssh
- do not forget to modify vagrant and dbaN users passwords if you are going to run tutorial engine in cloud
Create addition tutorial items
- check examples,
001-stored_procedure.sh
for single instance,002-broken-replication.sh
for master with one slave - Add files/N-testname.sh
- If needed add sql files
- Do not forget to chmod files/N-testname.sh to allow execution (755)
- modify files/tutorials.sh => add to options and case
- Update your vagrant instance with
vagrant up --provision
Running with LXC
- Install dependencies (on ubuntu 18.04)
sudo apt-get -y install build-essential git ruby lxc lxc-templates cgroup-lite redir
- install vagrant plugin
vagrant plugin install vagrant-lxc
- up with lxc provider
vagrant up --provider=lxc
Adding new tasks with LXC
It's not enough to just run vagrant up --provision, provisioning works only for first up, so destroy -f and run up again.
Running with Azure cloud
Based on https://blog.scottlowe.org/2017/12/11/using-vagrant-with-azure/
- Install azure cli https://docs.microsoft.com/en-us/cli/azure/install-azure-cli-apt?view=azure-cli-latest
- Install vagrant plugin
vagrant plugin install vagrant-azure
- auth with az tools: https://docs.microsoft.com/en-us/cli/azure/authenticate-azure-cli?view=azure-cli-latest
- Create a dummy box
vagrant box add azure-dummy https://github.com/azure/vagrant-azure/raw/v2.0/dummy.box --provider azure
- Create your service principal and save the output
az ad sp create-for-rbac
- get your account information
az account show
- Create your env file and fill it in a safe place, no spaces between
=
and other symbols,source envfile
at the end.
AZURE_TENANT_ID="put value of tenant from az ad sp create-for-rbac output"
AZURE_CLIENT_ID="put value of appId from az ad sp create-for-rbac output"
AZURE_CLIENT_SECRET="put value of password from az ad sp create-for-rbac output"
AZURE_SUBSCRIPTION_ID="put value of id from az account show output"
export AZURE_TENANT_ID AZURE_CLIENT_ID AZURE_CLIENT_SECRET AZURE_SUBSCRIPTION_ID
- In any bash shell intended for running vagrant up or ssh or destroy commands source access variables with
source envfile
- Modify playbook.yml to have strong passwords for vagrant and dbaN accounts.
- Modify
Vagrantfile:az.vm_name
if needed (and VM size, currently it's 1 core & 1GB) - Uncomment
require azure-plugin
at the beginning of Vagrantfile to avoid error:The resource group 'vagrant' is in deprovisioning state and cannot perform this operation.
- Start vagrant box
vagrant up --provider=azure
- Wait until creation and ansible run will be finished
- Connect with attender account:
ssh dbaN@tutorialengine.westus.cloudapp.azure.com
where N from 1 to 50 - Do not forget to remove VM after work to avoid wasting money:
vagrant destroy -f
- Check at https://portal.azure.com, VM should be destroyed completely after 10-15 minutes (Delete procedure is really slow)
Running with Amazon AWS cloud
https://github.com/mitchellh/vagrant-aws
- Install provider
vagrant plugin install vagrant-aws
vagrant box add dummy https://github.com/mitchellh/vagrant-aws/raw/master/dummy.box
- Update Vagrant file to provide your account details. If aws configure was executed on your machine it's enough to change just:
override.ssh.private_key_path = '~/.ssh/id_rsa-hadar'
aws.keypair_name = "nickolay.ihalainen"
- Start the box
vagrant up --provider=aws
- ssh dba1@ip
- Do not forget to shutdown with
vagrant destroy -f
to save money
Troubleshooting
- If you are not able to login with dba account with password, ansible failed first time, but finished after further vagrant up --provision, try to restart ssh daemon
vagrant ssh -- sudo systemctl restart ssh
- For Azure I was able to get the error
The resource group 'vagrant' is in deprovisioning state and cannot perform this operation.
It seems like it's not happening if I addrequire azure-plugin
at the beginning of Vagrantfile. But you can also wait until VM and "Resource group" will disappear after previous VM deletion. - If you are getting:
TASK [Include passwords] *******************************************************
fatal: [default]: FAILED! => {"ansible_facts": {"dbausers": {}}, "ansible_included_var_files": [], "changed": false, "message": "Could not find or access '/home/vagrant/tutorial/passwords.yml' on the Ansible Controller.\nIf you are using a module and expect the file to exist on the remote, see the remote_src option"}
Run ./update_passwords.sh
. It uses mkpasswd tool (on debian/ubuntu there is apt install whois
prerequirement.
On OS X there is no mkpasswd tool, but we can use slower simulation in python:
pip3 install passlib
replace mkpasswd -s --method=sha-512 with ./makepasswd-sha-512 in update_passwords.sh
Typical usage scenario
- Start vagrant box:
vagrant up --provider=lxc
- Create new tasks in files/NNN-testname.sh. Do not forget to add DESCRIPTION variable (menu item name).
- Update push changes to existing vagrant box:
vagrant provision
- When you finished for today stop box:
vagrant halt
- If you have created, but stopped box you can start it:
vagrant up
- Renaming task files:
- login to box:
vagrant ssh
- remove existing task files in box:
rm -rf tutorial/*
- exit from vagrant ssh
- push all tutorial files to the box:
vagrant provision
- During demonstration you should have pre-configured halted box, just start it:
vagrant up
. The box is already provisioned, thus it will not require internet connection to start.
Extending
Installing packages from apt
playbook.yml
file contains declarations what packages and files should be in the box. In order to add new packages add following lines before # keep allow password login at the end
comment:
- name: install sysbench
package:
name: sysbench
update_cache: no
state: present
update_cache: yes
instructs ansible to run apt update
before installing package.
Be careful with spaces and tabs, yml format is like a python programming language.
Using sysbench
- sysbench 1.0.11 is pre-installed.
- Could be used from task script:
use test < /home/vagrant/tutorial/001-stored_procedure-setup.sql
sb oltp_read_only.lua prepare
- Could be used from tmux window:
sb oltp_read_only.lua prepare
sb oltp_read_only.lua run --threads=2 --time=60
# you can also use full script path
sb /usr/share/sysbench/oltp_read_only.lua run
- or even directly from mysql cli
master [localhost] {msandbox} (test) > \! sb oltp_read_only.lua run
sysbench 1.0.11 (using system LuaJIT 2.1.0-beta3)
...
- Both for single and master-slave setup (executed against master).