Vagrant之CentOS

2018-02-27 10:53:35来源:oschina作者:yysue人点击

分享
Vagrant之CentOS

Vagrant官网


https://www.vagrantup.com


https://app.vagrantup.com/boxes/search


https://app.vagrantup.com/centos/boxes/7


前提安装Vagrant,Virtualbox


https://my.oschina.net/u/159293/blog/1623730


一、box

下载box


https://vagrantcloud.com/centos/boxes/7/versions/1801.02/providers/virtualbox.box


rename virtualbox.box centos7.4.1708.box

添加box


vagrant box add centos7.4.1708 E:/work/box/centos7.4.1708.box

生成公钥


http://git.mydoc.io/?t=154712


ssh-keygen -t rsa -C "xxxxx@xxxxx.com"
# 说明
生成公钥存在于C:/Users/your name/.ssh

配置文件 :Vagrantfile


# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "centos7.4.1708"
config.vm.define "centos7" do |config|
config.vm.provider "virtualbox" do |v|
v.customize ["modifyvm", :id, "--name", "centos7", "--memory", "1024"]
end
config.vm.hostname = "centos7"
config.vm.network :public_network, ip: "192.168.5.201", bridge: "eth1"
#config.vm.provision "file", source: "C:/Users/admin/.ssh/id_rsa.pub", destination: "~/.ssh/authorized_keys"
end
end

如果不下载box,在上述配置文件中配置box


https://app.vagrantup.com/centos/boxes/7


config.vm.box = "centos/7"
config.vm.box_version = "1801.02"
二、run

启动


vagrant up centos7

运行Provisioners


https://www.vagrantup.com/docs/provisioning/basic_usage.html


vagrant provision centos7
# 说明
只有运行Provisioners,配置文件中的config.vm.provision才会生效
上述配置是把本地的公钥上传到服务器

登录


vagrant ssh centos7
# 使用ssh软件登录,如Putty,Xshell5

更新YUM


https://my.oschina.net/u/159293/blog/1616650


安装软件包


# 安装软件包
yum groupinstall "Compatibility libraries" "Base" "Development tools" -y
yum groupinstall "debugging Tools" "Dial-up Networking Support" -y
# 查看选包的情况
yum grouplist

安装linux kernel headers and the basic developer tools


yum install kernel-devel kernel-devel-$(uname -r) -y

安装VirtualBox Guest Additions


1)先关闭CentOS系统


vagrant halt centos7

2)追加光驱



3)启动CentOS系统


vagrant up centos7

4)挂载光盘



打开VBox管理器,点击菜单的“设备” => “安装增强功能”


5)安装VirtualBox Guest Additions


mount /dev/cdrom /mnt
cd /mnt
sh /media/cdrom/VBoxLinuxAdditions.run

打包box


vagrant package centos7 --output E:/work/box/centos7.4.1708v2.box
三、问题

密钥在哪


echo %VAGRANT_HOME%

最新文章

123

最新摄影

闪念基因

微信扫一扫

第七城市微信公众平台