Vagrant之CentOS
Vagrant官网
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
生成公钥
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 groupinstall "Compatibility libraries" "Base" "Development tools" -y
yum groupinstall "debugging Tools" "Dial-up Networking Support" -y
# 查看选包的情况
yum grouplist
打包box
vagrant package centos7 --output E:\work\box\centos7.4.1708v2.box