Vagrant personalized custom template CentOS7

About Virtual Machine Templates

Vagrant want to build hadoop cluster, complete the following preparations:

  1. Three virtual machine instances operating system is the server version of CentOS7;
  2. 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

  1. Operating System: macOS Mojave 10.14.6
  2. Vagrant:2.2.5
  3. VirtualBox:6.0.10

Create an instance of complete and personalized settings

  1. Create an instance of a centos7, in order to do the template instance, the new directory, execute commands inside Vagrant the init CentOS / 7 ;
  2. And then execute the command vagrant up start instance;
  3. Run vagrant ssh into the virtual machine, the default password is Vagrant , another root account password is also Vagrant ;
  4. 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.;
  5. 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

  1. Exit the virtual machine;
  2. In Vagrantfile file directory execute vagrant halt command to stop the current virtual machine;
  3. 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
  1. 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

  1. Create a directory, execute commands inside Vagrant the init-My-c7 Template ;
  2. 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"
  1. And then execute the command vagrant up start instance;
  2. 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:
    Here Insert Picture Description
  3. 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.

Published 328 original articles · won praise 946 · Views 1.17 million +

Guess you like

Origin blog.csdn.net/boling_cavalry/article/details/102240871