preface
I need to use Docker, but my machine configuration is amazing, I can’t install Docker directly, so I have no choice but to use Vagrant+VirtualBox to save the country.
Install VirtualBox
Download the VirtualBox installation package
VirtualBox download page address (not guaranteed for long term) :
https://www.virtualbox.org/wiki/Downloads
Copy the code
My current version is Windows, the specific link is as follows (not guaranteed to be valid for a long time) :
https://download.virtualbox.org/virtualbox/6.1.30/VirtualBox-6.1.30-148432-Win.exe
Copy the code
Note the vagrant and VirtualBox versions. There may be compatibility issues between the different versions, so you’d better stick with mine, because I’ve already been there. Virtualbox: version 6.1.30; Vagrant: 2.2.19
Install the vagrant
Download the Vagrant installation package
Vagrant download page address:
https://www.vagrantup.com/downloads
Copy the code
You can download the 64-bit version directly. The version I downloaded is vagrant_2.19, and the specific link is as follows (it is not guaranteed to be valid for a long time) :
https://releases.hashicorp.com/vagrant/2.2.19/vagrant_2.2.19_x86_64.msi
Copy the code
Install the vagrant
Nothing special direct next next step, of course, can choose their own installation address, this depends on their own wishes.
Download a VM image
The loading speed of this virtual machine image is really impressive! So we need to image it and add it directly to Vagrant’s box with the command. The address of the download page is as follows (not guaranteed to be valid for a long time) :
https://app.vagrantup.com/centos/boxes/7
Copy the code
I downloaded the centos7 image, the link is as follows (not guaranteed to be valid for a long time) :
Don’t ask why you still use centos7, ask because you are used to centos.
https://cloud.centos.org/centos/7/vagrant/x86_64/images/CentOS-7-x86_64-Vagrant-2004_01.VirtualBox.box
Copy the code
Customize the project address
Creating a virtual machine with Vagrant requires an initial import of image files, known as boxes, which are stored by default in the.vagrant.d directory in the user directory, or C:\Users\ username.vagrant.d for Windows. If you may need a lot of images later, or if you are short of space on drive C, you can set this directory by setting the environment variable VAGRANT_HOME.
The window system
setx VAGRANT_HOME "D:\ProgramFiles\vagrant\boxData"
setx VAGRANT_HOME "D:\ProgramFiles\vagrant\boxData" /M
Copy the code
Linux system
export VAGRANT_HOME="/path/to/vagrant_home"
Copy the code
After running the preceding command in Windows, open CMD again for the configuration to take effect.
Adding a Local Mirror
I placed the image in the D: ProgramFiles\ Vagrant \data directory and added the image on CMD by executing the following command:
vagrant box add centos/7 ./CentOS-7-x86_64-Vagrant-2004_01.VirtualBox.box
Copy the code
If no permission is displayed, start CMD with administrator permission
The image is added successfully if the following message is displayed:
==> box: Successfully added box 'centos/7' (v0) for 'virtualbox'!
Copy the code
A new virtual machine
Again, under D: ProgramFiles\ Vagrant \data, execute the following command:
vagrant init centos/7
Copy the code
If the following text prompt appears, the initialization is successful:
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.
Copy the code
Starting a VM
Start VirtualBox before executing the following command.
vagrant up
Copy the code
The VM is successfully started if the following message is displayed:
D:\ProgramFiles\vagrant\data>vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Clearing any previously set forwarded ports...
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
default: Adapter 1: nat
default: Adapter 2: hostonly
==> default: Forwarding ports...
default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
default: SSH address: 127.0.0.1:2222
default: SSH username: vagrant
default: SSH auth method: private key
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
default: No guest additions were detected on the base box for this VM! Guest
default: additions are required for forwarded ports, shared folders, host only
default: networking, and more. If SSH fails on this machine, please install
default: the guest additions and repackage the box to continue.
default:
default: This is not an error message; everything may continue to work properly,
default: in which case you may ignore this message.
==> default: Configuring and enabling network interfaces...
==> default: Rsyncing folder: /cygdrive/d/ProgramFiles/vagrant/data/ => /vagrant
==> default: Machine already provisioned. Run `vagrant provision` or use the `--provision`
==> default: flag to force provisioning. Provisioners marked to run always will still run.
Copy the code
The first is the aforementioned compatibility issue between vagrant and Virtualbox. The second is the problem of Chinese user names. Vagrant. D. Vagrant is written in Ruby and has some coding problems. It happens that my user name is also Chinese.
Next you can see a started virtual machine in VirtualBox.
Attach my Vagrantfile profile
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
# The most common configuration options are documented and commented below.
# For a complete reference, please see the online documentation at
# https://docs.vagrantup.com.
# Every Vagrant development environment requires a box. You can search for
# boxes at https://vagrantcloud.com/search.Config.vm. box = "centos/7" config.vm.network "private_network", IP: "192.168.33.10" endCopy the code
Logging In to a VM
Vagrant has two accounts by default, as follows:
Account: Vagrant Password: Vagrant Account: root Password: VagrantCopy the code
Vagrant, by default, logs in with a key and executes directlyvagrant ssh
Command to log in, but the login isvagrant
However, to install some software in the VM, such as docker, you need to use the root account permission, so how to solve the problem?
Simply use the su command and enter the password vagrant.
You can use Vagrant ssh-config to see the specific login configuration:
D:\ProgramFiles\vagrant\data> Vagrant ssh-config Host default HostName 127.0.0.1 User Vagrant Port 2222 UserKnownHostsFile /dev/null StrictHostKeyChecking no PasswordAuthentication no IdentityFile D:/ProgramFiles/vagrant/data/.vagrant/machines/default/virtualbox/private_key IdentitiesOnly yes LogLevel FATALCopy the code
It is mentioned above that you can log in to the VIRTUAL machine using Vagrant SSH, but it is still not convenient in some places, so you still need to use professional terminal software to log in to the virtual machine. Here I use MobaXterm. I used to use Xshell + XFTP before, but I couldn’t pay for prostitution later, so I changed this MobaXterm. It feels ok to use.
I tried to use the IP address 192.168.33.10 in the previous Vagrantfile for this host, but could not connect.
Install jdk8
Next, log in to the virtual machine and install the JDK8. The following steps are performed on a virtual machine.
Download the JDK8 installation package
Oracle Java8 download page address (not guaranteed to be valid for a long time) :
https://www.oracle.com/java/technologies/downloads/#java8
Copy the code
I choose x64 Compressed Archive version, the specific download address is as follows (this link should also be invalid at any time) :
https://download.oracle.com/otn/java/jdk/8u311-b11/4d5417147a92418ea8b615e228bb6935/jdk-8u311-linux-x64.tar.gz?AuthParam =1638083601_4ec49a992915eff50f4be9d904997568Copy the code
You can download it from Windows and upload it to Linux, but I recommend downloading it directly from Linux. After all, it is a command matter:
cd /usr/local/src wget https://download.oracle.com/otn/java/jdk/8u311-b11/4d5417147a92418ea8b615e228bb6935/jdk-8u311-linux-x64.tar.gz?AuthParam =1638083601_4ec49a992915eff50f4be9d904997568Copy the code
The download now requires a login account, which is provided here
Account: [email protected] Password: Azerty1!
The account will be invalid at any time, if the failure of their baidu or directly registered an account!
Install jdk8
-
Creating an installation directory
mkdir /usr/local/java Copy the code
-
Decompress the installation package to the installation directory
tar -zxvf /usr/local/src/jdk-8u311-linux-x64.tar.gz\? AuthParam\=1638083601_4ec49a992915eff50f4be9d904997568 -C /usr/local/java/Copy the code
-
Set the environment variable to add Java to it
Open the file
vim /etc/profile Copy the code
Add at the end of the file
Export JAVA_HOME=/usr/local/java/jdk1.8.0_311 export JRE_HOME=${JAVA_HOME}/jre export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib export PATH=${JAVA_HOME}/bin:$PATHCopy the code
Run the source command to reload the profile file
source /etc/profile Copy the code
Add soft connection (this step is not good image is also ok)
Ln -s/usr/local/Java/jdk1.8.0 _311 / bin/Java/usr/bin/JavaCopy the code
-
Check the effect:
java -version
Copy the code
The results of the following text representsjava
The installation is complete.
Install the docker
Remember to switch to root before installing Docker.
-
Uninstall the docker system by executing the following command.
yum remove docker \ docker-client \ docker-client-latest \ docker-common \ docker-latest \ docker-latest-logrotate \ docker-logrotate \ docker-engine Copy the code
-
To start installing docker, run the following commands:
#Step 1: Install the necessary system tools sudo yum install -y yum-utils device-mapper-persistent-data lvm2 #Step 2: Add software source information sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo #Step 3: Update and install docker-CE sudo yum makecache fast sudo yum -y install docker-ce #Step 4: Enable the Docker service sudo service docker start #Powered up systemctl enable docker Copy the code
For resources, see my previous article installing Docker with yum on CentOS7
Install the docker composer
This is all done in Docker and the container choreography should at least be done in Docker composer. The installation commands are as follows:
- Run the following command to download the current stable version of Docker Compose:
Sudo curl - L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname - s) - $(uname -m)" - o /usr/local/bin/docker-composeCopy the code
The examples used here are from the official documentation and version 1.29.2 is installed. Link: https://docs.docker.com/compose/install/
-
Apply executable permissions to binaries:
chmod +x /usr/local/bin/docker-compose Copy the code
-
Test installation result:
docker-compose --version Copy the code
Docker-compose installation is complete if the following prompt is displayed.
[root@localhost vagrant]# docker-compose -- docker-compose version 1.29.2, build 5becea4c [root@localhost vagrant]#Copy the code
conclusion
This completes the Configuration of the Vagrant+VirtualBox environment, as well as the Java environment and Docker in the virtual machine.