vagrant springcloud java mirroring: production details (with download address)


"SpringCloud Nginx High Concurrency Core Programming" Environment Setup-Series

Component link address
[Required] Virtual machine Linux development environment preparation
Linux openresty installation Linux openresty installation
[Required] Linux Redis installation (with video) Linux Redis installation (with video)
[Required] Linux Zookeeper installation (with video) Linux Zookeeper installation, with video
Windows Redis installation (with video) Windows Redis installation (with video)
RabbitMQ offline installation (with video) RabbitMQ offline installation (with video)
ElasticSearch installation, with video ElasticSearch installation, with video
Nacos installation (with video) Nacos installation (with video)
[Required] Eureka Getting started with Eureka with video
[Required] Getting started with springcloud Config, with video Getting started with springcloud Config with video
[Required] SpringCloud scaffolding packaging and startup SpringCloud scaffolding packaging and startup
Linux self-start, suspended animation, self-start, timed self-start Linux self-starting suspended animation

What is vagrant

We must first sharpen our tools. The development environment and development tools are the swords of our developers, so we need a fast and easy-to-use sword

**Vagrant:** is a more popular virtual machine management software. Using Vagrant allows us to download the image of the virtual machine directly from the cloud with commands, and then create and manage it.

When I first started development, I configured the development environment on my own computer. As we came into contact with more and more things, slowly, there were various environments on the computer, such as php, java, python, nodejs. Wait, it's very troublesome, and the computer is often reinstalled for some reason, ORZ, so the environment has to be reset. Therefore, it is very important to create a mobile environment that belongs to you.

Vagrant is a tool for building a virtual development environment. It supports window, linux, mac, and there is always one suitable for you. And vagrant can package the configured environment into a box and share it with others for direct use, which is very convenient

Vagrant is a virtual environment deployment tool that is very suitable for developers. It integrates mainstream virtualizer management tools and supports vmvare and virtualbox.

The essence of vagrant is in a Vagrantfile, which is functionally the same as docker's Dockerfile. We only need to write the steps that need to be installed and deployed in the Vagrantfile to achieve easy deployment. Vagrant also supports making the current system into a mirror named with a .box suffix, similar to docker's image, which can easily implement environment transplantation.

Therefore, using vagrant can define complex virtual frameworks on systems running multiple VMs. A Linux development environment can be packaged through Vagrant and distributed to team members. Members can develop programs on their favorite desktop systems (Mac/Windows/Linux), but the code can run in a packaged environment, which is very domineering. Isn't it cool?

Ready to work:

Download and install VirtualBox, download and install Vagrant, download more boxes that can be used directly on different systems or even the configured environment. Although you can use the URL directly in Vagrant, Vagrant will automatically download and install it, but considering the network situation, it is recommended to start by yourself The download is good.

You can also download more different systems or even boxes that can be used directly with the configured environment at http://www.vagrantbox.es/. Although the URL can be used directly in Vagrant, Vagrant will automatically download and install it, but consider the network In case, it is recommended to download it by yourself.

  • Virtualbox official website address

    Virtual machines still have to rely on VirtualBox to build, free and compact. Download address https://www.virtualbox.org/

  • vagrant2.2.7 official website address

    https://www.vagrantup.com/downloads.html

  • Download the box you need to use:

此外,还得下载官方封装好的基础镜像:
Ubuntu precise 32 VirtualBox http://files.vagrantup.com/precise32.box
Ubuntu precise 64 VirtualBox http://files.vagrantup.com/precise64.box

如果你要其他系统的镜像,可以来这里下载:http://www.vagrantbox.es/

网友提供的centos 7.2网盘地址:https://pan.baidu.com/s/15S2OZq37FcL9RWWSTWntIw   提取码:3xb0
  • GitBash
    GitBash is a Unix shell under windows, which is convenient for inputting commands to Vagrant. (General java development will use git for code synchronization, so this tool is already installed by default)
    https://git-scm.com/download/win

space:

15G hard disk space

What is: springcloud.box mirror

Crazy Maker Circle has prepared a springcloud.box image for everyone, pre-installed with necessary components such as java, redis, zookeeper, kafka, Eureka, springcloud config and so on. For the network disk address, please see [ Blog Park General Entrance ]

Insert picture description here

Use vagrant to make a Java development environment

The first step is to create a new directory

E:\virtual\work

Select the newly created folder, right click —> Git Bash Here, open the current directory in Git Bash

As you can see in Git Bash, the current linux format directory, the execution instructions are as follows:

$ pwd
/e/virtual/work

The second step is to add the mirror to Vagrant

vagrant box add  centos  /e/virtual/vagrant-centos-7.2.box
centos 表示指定名称,如果使用base,之后可以直接使用 

$ vagrant box add centos /e/virtual/vagrant-centos-7.2.box
==> box: Box file was not detected as metadata. Adding it directly…
==> box: Adding box ‘centos’ (v0) for provider:
box: Unpacking necessary files from: file:///E:/virtual/vagrant-centos-7.2.box
box:
==> box: Successfully added box ‘centos’ (v0) for ‘virtualbox’!

$

vagrant-centos-7.2.box is the file name of the box, here is the path to save the box locally. It can also be a URL where the box can be downloaded. If it is a URL, Vagrant will automatically start the download.

The third step is to initialize the virtual machine

After setting up the box, run in the current working directory

$ vagrant init centos

When centos is initialized, you need to specify the name of the box. The results of the implementation are as follows:

$ vagrant init centos
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.

