Vagrant之CentOS

原创
2018/02/25 20:25
阅读数 36

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

http://www.vagrantbox.es

https://vagrantcloud.com -> https://app.vagrantup.com/boxes/search

# 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%

展开阅读全文
打赏
0
1 收藏
分享
加载中
更多评论
打赏
0 评论
1 收藏
0
分享
返回顶部
顶部