Vagrant is a wrapper around virtualization software such as virtualbox, VMware or KVM. In development environment, you can quickly build virtual machines by configuring CPUs, memory, network, and storage.
Git provides a number of UNIX command line tools along with access to Git.
Download and install git from http://git-scm.com/download/win
Download and install Virtualbox from http://download.virtualbox.org/virtualbox/4.3.26/VirtualBox-4.3.26-98988-Win.exe
Download and install vagrant from https://dl.bintray.com/mitchellh/vagrant/vagrant_1.7.2.msi
Download CentOS 7 Minimal ISO at http://isoredirect.centos.org/centos/7/isos/x86_64/CentOS-7-x86_64-Minimal-1503-01.iso
Create Virtual Machine
In Oracle VM VirtualBox Manager, click New
Name: centos7-vagrant
Type: Linux
Version: Red Hat (64 bit)
Memory size: 2048 MB
Hard drive: Create a virtual hard drive now
Hard drive file type: VMDK (Virtual Machine Disk)
Storage on physical hard drive: Dynamically allocated
File location and size: 30 GB
In Oracle VM VirtualBox Manager, select centos7-vagrant and click Settings
General -> Advanced --> Shared Clipboard: Bidirectional
Storage --> Select Controller: IDE and Click Add CD/DVD device icon --> Choose Disk --> Select CentOS-7-x86_64-Minimal-1503-01.iso
Network --> Adapter 1 --> Check Enable Network Adapter --> Attached to: Bridged Adapter
Start the VM
Select Install CentOS 7
English (United States) and Click Continue
To switch from VM to laptop and VM, click Right Ctrl
Click INSTALLATION DESTINATION, select ATA VBOX HARDDISK 30 GiB, click Done
Click Begin Installation
Click ROOT PASSWORD, enter Root Password as vagrant, click Done
Click Reboot
In Settings window, highlight CentOS-7-x86_64-Minimal-1503-01.iso and click Remove floppy icon at bottom.
Create user vagrant and set password
Login as root
# useradd -c "Vagrant Admin" -G wheel -s /bin/bash vagrant
Set password as vagrant
# passwd vagrant
Modify Base Repository
# vi /etc/yum.repos.d/CentOS-Base.repo
Replace $releasever as 7 and $basearch as x86_64
[centosplus]
enabled=1
Enable the network interface to activate at boot time and get dynamic IP
# vi /etc/sysconfig/network-scripts/ifcfg-enp0s3
TYPE=Ethernet
BOOTPROTO=dhcp
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
NAME=enp0s3
DEVICE=enp0s3
ONBOOT=yes
# ifup enp0s3
Disable SELINUX
# vi /etc/selinux/config
SELINUX=disabled
Update the sudoes file
# visudo
# Defaults !visiblepw
Defaults:vagrant !requiretty
Defaults env_keep = "SSH_AUTH_SOCK"
Comment the below line
# %wheel ALL=(ALL) ALL
Uncomment the below line
%wheel ALL=(ALL) NOPASSWD: ALL
Update the OpenSSH Configuration
# vi /etc/ssh/sshd_config
Port 22
PubkeyAuthentication yes
PermitEmptyPasswords no
PasswordAuthentication yes
Update packages and start ntpd
# yum -y udpate
# yum -y install ntp wget net-tools
# systemctl start ntpd.service
# systemctl enable ntpd.service
# systemctl is-enabled ntpd.service
# shutdown -r now
Add vagrant insecure key
Login as vagrant in VM or SSH into VM from Git Bash.
$ mkdir -p /home/vagrant/.ssh
$ chmod 0700 /home/vagrant/.ssh
$ wget --no-check-certificate https://raw.github.com/mitchellh/vagrant/master/keys/vagrant.pub -O /home/vagrant/.ssh/authorized_keys
$ chmod 0600 /home/vagrant/.ssh/authorized_keys
$ chown -R vagrant:vagrant /home/vagrant/.ssh
$ exit
Installing Guest Tools
Login as root
Devices --> Insert Guest Addtions CD image...
# mount /dev/cdrom /mnt
# yum -y bzip2 gcc make kernel-devel
# yum groupinstall "X Window System"
# yum clean all
# /mnt/VBoxLinuxAdditions.run
# umount /mnt
# shutdown -h now
In Settings window, highlight VBoxGuestAdditions.iso and click Remove floppy icon at bottom.
Export and Compress package
Open Git Bash
$ mkdir vagrant
$ cd vagrant
$ vagrant package --output centos-7.1.box --base centos7-vagrant
This base box is uploaded at https://atlas.hashicorp.com/anandbitra/boxes/centos-7.1/versions/1.0.0/providers/virtualbox.box
Add vagrant base box
Open Git Bash
$ vagrant box add anandbitra/centos-7.1 centos-7.1.box
List vagrant boxes
Open Git Bash
$ vagrant box list
Remove vagrant base box
Open Git Bash
$ vagrant box remove anandbitra/centos-7.1
No comments:
Post a Comment