devops(2) : vagrant - (mosg)

14
DevOps (2) Vagrant Mulodo Vietnam Co., Ltd.

Upload: soshi-nemoto

Post on 11-Apr-2017

478 views

Category:

Software


5 download

TRANSCRIPT

Page 1: DevOps(2) : Vagrant  -  (MOSG)

DevOps (2)Vagrant

Mulodo Vietnam Co., Ltd.

Page 2: DevOps(2) : Vagrant  -  (MOSG)

What’s DevOps? Mindset of filling gap between Dev and Ops. It’s not any technologies or solutions.

C.A.M.S Culture

Bust silos. Don’t say “no”. Involve everyone. Automation

XXX as Code. Ask machines to do same things. Metrics

monitor, find failure, Improve, make a plan. Share

Dev->Ops, Ops->Dev, share metrics.

Feedback of previous study

Page 3: DevOps(2) : Vagrant  -  (MOSG)

What’s DevOps? mindset of DevOps <—- DevOps(1)

Infrastructure as Code: Vagrant <———————————- DevOps(2) Now Ansible (Fabric)

What’s for ‘Infrastructure as Code’?

Scope of this study

Page 4: DevOps(2) : Vagrant  -  (MOSG)

Vagrant is one of a ‘VM manager’

What’s Vagrant?Virtu

alBo

x

VMwar

e

AWS

EC2

Vagrant $ vagrant box listcentos6.4 (virtualbox, 0)centos7.0 (virtualbox, 0)precise64 (vmware_fusion)

Page 5: DevOps(2) : Vagrant  -  (MOSG)

Task trigger : Chef, Ansible

What’s Vagrant?

Vagrant virtual machine

Task

Chef

Ansible

Page 6: DevOps(2) : Vagrant  -  (MOSG)

BOX : Virtual server images for Vagrant.

Try : boxes

$ vagrant box listcentos6.5 (virtualbox, 0)centos7.0 (virtualbox, 0)precise64 (vmware_fusion)

Adding boxes.

$ vagrant box add {NAME} {URL}

Boxes: http://www.vagrantbox.es/ https://atlas.hashicorp.com/boxes/search :

Page 7: DevOps(2) : Vagrant  -  (MOSG)

Plug-in : additional modules sahara : sandbox for Vagrant vagrant-aws : AWS tools for Vagrant vagrant-omnibus : utilities for many tools.

Try : plug-ins

$ vagrant plugin list$ vagrant plugin install sahara$ vagrant plugin install vagrant-aws$ vagrant plugin install vagrant-omnibus$ vagrant plugin listsahara (0.0.17)vagrant-aws (0.6.0)vagrant-omnibus (1.4.1)

Page 8: DevOps(2) : Vagrant  -  (MOSG)

init : initialize virtual machine

Try : initialize

$ vagrant box listcentos6.5 (virtualbox, 0)centos7.0 (virtualbox, 0)precise64 (vmware_fusion)$ vagrant init centos6.5A `Vagrantfile` has been placed in this directory. You are nowready to `vagrant up` your first virtual environment! Please readthe comments in the Vagrantfile as well as documentation on`vagrantup.com` for more information on using Vagrant.$ ls VagrantfileVagrantfile$

Page 9: DevOps(2) : Vagrant  -  (MOSG)

up : launch virtual machine at the directory

Try : up, status, halt

$ vagrant up : :$ vagrant statusCurrent machine states:

default running (virtualbox)

The VM is running. To stop this VM, you can run `vagrant halt` toshut it down forcefully, or you can run `vagrant suspend` to simplysuspend the virtual machine. In either case, to restart it again,simply run `vagrant up`.$ vagrant halt==> default: Attempting graceful shutdown of VM...air:nemo@~/hogera$ vagrant statusCurrent machine states:

default poweroff (virtualbox)

The VM is powered off. To restart the VM, simply run `vagrant up`$

Page 10: DevOps(2) : Vagrant  -  (MOSG)

ssh : ssh login to virtual machine

Try: ssh

$ vagrant sshLast login: Wed Nov 18 09:09:04 2015 from 10.0.2.2[vagrant@vagrant-centos64 ~]$

login by yourself$ vagrant ssh-configHost default HostName 127.0.0.1 User vagrant Port 2222 UserKnownHostsFile /dev/null StrictHostKeyChecking no PasswordAuthentication no IdentityFile /XXXXXXX/.vagrant/machines/default/virtualbox/private_key IdentitiesOnly yes LogLevel FATAL

Page 11: DevOps(2) : Vagrant  -  (MOSG)

Vagrantfile : configuration file of Vagrant described by ruby language

Vagrantfile

config.vm.box = "centos6.5"

# config.vm.network "forwarded_port", guest: 80, host: 8080 config.vm.network "private_network", ip: “192.168.33.10"# config.vm.network "public_network"

https://docs.vagrantup.com/v2/provisioning/index.html

Page 12: DevOps(2) : Vagrant  -  (MOSG)

Try: provision, reloadprovision:

apply provision against running virtual machine.$ vagrant provision :$

reload halt and up (= restart) with ‘--provision’ option, force provisioning.

$ vagrant reload :$ vagrant reload --provision :$

Page 13: DevOps(2) : Vagrant  -  (MOSG)

Trouble?Do same things inside the virtual machine (up):

/etc/init.d/vboxadd

[vagrant@vagrant-centos65 vagrant]$ sudo /etc/init.d/vboxadd setupRemoving existing VirtualBox non-DKMS kernel modules [ OK ]Building the VirtualBox Guest Additions kernel modulesThe headers for the current running kernel were not found. If the followingmodule compilation fails then this could be the reason.The missing package can be probably installed withyum install kernel-devel-2.6.32-431.3.1.el6.x86_64

Building the main Guest Additions module [FAILED](Look at /var/log/vboxadd-install.log to find out what went wrong)Doing non-kernel setup of the Guest Additions [ OK ][vagrant@vagrant-centos65 vagrant]$

You don’t know about ‘init.d’ ? If not, please study by myself.

Page 14: DevOps(2) : Vagrant  -  (MOSG)

NextAnsible

What’s Ansible? Basic usage

Target machine: Apache + PHP server with MySQL.