Command note

建置 box
vagrant init
vagrant package –output 20170101_ec2.box –base “EC2 -test” –vagrantfile Vagrantfile

查看指令
vagrant global-status
vagrant box list
vagrant box  remove

(範例)
vagrant  box add ec2 ec2.box
del vagrant file
vagrant box remove ec2_20170106_vagrant
vagrant init ec2
vagrant up
vagrant global-status –prune

安裝外掛
vagrant plugin install vagrant-vbguest

清除
vagrant destroy -f
vagrant global-status
vagrant  destroy id



viturbox 指令方式

VBoxManage list vms 移轉到vagrant 上面

移轉動作

vagrant package –base acef4c0a-35be-4640-a214-be135417f04d –output UCS.box

vagrant package existing_instance_name –output new_instance_name.box

建立最小images

參考:https://scotch.io/tutorials/how-to-create-a-vagrant-base-box-from-an-existing-one

sudo apt-get clean

Then, “zero out” the drive (this is for Ubuntu):


sudo dd if=/dev/zero of=/EMPTY bs=1M
sudo rm -f /EMPTY

Lastly, let's clear the Bash History and exit the VM:

cat /dev/null > ~/.bash_history && history -c && exit

vagrant :現有-採取kpns方式

路徑:D:\pjo_vagrant

D:\pjo_vagrant\160405

box會存在另一方,可留可不留

Vagrantfile 設定 (這方式是透過網路下載下來之後再進行佈署)

程式碼如下:

VAGRANTFILE_API_VERSION = "2"
SERVERS = ["single"]
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.ssh.insert_key = false
  
  
  N = 1
  (1..N).each do |node_id|
    nid = (node_id - 1)
    config.vm.define SERVERS[nid] do |single|
     single.vm.hostname = SERVERS[nid]
      single.vm.box = "hon0612/EC2Ubuntu"
	  single.vm.box_version = "16.04.5"
	  single.ssh.username = "ubuntu"
	  single.ssh.port = "22#{33 + nid}"
	  single.vm.network "forwarded_port", guest: 22, host: "22#{33 + nid}", id: "ssh"
	  single.vm.network "private_network", ip: "172.35.1.#{33 + nid}"
	  single.vm.synced_folder "D:/pjo_vagrant/1604", "/vagrant", disabled: true
      single.ssh.forward_agent = true
      single.vm.provider "virtualbox" do |vb|
        vb.memory = 512
        vb.cpus = 1
      end
    end
  end
end






 #mongo.vm.synced_folder  "D:/pjo_vagrant/1604", "/vagrant", owner: "vagrant" , group: "vagrant" , mount_options: ["uid=1000", "gid=1000"] , disabled: true
 #config.vm.synced_folder "D:/pjo_vagrant/1604", "/vagrant", disabled: true

D:\pjo_vagrant\m-replica

Vagrantfile

VAGRANTFILE_API_VERSION = "2"
SERVERS = ["mongo1", "mongo2", "mongo3"]
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.ssh.insert_key = false
  config.vm.synced_folder "D:/pjo_vagrant/1604", "/vagrant", disabled: true
  
  
  N = 3
  (1..N).each do |node_id|
    nid = (node_id - 1)
    config.vm.define SERVERS[nid] do |mongo|
     mongo.vm.hostname = SERVERS[nid]
      mongo.vm.box = "hon0612/EC2Ubuntu"
	  mongo.vm.box_version = "16.04.5"
	  mongo.ssh.username = "ubuntu"
	  mongo.ssh.port = "22#{211 + nid}"
	  mongo.vm.network "forwarded_port", guest: 22, host: "22#{211 + nid}", id: "ssh"
	  mongo.vm.network "private_network", ip: "172.35.1.#{211 + nid}"
      mongo.ssh.forward_agent = true
      mongo.vm.provider "virtualbox" do |vb|
        vb.memory = 1024
        vb.cpus = 1
      end
    end
  end
end






 #mongo.vm.synced_folder  "D:/pjo_vagrant/1604", "/vagrant", owner: "vagrant" , group: "vagrant" , mount_options: ["uid=1000", "gid=1000"] , disabled: true
 #config.vm.synced_folder "D:/pjo_vagrant/1604", "/vagrant", disabled: true

