Thursday 3 July 2014

vagrant box with percona-XtraDB centos image

For testing the mysql cluster I am using the percona-XtraDB, on centos server. I choose the basic centos6.5 image for that and later I have installed the percona-XtraDB on that and did a packaging of the same, so that we all can do a quick test of the same.

Step 1:
Install virtualbox on your system. [4.1 onwards or the latest would be good. ]
 [https://www.virtualbox.org/wiki/Downloads]

Step 2:
Install the vagrant on your system.
[https://www.vagrantup.com/downloads.html ]

Step 3: 
mkdir amit-percona && cd amit-percona

Step 4:
 Download the vagrantfile from the following share location:
https://drive.google.com/file/d/0B02LZ59YLdSddDRFTDdHaWJDQXc/edit?usp=sharing

 $ vagrant box add amit-percona-XtraDB amit-percona-XtraDB


output: [ something like following: ]

==> box: Adding box 'amit-percona-XtraDB' (v0) for provider:
    box: Downloading: file:///home/amit/vagrant-boxes/amit-percona/amit-percona-XtraDB
==> box: Successfully added box 'amit-percona-XtraDB' (v0) for 'virtualbox'!

if you type: $ vagrant box list
amit-percona-XtraDB  (virtualbox, 0)
[ you will see something like this. ]

Step 5: 
 5.a: $ mv ~/.vagrant.d/boxes/amit-percona-XtraDB/0/virtualbox/include/_Vagrantfile Vagrantfile

NOTE: This above command will copy custom vagrantfile and moved to your current folder with the name Vagrantfile. [ instead of doing vagrant init ]

 5.b: cat ~/.vagrant.d/boxes/amit-percona-XtraDB/0/virtualbox/include/ssh_config >> ~/.ssh/config

NOTE: This will add my ssh_config to your .ssh/config file.

Step 6:
 $ vagrant up

NOTE: it will start 3 vagrant instance as name cenos[2-4]

Step 7:
 $ vagrant global-status
[ You can see your box information ]

Step 8:
To login: ssh centos2
               ssh centos3
               ssh centos4

[this will work out-of-box because, we have added the ssh/config already, with a private key that comes with vagrant.

or you can do:
ssh vagrant@10.0.10.2 [ password: vagrant ]


NOTE:$ rpm -qa | grep -i percona
percona-release-0.0-1.x86_64
Percona-XtraDB-Cluster-galera-2-2.10-1.188.rhel6.x86_64
Percona-XtraDB-Cluster-server-55-5.5.37-25.10.756.el6.x86_64
Percona-XtraDB-Cluster-client-55-5.5.37-25.10.756.el6.x86_64
Percona-Server-shared-compat-5.1.68-rel14.6.551.rhel6.x86_64
percona-xtrabackup-2.2.3-4982.el6.x86_64


## Enjoy the 3 running vagrant instance that you can play your mysql cluster.






###############################################
###############################################

No need to follow the following section, if you are not interested on how I did this:

################# How I did this ####################

If you are still interested how I did all this then please follow the following notes:

Step 1:
Install virtualbox on your system. [4.1 onwards, the latest would be good. ]

Step 2:
Install the vagrant on your system.

Step 3:
$ vagrant box add centos https://github.com/2creatives/vagrant-centos/releases/download/v6.5.3/centos65-x86_64-20140116.box

  - This will download the base centos image. [ around 250MB ]
 - NOTE: Will update this blog, when I can share my vagrant box. [ that is with percona-XtraDB cluster for mysql. ]


Step 4:
$ vagrant init centos

 - This will create Vagrantfile at your present directory.

Step 5:

Over write your Vagrantfile with the following entry:

VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.define "centos2" do |centos2|
    centos2.vm.box = "centos"
    centos2.vm.network :private_network, ip: "10.0.10.2"
  end

- Because this will give you a private_network ip of 10.0.10.2 at your system, and only from your system it can be accessable.

Step 6:
login to the vagrant system:
Option a: vagrant ssh centos2 # Need to be in the same directory where you have this Vagrantfile
or
Option b:  ssh vagrant@10.0.10.2  # password: vagrant

Step 7:
Installed the percona-XtraDB-Clustier over here:

  7a: sudo su -

  7b: # rpm -Uhv http://www.percona.com/downloads/percona-release/percona-release-0.0-1.x86_64.rpm
Retrieving http://www.percona.com/downloads/percona-release/percona-release-0.0-1.x86_64.rpm

  7c: yum -y install Percona-XtraDB-Cluster-server Percona-XtraDB-Cluster-client Percona-Server-shared-compat percona-xtrabackup

Step 8:
Once the installation complete I have update the VagrantFile to run the same instance 3 time.

VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|

  config.vm.define "centos4" do |centos4|
    centos4.vm.box = "centos"
    centos4.vm.network :private_network, ip: "10.0.10.4"
# centos4.vm.network "public_network", :bridge => 'wlan0', :ip => "192.168.0.30"
  end

  config.vm.define "centos2" do |centos2|
    centos2.vm.box = "centos"
    centos2.vm.network :private_network, ip: "10.0.10.2"
# centos4.vm.network "public_network", :bridge => 'wlan0', :ip => "192.168.0.31"
  end

  config.vm.define "centos3" do |centos3|
    centos3.vm.box = "centos"
    centos3.vm.network :private_network, ip: "10.0.10.3"
# centos4.vm.network "public_network", :bridge => 'wlan0', :ip => "192.168.0.32"
  end

end

NOTE: If you want your vagrant box need to get public_ip, you do the same using the following: [ as comment at above line ]
centos4.vm.network "public_network", :bridge => 'wlan0', :ip => "192.168.0.30"

Step 9: create a ssh_config file for you all that you can add the same at your ~/.ssh/config file

 Host centos2
    HostName 10.0.10.2
    Port 22
    User vagrant
    IdentityFile ~/.vagrant.d/insecure_private_key
Host centos3
    HostName 10.0.10.3
    Port 22
    User vagrant
    IdentityFile ~/.vagrant.d/insecure_private_key
Host centos4
    HostName 10.0.10.4
    Port 22
    User vagrant
    IdentityFile ~/.vagrant.d/insecure_private_key

Step 10: Repackage the same vagrant box, so that it can be re-used:

$ vagrant package centos2 --output amit-percona-XtraDB --vagrantfile Vagrantfile --include ssh_config
==> centos2: Exporting VM...
==> centos2: Compressing package to: /home/amit/vagrant-boxes/centos/amit-percona-XtraDB
==> centos2: Packaging additional file: ssh_config
==> centos2: Packaging additional file: Vagrantfile


Step 10: Now you can use my image:
 du -ksh amit-percona-XtraDB
365M    amit-percona-XtraDB

It having the base image where percona-XtraDB is install with the updated Vagrantfile that all the setting and with a ssh config file, that you can add to your ssh config so that you can use it.


No comments:

Post a Comment