This is the 12th day of my participation in the August More Text Challenge. For details, see:August is more challenging

One – line Linux installation demo:

Vagrant Box add Bento/Oracle-7.9 -- Provider Virtualbox && Sudo Vagrant init Bento/Oracle-7.9 && Sudo Vagrant upCopy the code

As a result of the above demonstration, Linux7.9 has been successfully installed and can be accessed.

preface

A recently discovered artifact, the Vagrant:

  • Vagrant is a Ruby based tool for creating and deploying virtualized development environments.
  • It uses Oracle’s open source VirtualBox virtualization system and uses Chef to create automated virtual environments.

What can it do? You can think of it as similar to Docker, which helps us quickly deploy development environments.

  • The Vagrant’s official website: www.vagrantup.com/
  • Making: Github.com/hashicorp/v…
  • Vagrant documents: www.vagrantup.com/docs

This article briefly describes how to use Vagrant to rapidly deploy a Linux host.

  • Vagrant installation
  • VirtualBox installation
  • Vagrant add box
  • Vagrant configuration Vagrantfile
  • Vagrant creates and runs a Linux host

First, environmental preparation

  • Vagrant and VirtualBox need to be installed first, which I did directly through macOS homebrew. It can also be installed by downloading the installation package:
  • Vagrant:www.vagrantup.com/downloads
  • VirtualBox:www.virtualbox.org/wiki/Downlo…

Of course, other virtual machines are also supported, such as VM, PD, etc.

1 Vagranta installation

cd /opt
brew install vagrant
Copy the code

Note: macOS can be installed directly through Homebrew, and Windows can be installed by downloading the installation package.

2 VirtualBox installation

brew install virtualbox
Copy the code

As shown above, the software has been successfully installed.

Install the Linux host

  • Vagrant can be prebuilt with a box image and can be a simple OS installation or an entire environment installed.
  • There is no need to manually download the Box image source; once it is referenced, Vagrant automatically downloads it and adds it to the list of boxes for local downloads.
  • There are a lot of Vagrant boxes on the Web, and this one isBento/oracle - 7.9The installation.

Box image source: app.vagrantup.com/boxes/searc…

Run the following command to switch to user root:

su - root
Copy the code

1. View the box image of the current host

vagrant box list
Copy the code

2. Initialize the Box image

Box profile may refer to: app.vagrantup.com/bento/boxes…

  • Add through the standard repository:
Vagrant Box add Bento/Oracle-7.9 -- Provider VirtualBoxCopy the code

  • Add using an image source:
  • Centos: cloud.centos.org/centos/
  • OracleLinux: yum.oracle.com/boxes/
vagrant box add --name ol76 https://yum.oracle.com/boxes/oraclelinux/ol76/ol76.box
Copy the code

  • View the box added:
vagrant box list
Copy the code

  • Create a Linux vm
mkdir /Volumes/DBA/Vagrantboxes
cd/ Volumes/DBA/Vagrantboxes vagrant init bento/oracle - 7.9Copy the code

  • Edit the Vagrantfile configuration file
mkdir -p /Volumes/DBA/Vagrantboxes/scripts/
echo 'echo "**** hello ****"' > /Volumes/DBA/Vagrantboxes/scripts/my_script.sh
Copy the code

  • We can change some VM attributes by editing Vagrantfile.
cd /Volumes/DBA/Vagrantboxes
mv Vagrantfile Vagrantfilebak
cat <<EOF > / Volumes/DBA/Vagrantboxes Vagrantfile # Set some variables. The var_public_ip = '192.168.56.100' Vagrant. Configure (" 2 ") Do | config | config. Vm. Box = "bento/oracle - 7.9" config. Vm. Provision: the shell, the path: "/opt/vagrant/scripts/my_script.sh" config.vm.network :forwarded_port, guest: 1521, host: 1521 config.vm.network "private_network", ip: "192.168.56.10" config. The vm. The provider "virtualbox" do | | vb vb. The memory = 2048 # memory size m. in vb. # Number of cpus = 1 VCPUs vB.name = "oracle -- 7.9" # VM name. End end EOF
Copy the code

  • Start the Linux on the vm
vagrant up
vagrant ssh
Copy the code

As above, the Linux host is already accessible.

3. Log in to the host using SSH

SSH 127.0.0.1 -p 2222Copy the code

4. Manage the Box image host

  • You can initialize, stop, start, restart, delete a VM, and list and remove images using the following commands.
Vagrant init bento/ Oracle -7.9 Vagrant halt vagrant up Vagrant status Vagrant reload vagrant destroy -f Vagrant box list The vagrant box remove bento/oracle - 7.6Copy the code
  • After modifying the Vagrantfile configuration, you can use the –provision option to reload the VM
vagrant reload --provision
Copy the code

At this point, the Vagrant installation Linux host has been demonstrated.

Write in the last

Personally, I find VirtualBox really hard to use, so I recommend using VM and PD.

  • PD Reference Manual: Github.com/Parallels/v…
  • VM Reference Manual: Github.com/hashicorp/v…

Vagrant is certainly not a simple tool for deploying Linux hosts. We will update the series to install Oracle databases using Vagrant. Stay tuned for 👏🏻.


That’s the end of this sharing

If you think the article is helpful to you, like, collect, follow, comment, one key four support, your support is the biggest motivation for my creation.