Vagrantfile – 1604

VAGRANTFILE_API_VERSION = "2"
SERVERS = ["mongo1", "mongo2", "mongo3", "ansible"]
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.ssh.insert_key = false
  
  
  N = 3
  (1..N).each do |node_id|
    nid = (node_id - 1)
    config.vm.define SERVERS[nid] do |mongo|
     mongo.vm.hostname = SERVERS[nid]
      mongo.vm.box = "1604"
	  mongo.ssh.username = "ubuntu"
	  mongo.ssh.port = "22#{10 + nid}"
	  mongo.vm.network "forwarded_port", guest: 22, host: "22#{10 + nid}", id: "ssh"
	  mongo.vm.network "private_network", ip: "172.35.1.#{201 + nid}"
	  mongo.vm.synced_folder "D:/pjo_vagrant/1604", "/vagrant", disabled: true
      mongo.ssh.forward_agent = true
      mongo.vm.provider "virtualbox" do |vb|
        vb.memory = 1024
        vb.cpus = 1
      end
    end
  end
end






 #mongo.vm.synced_folder  "D:/pjo_vagrant/1604", "/vagrant", owner: "vagrant" , group: "vagrant" , mount_options: ["uid=1000", "gid=1000"] , disabled: true
 #config.vm.synced_folder "D:/pjo_vagrant/1604", "/vagrant", disabled: true

Vagrantfile – new -160405

VAGRANTFILE_API_VERSION = "2"
SERVERS = ["mongo1", "mongo2", "mongo3", "ansible"]
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.ssh.insert_key = false
  
  
  N = 3
  (1..N).each do |node_id|
    nid = (node_id - 1)
    config.vm.define SERVERS[nid] do |mongo|
     mongo.vm.hostname = SERVERS[nid]
      mongo.vm.box = "hon0612/EC2Ubuntu"
	  mongo.vm.box_version = "16.04.5"
	  mongo.ssh.username = "ubuntu"
	  mongo.ssh.port = "22#{10 + nid}"
	  mongo.vm.network "forwarded_port", guest: 22, host: "22#{10 + nid}", id: "ssh"
	  mongo.vm.network "private_network", ip: "172.35.1.#{201 + nid}"
	  mongo.vm.synced_folder "D:/pjo_vagrant/1604", "/vagrant", disabled: true
      mongo.ssh.forward_agent = true
      mongo.vm.provider "virtualbox" do |vb|
        vb.memory = 1024
        vb.cpus = 1
      end
    end
  end
end






 #mongo.vm.synced_folder  "D:/pjo_vagrant/1604", "/vagrant", owner: "vagrant" , group: "vagrant" , mount_options: ["uid=1000", "gid=1000"] , disabled: true
 #config.vm.synced_folder "D:/pjo_vagrant/1604", "/vagrant", disabled: true

D:\pjo_vagrant\Xwindows

VAGRANTFILE_API_VERSION = "2"
SERVERS = ["xww"]
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.ssh.insert_key = false
  config.vm.synced_folder "D:/pjo_vagrant/1604", "/vagrant", disabled: true
  
  N = 1
  (1..N).each do |node_id|
    nid = (node_id - 1)
    config.vm.define SERVERS[nid] do |xw|
     xw.vm.hostname = SERVERS[nid]
      xw.vm.box = "x16042-1"
	  xw.ssh.username = "michael_hong"
	  xw.ssh.port = "22#{44 + nid}"
	  xw.vm.network "forwarded_port", guest: 22, host: "22#{44 + nid}", id: "ssh"
	  xw.vm.network "private_network", ip: "172.35.1.#{44 + nid}"
      xw.ssh.forward_agent = true
      xw.vm.provider "virtualboxw" do |vb|
        vb.memory = 4096
        vb.cpus = 4
      end
    end
  end
end






 #mongo.vm.synced_folder  "D:/pjo_vagrant/1604", "/vagrant", owner: "vagrant" , group: "vagrant" , mount_options: ["uid=1000", "gid=1000"] , disabled: true
 #config.vm.synced_folder "D:/pjo_vagrant/1604", "/vagrant", disabled: true

發表迴響

你的電子郵件位址並不會被公開。 必要欄位標記為 *