You can also use the existing directory, switch to the development directory, and initialize the current directory with the centos mirror. After the image is initialized, a virtual machine configuration file Vagrantfile is generated in the current directory. Through this configuration file, port mapping, virtual machine IP, directory mapping, etc. can be configured. Open Vagrantfile through a text editor to perform some further common configurations. If you configure the login user name and password, the ip of the virtual machine is as follows:

config.ssh.username = "root"
config.ssh.password = "vagrant"

config.vm.network :private_network, ip: "192.168.68.128"

Restart the virtual machine, so that we can use 192.168.233.128 to access this machine, you can change the IP to another address, as long as there is no conflict.

The specific configuration will be introduced later.

The fourth step is to start the virtual machine

Use the following command:

$ vagrant up   # 启动虚拟机

You will see the terminal showing the startup process. After the startup is complete, we can log in to the virtual machine with SSH. The remaining steps are to configure the various environments and parameters you want to run in the virtual machine.

$ vagrant ssh # SSH login
$ cd /vagrant # Switch to the development directory, which is E:\virtual\work on the host

Note for Windows users: Windows terminals do not support ssh, so you need to install a third-party SSH client, such as Putty, Cygwin, Git Bash, etc.

About the initial account and password:

Account password
vagrant vagrant
root vagrant

You can use other terminal tools to access the virtual machine through root

Package and distribute

When you have configured the development environment, exit and shut down the virtual machine. Package the development environment in the terminal:

$ vagrant package

After the complete package in the current directory will generate a package.boxfile, the file will be passed to other users, add other users as long as this box and use it to initialize its development directory will be able to get an identical development environment.

vagrant package -hUsage: vagrant package [options] [name]

Options:
-base NAME The name of the virtual machine in the virtualbox program, not the name of the box or the name of the virtual machine in the Vagrantfile. The default is to package the virtual machine in the current directory.
--Output NAME The name of the box to be packaged into. The .box suffix will not be automatically added, and it must be manually added. The default value is package.box

​ --include FILE... The name of the file included when packaging, you can understand
the .box file as a compressed package​ --vagrantfile FILE The Vagrantfile file included when packaging, the principle is similar to the above
​ -h, --help Print this help
Example: vagrant package –base virtualbox_vm_name –output newbox_name.box

Virtual machine configuration through Vagrantfile:

Network Configuration:

Vagrant's network has three modes

1. The more commonly used port mapping is to map the port in the virtual machine to the port corresponding to the host and use it directly, and configure it in the Vagrantfile:

config.vm.network :forwarded_port, guest: 80, host: 8080

guest: 80 means port 80 in the virtual machine, host: 8080 means port 8080 mapped to the host machine.

2. If you need to access the virtual machine freely, but others do not need to access the virtual machine, you can use private_network, and set the IP for the virtual machine, and configure it in the Vagrantfile:

 config.vm.network :private_network, ip: "192.168.1.104"

192.168.1.104 represents the IP of the virtual machine. If multiple virtual machines need to access each other, they can be set in the same network segment.

3. If you need to use the virtual machine as a computer in the current LAN and use the LAN for DHCP, then configure it in the Vagrantfile:

config.vm.network :public_network

Directory mapping:

Since it is a development environment, the development work must be done locally instead of going to the virtual machine to complete. The virtual machine runs the service in the background, otherwise the cart is upside down, so you need to use the directory here. The mapping function maps the local directory to the corresponding directory of the virtual machine.

By default, the current working directory will be mapped to the /vagrant directory of the virtual machine. The files in the current directory can be accessed directly under /vagrant. Of course, you can also create a soft connection through ln, such as

ln -fs /vagrant/wwwroot /var/www

To perform directory mapping, of course, from the perspective of automated configuration, you do not need to enter the system without entering the system, so you can also perform directory mapping operations in Vagrant:

config.vm.synced_folder "wwwroot/", "/var/www"

The preceding parameter "wwwroot/" means the local path, here the relative path to the working directory is used, here you can also use the absolute path, for example: "d:/www/"

The following parameter "/var/www" represents the corresponding mapped directory in the virtual machine.

After starting Vagrant, the virtual machine has been configured for the installation environment. If you don’t want to write it in the Vagrant startup shell and reinstall the configuration every time, you can package the currently configured virtual machine into a box.

Note: If private_network is used in the network mode, you need to clear the private_network setting before packaging to avoid unnecessary errors:

sudo rm -f /etc/udev/rule.d/70-persistent-net.rules

After the production is completed, directly take the box file to another computer and configure it for use.

更多信息可以参考官方文档:http://docs.vagrantup.com/v2/

Attachment: the vagrantfile file on my machine

Vagrant.configure(2) do |config|
	config.ssh.username = "root"
	config.ssh.password = "vagrant"
    config.vm.box = "centos"
    config.vm.network "private_network", ip: "192.168.68.128"

   config.vm.synced_folder "/home/wangkongming/files/works/code/kfz-pm", "/data/webroot/pmv2"
   
end

Vagrant basic commands

Official website document: https://docs.vagrantup.com/v2/getting-started/index.html

vagrant init initialize vagrantfile

vagrant add box Add box, automatically generate vagrantfile for you

vagrant halt shuts down the virtual machine

vagrant destroy destroy the virtual machine

vagrant ssh to connect to the virtual machine

vagrant reload reload the vagarntfile file

vagrant suspend temporarily suspends the virtual machine

vagrant status View the running status of the virtual machine

vagrant package package box file

Back to ◀ Crazy Maker Circle

Crazy Maker Circle-Java high-concurrency research community, open the door to big factories for everyone

Guess you like

Origin blog.csdn.net/crazymakercircle/article/details/111770275