vagrant + virtualbox安装centos环境

Posted FLGB

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了vagrant + virtualbox安装centos环境相关的知识,希望对你有一定的参考价值。

1. 下载vagrant 并安装,安装完成后,输入vagrant回车查看是否安装成功

2. 下载virtualbox.box并安装,安装完成后。

3. 创建虚拟机文件夹,例如、F:/vmimg/first-docker-centos 在此目录下运行 vagrant init 生成Vagrantfile文件(可以自定义一些属性)

 

然后绑定centos的操作系统镜像virtualbox.box所在路径 

F:vmimgfirst-docker-centos>vagrant box add centos/7 E:BaiduNetdiskDownloadcentos7.0virtualbox.box
==> box: Box file was not detected as metadata. Adding it directly...
==> box: Adding box ‘centos/7‘ (v0) for provider:
box: Unpacking necessary files from: file:///E:/BaiduNetdiskDownload/centos7.0/virtualbox.box
box:
==> box: Successfully added box ‘centos/7‘ (v0) for ‘virtualbox‘!

输入vagrant list 查看当前box

F:vmimgfirst-docker-centos>vagrant box list
centos/7 (virtualbox, 0)

然后输入vagrant up命令创建并启动虚拟机

F:vmimgfirst-docker-centos>vagrant up

Bringing machine ‘default‘ up with ‘virtualbox‘ provider...
==> default: Importing base box ‘centos/7‘...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: lf-centos7
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
default: Adapter 1: nat
default: Adapter 2: bridged
==> default: Forwarding ports...
default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Running ‘pre-boot‘ VM customizations...
==> 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:
default: Vagrant insecure key detected. Vagrant will automatically replace
default: this with a newly generated keypair for better security.
default:
default: Inserting generated public key within guest...
default: Removing insecure key from the guest if it‘s present...
default: Key inserted! Disconnecting and reconnecting using new SSH 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/f/vmimg/first-docker-centos/ => /vagrant

F:vmimgfirst-docker-centos>

查看centos一些相关信息

F:vmimgfirst-docker-centos>vagrant ssh-config
Host default
HostName 127.0.0.1
User vagrant
Port 2222
UserKnownHostsFile /dev/null
StrictHostKeyChecking no
PasswordAuthentication no
IdentityFile F:/vmimg/first-docker-centos/.vagrant/machines/default/virtualbox/private_key
IdentitiesOnly yes
LogLevel FATAL

Xshell连接:

Ip:127.0.0.1

port:2222

username:vagrant

password:vagrant

文件 identityfile所指向的路径

使用root用户登录:

sudu -i

vi etc/ssh/sshd_config

修改PasswordAuthentication yes

passwd修改密码

systemctl restart sshd

root vagrant 登录

BOX打包分发:

01退出虚拟机  vagrant halt

02打包 vagrant package --output first-docker-centos.box

03得到first-docker-centos.box

04 将first-docker-centos.box添加到其他vagrant环境中

  vagrant box add first-docker-centos first-docker-centos.box

05 得到vagrantfile

  vagrant init  first-docker-centos

06 根据vagrantfile启动虚拟机

  vagrant up (网络可能需要从新配置)

以上是关于vagrant + virtualbox安装centos环境的主要内容,如果未能解决你的问题,请参考以下文章

vagrant + virtualbox安装centos环境

使用 Vagrant 在 VirtualBox 安装 Linux 虚拟机

markdown [Vagrant] Fedora #linux上的Vagrant和Virtualbox安装

virtualbox+vagrant快速安装Centos7

virtualbox+vagrant快速安装Centos7

使用Vagrant和VirtualBox安装CentOS