About Virtual Machine Templates
Vagrant want to build hadoop cluster, complete the following preparations:
- Three virtual machine instances operating system is the server version of CentOS7;
- Each instance of the same application to be installed, turn off the firewall, turn off swap and so on;
it is today to be a template, use this template to create a good virtual machine have completed the above operations;
Installation and basic operations on vagrant, see "Mac under vagrant from installation to experience" ;
Environmental Information
- Operating System: macOS Mojave 10.14.6
- Vagrant:2.2.5
- VirtualBox:6.0.10
Create an instance of complete and personalized settings
- Create an instance of a centos7, in order to do the template instance, the new directory, execute commands inside Vagrant the init CentOS / 7 ;
- And then execute the command vagrant up start instance;
- Run vagrant ssh into the virtual machine, the default password is Vagrant , another root account password is also Vagrant ;
- After logging in, and in accordance with their own needs to operate it, such as turning off the firewall, install JDK, close the swap, etc.;
- To use ssh tools to remotely connect to a virtual machine, modify the / etc / ssh / sshd_config file, and the values are set as follows:
PermitRootLogin yes
PasswordAuthentication yes
The above has been set to meet my personal needs, and you can do according to their own requirements;
The examples made templates
- Exit the virtual machine;
- In Vagrantfile file directory execute vagrant halt command to stop the current virtual machine;
- Execution vagrant package command to export the current virtual machine as a file named package.box :
zhaoqin@CN0014005932:~/vm/template$ vagrant package
==> default: Attempting graceful shutdown of VM...
==> default: Clearing any previously set forwarded ports...
==> default: Exporting VM...
==> default: Compressing package to: /Users/zhaoqin/vm/template/package.box
zhaoqin@CN0014005932:~/vm/template$ ls
Vagrantfile package.box
- Next to this the exported file to the local box package.box Warehouse:
vagrant box add --name my-c7-template ./package.box
After executing the above command is successful, the name can be seen in the local box list My-c7-Template box are:
zhaoqin@CN0014005932:~/vm/template$ vagrant box add --name my-c7-template ./package.box
==> box: Box file was not detected as metadata. Adding it directly...
==> box: Adding box 'my-c7-template' (v0) for provider:
box: Unpacking necessary files from: file:///Users/zhaoqin/vm/template/package.box
==> box: Successfully added box 'my-c7-template' (v0) for 'virtualbox'!
zhaoqin@CN0014005932:~/vm/template$ vagrant box list
centos/7 (virtualbox, 1905.1)
customize-c7 (virtualbox, 0)
my-c7-template (virtualbox, 0)
Note: Performing vagrant box add command when the last parameter specifies the file location box, here I added a "./" indicates that the current directory, the "./" must not be dispensed with, or is likely to find a package.box files in other directories
templates to create has been completed, the next test this example;
verification
- Create a directory, execute commands inside Vagrant the init-My-c7 Template ;
- Open a new generation of Vagrantfile file, add the following configuration, the role of the virtual machine network type to a private network and a fixed IP address:
config.vm.network "private_network", ip: "192.168.33.10"
- And then execute the command vagrant up start instance;
- Since the template has been set up ssh, allow remote ssh login to the root account, so this ssh client logon try, as shown below, can successfully log on successfully:
- You can also check whether the other settings already in force;
These are the production process personalized virtual machine template With this feature you can create a virtual machine instance and efficient, I hope this can give you some reference.