Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to customize personalized CentOS7 virtual machine template by Vagrant

2025-01-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces Vagrant how to customize personalized CentOS7 virtual machine template, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.

Environmental information

Operating system: macOS Mojave 10.14.6

Vagrant:2.2.5

VirtualBox:6.0.10

Create an instance and complete personalization

Create an instance of centos7, use it as a template, create a new directory, and execute the command vagrant init centos/7 in it

Then execute the command vagrant up to start the instance

Execute the command vagrant ssh to enter the virtual machine. The default password is vagrant, and the password of the root account is also vagrant.

After logging in, then do what you need, such as turning off the firewall, installing JDK, shutting down swap, etc.

In order to connect to the virtual machine remotely using the ssh tool, you need to modify the / etc/ssh/sshd_config file and set the values of and as follows:

PermitRootLogin yesPasswordAuthentication yes

The above settings have met my personal needs, you can do it according to your own requirements.

Make an example into a template

Exit the virtual machine

Execute the vagrant halt command in the directory where the Vagrantfile file is located to stop the current virtual machine

Execute the 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.boxzhaoqin@CN0014005932:~/vm/template$ lsVagrantfile package.box

Next, add the exported package.box file to the local box repository:

Vagrant box add-- name my-c7-template. / package.box

After the above command is executed successfully, you can see the box named my-c7-template in the local box list:

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 cards zhaoqin cards CN0014005932 VMS vagrant box listcentos/7 (virtualbox, 1905.1) customize-c7 (virtualbox, 0) my-c7-template (virtualbox, 0)

Note: when executing the vagrant box add command, the last parameter indicates the location of the box file. I added ". /" indicates the current directory, this ". /" must not be omitted, otherwise it is very likely to find another directory under the package.box file template has been completed, and then verify this example.

Verification

Create a new directory and execute the command vagrant init my-c7-template in it

Open the newly generated Vagrantfile file and add the following configuration to change the virtual machine network type to VPC and fix the IP address:

Config.vm.network "private_network", ip: "192.168.33.10"

Then execute the command vagrant up to start the instance

Since ssh has been set in the template to allow remote ssh login under the root account, try to log in to the ssh client this time. As shown below, you can log in successfully:

You can also check whether other settings are in effect.

Thank you for reading this article carefully. I hope the article "how to customize the personalized CentOS7 virtual machine template by Vagrant" shared by the editor will be helpful to everyone. At the same time, I also hope you can support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report