创建
cd /home/vm
cp -rf ubuntu127/ ubuntu128
cd ubuntu128
vim Vagrantfile
rm -rf .vagrant
vagrant up
Vagrantfile 文件内容
sudo tee ~/Vagrantfile <<-'EOF'
# -*- mode: ruby -*-
# vi: set ft=ruby :
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure("2") do |config|
# The most common configuration options are documented and commented below.
# For a complete reference, please see the online documentation at
# https://docs.vagrantup.com.
# Every Vagrant development environment requires a box. You can search for
# boxes at https://vagrantcloud.com/search.
config.vm.box = "centos/7"
end
EOF
sudo tee /root/vagrant/Vagrantfile <<-'EOF'
# -*- mode: ruby -*-
# vi: set ft=ruby :
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure("2") do |config|
# config.provider=PROVIDER
# The most common configuration options are documented and commented below.
# For a complete reference, please see the online documentation at
# https://docs.vagrantup.com.
# Every Vagrant development environment requires a box. You can search for
# boxes at https://vagrantcloud.com/search.
# config.vm.box = "ubuntu/trusty64"
# vagrant plugin install --plugin-clean-sources --plugin-source https://gems.ruby-china.com/vagrant-vmware-fusion
# 服务器1
config.vm.define "u125" do |node|
node.vm.box = "ubuntu18.04"
node.vm.hostname = "u125"
#node.ssh.username = "root"
#node.ssh.password = "root"
#node.ssh.insert_key = "true"
# node.vm.network "forwarded_port", guest: 80, host: 8080
# node.vm.synced_folder "./data", "/data"
node.vm.network "public_network" , type: "static", ip: "192.168.2.125"
# node.vm.network "forwarded_port", guest: 4443, host: 4443
# node.vm.network "forwarded_port", guest: 443, host: 8443
# node.vm.network "forwarded_port", guest: 80, host: 8000
# node.vm.network "forwarded_port", guest: 10000, host: 10000
# node.vm.provider "vmware_desktop" do |v|
# v.vmx["memsize"] = "8000"
# v.vmx["numvcpus"] = "4"
# end
node.vm.provider "virtualbox" do |vb|
vb.memory = "4000"
end
# for i in 20000..20050
# node.vm.network "forwarded_port", guest: i, host: i
# end
end
# 服务器2
config.vm.define "u126" do |node|
node.vm.box = "ubuntu18.04"
node.vm.hostname = "u126"
#node.ssh.username = "root"
#node.ssh.password = "root"
#node.ssh.insert_key = "true"
# node.vm.network "forwarded_port", guest: 80, host: 8080
# node.vm.synced_folder "./data", "/data"
node.vm.network "public_network" , type: "static", ip: "192.168.2.126"
# node.vm.network "forwarded_port", guest: 4443, host: 4443
# node.vm.network "forwarded_port", guest: 443, host: 8443
# node.vm.network "forwarded_port", guest: 80, host: 8000
# node.vm.network "forwarded_port", guest: 10000, host: 10000
# node.vm.provider "vmware_desktop" do |v|
# v.vmx["memsize"] = "8000"
# v.vmx["numvcpus"] = "4"
# end
node.vm.provider "virtualbox" do |vb|
vb.memory = "4000"
end
# for i in 20000..20050
# node.vm.network "forwarded_port", guest: i, host: i
# end
end
# 定义 jitsi meet 服务器
config.vm.define "c127" do |node|
node.vm.box = "centos/7"
node.vm.hostname = "c127"
#node.ssh.username = "root"
#node.ssh.password = "root"
#node.ssh.insert_key = "true"
# node.vm.network "forwarded_port", guest: 80, host: 8080
# node.vm.synced_folder "./data", "/data"
node.vm.network "public_network" , type: "static", ip: "192.168.2.127"
# node.vm.network "forwarded_port", guest: 4443, host: 4443
# node.vm.network "forwarded_port", guest: 443, host: 8443
# node.vm.network "forwarded_port", guest: 80, host: 8000
# node.vm.network "forwarded_port", guest: 10000, host: 10000
# node.vm.provider "vmware_desktop" do |v|
# v.vmx["memsize"] = "8000"
# v.vmx["numvcpus"] = "4"
# end
node.vm.provider "virtualbox" do |vb|
vb.memory = "4000"
end
# for i in 20000..20050
# node.vm.network "forwarded_port", guest: i, host: i
# end
end
end
EOF
重启
vagrant reload
登录
vagrant ssh
ifconfig -a
常用的几个vagrant命令
- vagrant up ? ? ? ?# 启动虚拟机
- vagrant halt ? ? ?# 关闭虚拟机
- vagrant reload ? ?# 重启虚拟机
- vagrant ssh ? ? ? # SSH 至虚拟机
- vagrant suspend ? # 挂起虚拟机
- vagrant resume ? ?# 唤醒虚拟机
- vagrant status ? ?# 查看虚拟机运行状态
- vagrant destroy ? # 销毁当前虚拟机
box管理命令
vagrant box list ? ?# 查看本地box列表
vagrant box add ? ? # 添加box到列表
vagrant box remove ?# 从box列表移除
|