码迷,mamicode.com
首页 > 其他好文 > 详细

vagrant + virtualbox安装centos环境

时间:2020-01-02 22:51:45      阅读:187      评论:0      收藏:0      [点我收藏+]

标签:mct   removing   rda   root   star   ada   unp   run   Nging   

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

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

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

 

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

F:\vmimg\first-docker-centos>vagrant box add centos/7 E:\BaiduNetdiskDownload\centos7.0\virtualbox.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:\vmimg\first-docker-centos>vagrant box list
centos/7 (virtualbox, 0)

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

F:\vmimg\first-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:\vmimg\first-docker-centos>

查看centos一些相关信息

F:\vmimg\first-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环境

标签:mct   removing   rda   root   star   ada   unp   run   Nging   

原文地址:https://www.cnblogs.com/flgb/p/12142171.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!