Vagrant文檔地址 https://www.vagrantup.com/docs
1、下載安裝VirtualBox贿条、Vagrant
- 下載并安裝VirtualBox https://www.virtualbox.org/wiki/Downloads
- 下載并安裝Vagrant https://www.vagrantup.com/downloads.html
2雹仿、執(zhí)行 vagrant version 命令查看Vagrant是否安裝成功
vagrant version
3、初始化項(xiàng)目目錄整以,創(chuàng)建Vagrantfile文件
- 新建一個(gè)文件夾胧辽,在文件夾下再創(chuàng)建兩個(gè)文件夾vagrant和share_data(與Vagrantfile中的本地共享文件夾名稱一致),在vagrant文件夾中創(chuàng)建Vagrantfile文件(注意沒(méi)有后綴)
- Vagrantfile中安裝了docker公黑、git邑商、JavaJDK摄咆、maven等,根據(jù)自己的需要選擇
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "centos/7"
config.vm.box_url = "https://mirrors.ustc.edu.cn/centos-cloud/centos/7/vagrant/x86_64/images/CentOS-7.box"
config.vm.network "forwarded_port", guest: 80, host: 80
config.vm.network "forwarded_port", guest: 8080, host: 8080
config.vm.network "forwarded_port", guest: 18080, host: 18080
config.vm.network "forwarded_port", guest: 18081, host: 18081
config.vm.network "forwarded_port", guest: 18082, host: 18082
config.vm.network "forwarded_port", guest: 18083, host: 18083
config.vm.network "forwarded_port", guest: 18084, host: 18084
config.vm.network "forwarded_port", guest: 18085, host: 18085
config.vm.network "forwarded_port", guest: 18086, host: 18086
config.vm.network "forwarded_port", guest: 18087, host: 18087
config.vm.network "forwarded_port", guest: 18088, host: 18088
config.vm.network "forwarded_port", guest: 18089, host: 18089
config.vm.network "forwarded_port", guest: 28081, host: 28081
config.vm.network "forwarded_port", guest: 28082, host: 28082
config.vm.network "forwarded_port", guest: 28083, host: 28083
config.vm.network "private_network", ip: "192.168.33.224"
config.vm.synced_folder '.', '/vagrant', disabled: true
config.vm.synced_folder "E:/git", "/git-resp", type: "nfs"
config.vm.provider "virtualbox" do |v|
v.memory = 4096
v.cpus = 2
v.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
v.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
end
config.vm.provision "shell", inline: <<-SHELL
sudo yum -y update
sudo timedatectl set-timezone "Asia/Shanghai"
sudo yum -y install vim
sudo yum -y install dos2unix
sudo yum -y install unzip zip
sudo yum -y install git
sudo yum -y install java-1.8.0-openjdk.x86_64
sudo yum -y install maven
sudo curl -fsSL get.docker.com -o get-docker.sh
sudo sh get-docker.sh --mirror Aliyun
sudo systemctl enable docker
sudo mkdir -p /etc/docker
sudo systemctl daemon-reload
sudo systemctl start docker
sudo docker volume create portainer_data
sudo docker run -d -p 18000:8000 -p 19000:9000 --name=portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer
sudo curl -L https://download.fastgit.org/docker/compose/releases/download/1.27.4/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
SHELL
end
4人断、安裝WinNFSd插件吭从,在Windows上管理并添加對(duì)NFS的支持。
- vagrant-winnfsd: https://github.com/winnfsd/vagrant-winnfsd
vagrant plugin install vagrant-winnfsd
vagrant plugin install vagrant-vbguest
5恶迈、Vagrant啟動(dòng)
- 在vagrant文件夾下涩金,打開(kāi)命令行,執(zhí)行vagrant up 命令啟動(dòng)鏡像暇仲,啟動(dòng)成功后步做,在文件夾下會(huì)出現(xiàn)一個(gè).vagrant文件夾。
vagrant up #啟動(dòng)vagrant
- 使用vagrant ssh 命令連接虛擬機(jī)奈附,默認(rèn)賬號(hào) vagrant全度, 密碼 vagrant
vagrant ssh #使用ssh