實戰 Istio入門與實戰》—3.2 Vagrant常用命令

      網友投稿 689 2022-05-29

      3.2 Vagrant常用命令

      注意事項:由于默認情況下,Vagrant會把臨時文件和Box文件存放在用戶主目錄里。如果Box文件過大,會導致占用過大空間,可以通過設置環境變量VAGRANT_HOME來設定Vagrant的主目錄路徑。Vagrant默認設置的主目錄為用戶主目錄的.vagrant.d文件夾。本次實驗時把此環境變量設置為D:\vagrant\home,關于各個操作系統的環境變量的設置,請查閱相關文檔。

      1. 基本命令

      基礎命令總覽:

      box add:導入box

      box list:查看box

      box remove:刪除box

      init:初始化

      up:啟動

      status:查看狀態

      ssh:SSH連接

      reload:重載

      halt:關閉

      suspend:暫停

      destroy:刪除

      下面舉例說明這些命令的使用方法。

      (1)導入Box

      導入已經下載的Box命令如下:

      $ vagrant box add --name centos-7.4-base /f/vagrant/box/centos-7.4-base.box

      ==> box: Box file was not detected as metadata. Adding it directly...

      ==> box: Adding box 'centos-7.4-base' (v0) for provider:

      box: Unpacking necessary files from: file://F:/vagrant/box/centos-7.4-base.box

      box:

      ==> box: Successfully added box 'centos-7.4-base' (v0) for 'virtualbox'!

      /f/vagrant/box/centos-7.4-base.box表示Box的路徑地址,這是由于使用了Git Bash的路徑表示方法。如果使用CMD命令行,使用F:/vagrant/box/centos-7.4-base.box即可。此處使用的Box從第2章“實驗說明”中提供的百度云盤鏈接上下載。

      (2)查看Box

      查看可用的Box如下所示:

      $ vagrant box list

      centos-7.4-base? ? ? (virtualbox, 0)

      (3)刪除Box

      刪除不再使用的Box如下所示:

      $ vagrant box remove centos-7.4-base

      Removing box 'centos-7.4-base' (v0) with provider 'virtualbox'...

      (4)初始化

      初始化虛擬機如下所示:

      $ mkdir test

      $ cd test

      $ vagrant init centos-7.4-base

      A 'Vagrantfile' has been placed in this directory. You are now

      ready to 'vagrant up' your first virtual environment! Please read

      the comments in the Vagrantfile as well as documentation on

      'vagrantup.com' for more information on using Vagrant.

      查看未被注釋配置文件內容:

      $ cat Vagrantfile | tr -d '\r' | egrep -v '^#|^ +#|^$'

      Vagrant.configure("2") do |config|

      config.vm.box = "centos-7.4-base"

      end

      (5)啟動

      啟動虛擬機如下所示:

      $ vagrant up

      Bringing machine 'default' up with 'virtualbox' provider...

      ==> default: Importing base box 'centos-7.4-base'...

      ==> default: Matching MAC address for NAT networking...

      ==> default: Setting the name of the VM: test_default_1543216915133_85015

      ==> default: Clearing any previously set network interfaces...

      ==> default: Preparing network interfaces based on configuration...

      default: Adapter 1: nat

      ==> default: Forwarding ports...

      default: 22 (guest) => 2222 (host) (adapter 1)

      ==> default: Booting VM...

      ==> default: Waiting for machine to boot. This may take a few minutes...

      default: SSH address: 127.0.0.1:2222

      default: SSH username: vagrant

      default: SSH auth method: private key

      default:

      default: Vagrant insecure key detected. Vagrant will automatically replace

      default: this with a newly generated keypair for better security.

      default:

      default: Inserting generated public key within guest...

      default: Removing insecure key from the guest if it's present...

      default: Key inserted! Disconnecting and reconnecting using new SSH key...

      ==> default: Machine booted and ready!

      ==> default: Checking for guest additions in VM...

      default: No guest additions were detected on the base box for this VM! Guest

      default: additions are required for forwarded ports, shared folders, host only

      default: networking, and more. If SSH fails on this machine, please install

      default: the guest additions and repackage the box to continue.

      default:

      default: This is not an error message; everything may continue to work properly,

      default: in which case you may ignore this message.

      (6)查看狀態

      查看虛擬機狀態如下所示:

      $ vagrant status

      Current machine states:

      default? ? ? ? ? ? ? ? ? ?running (virtualbox)

      The VM is running. To stop this VM, you can run 'vagrant halt' to

      shut it down forcefully, or you can run 'vagrant suspend' to simply

      suspend the virtual machine. In either case, to restart it again,

      simply run 'vagrant up'.

      (7)SSH連接

      注意,如果Windows下使用Git Bash時無法使用SSH連接虛擬機,可以嘗試使用系統自己帶的命令行工具CMD連接虛擬機:

      $ vagrant ssh

      Last login: Tue Dec 12 16:01:23 2017 from 10.0.2.2

      [vagrant@localhost ~]$ hostname

      localhost.localdomain

      [vagrant@localhost ~]$ ip a

      1: lo: mtu 65536 qdisc noqueue state UNKNOWN qlen 1

      link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

      inet 127.0.0.1/8 scope host lo

      valid_lft forever preferred_lft forever

      inet6 ::1/128 scope host

      valid_lft forever preferred_lft forever

      2: eth0: mtu 1500 qdisc pfifo_fast state UP qlen 1000

      link/ether 52:54:00:ca:e4:8b brd ff:ff:ff:ff:ff:ff

      inet 10.0.2.15/24 brd 10.0.2.255 scope global dynamic eth0

      valid_lft 86194sec preferred_lft 86194sec

      inet6 fe80::5054:ff:feca:e48b/64 scope link

      valid_lft forever preferred_lft forever

      [vagrant@localhost ~]$ exit;

      logout

      Connection to 127.0.0.1 closed.

      (8)重新

      當我們編輯當前文件夾下的虛擬機配置文件Vagrantfile后,可以使用reload命令重載虛擬機,使配置生效。比如添加設置主機名的配置:

      ...

      config.vm.box = "centos-7.4-base"

      config.vm.hostname = "istio"

      ...

      重載使配置文件生效:

      $ vagrant reload

      ==> default: Attempting graceful shutdown of VM...

      Connection to 127.0.0.1 closed by remote host.

      ==> default: Clearing any previously set forwarded ports...

      ==> default: Clearing any previously set network interfaces...

      ==> default: Preparing network interfaces based on configuration...

      default: Adapter 1: nat

      ==> default: Forwarding ports...

      default: 22 (guest) => 2222 (host) (adapter 1)

      ==> default: Booting VM...

      ==> default: Waiting for machine to boot. This may take a few minutes...

      default: SSH address: 127.0.0.1:2222

      default: SSH username: vagrant

      default: SSH auth method: private key

      ==> default: Machine booted and ready!

      ==> default: Checking for guest additions in VM...

      default: No guest additions were detected on the base box for this VM! Guest

      default: additions are required for forwarded ports, shared folders, host only

      default: networking, and more. If SSH fails on this machine, please install

      default: the guest additions and repackage the box to continue.

      default:

      default: This is not an error message; everything may continue to work properly,

      default: in which case you may ignore this message.

      ==> default: Setting hostname...

      ==> default: Machine already provisioned. Run 'vagrant provision' or use the '--provision'

      ==> default: flag to force provisioning. Provisioners marked to run always will still run.

      $ vagrant ssh

      Last login: Tue Dec 12 16:11:12 2017 from 10.0.2.2

      [vagrant@istio ~]$ hostname

      istio

      [vagrant@istio ~]$ exit;

      logout

      Connection to 127.0.0.1 closed.

      (9)關閉

      關閉虛擬機如下所示:

      $ vagrant halt

      ==> default: Attempting graceful shutdown of VM...

      (10)暫停

      由于上一步驟關閉虛擬機,執行本步驟時需要先啟動虛擬機,然后再暫停虛擬機:

      $ vagrant suspend

      ==> default: Saving VM state and suspending execution...

      (11)刪除

      刪除虛擬機的命令如下所示:

      $ vagrant destroy

      default: Are you sure you want to destroy the 'default' VM? [y/N] y

      ==> default: Discarding saved state of VM...

      ==> default: Destroying VM and associated drives...

      2. 使用虛擬機快照命令

      虛擬機快照命令如下:

      save:保存虛擬機快照。

      list:查看虛擬機快照。

      restore:用快照恢復虛擬機。

      delete:刪除虛擬機快照。

      進行如下快照的相關操作時,需要先創建虛擬機并啟動虛擬機。

      保存虛擬機快照示例:

      $ vagrant snapshot save istio

      ==> default: Snapshotting the machine as 'istio'...

      ==> default: Snapshot saved! You can restore the snapshot at any time by

      ==> default: using 'vagrant snapshot restore'. You can delete it using

      ==> default: 'vagrant snapshot delete'.

      查看虛擬機快照示例:

      $ vagrant snapshot list

      《實戰 Istio入門與實戰》—3.2 Vagrant常用命令

      istio

      用快照恢復虛擬機示例:

      $ vagrant snapshot restore istio

      ==> default: Forcing shutdown of VM...

      ==> default: Restoring the snapshot 'istio'...

      ==> default: Resuming suspended VM...

      ==> default: Booting VM...

      ==> default: Waiting for machine to boot. This may take a few minutes...

      default: SSH address: 127.0.0.1:2222

      default: SSH username: vagrant

      default: SSH auth method: private key

      ==> default: Machine booted and ready!

      刪除虛擬機快照示例:

      $ vagrant snapshot delete istio

      ==> default: Deleting the snapshot 'istio'...

      ==> default: Snapshot deleted!

      虛擬化 Istio

      版權聲明:本文內容由網絡用戶投稿,版權歸原作者所有,本站不擁有其著作權,亦不承擔相應法律責任。如果您發現本站中有涉嫌抄襲或描述失實的內容,請聯系我們jiasou666@gmail.com 處理,核實后本網站將在24小時內刪除侵權內容。

      上一篇:常見日語單詞
      下一篇:區塊鏈核心技術-密碼學
      相關文章
      亚洲 小说区 图片区 都市| 亚洲最大无码中文字幕| 亚洲成?v人片天堂网无码| 自拍偷区亚洲国内自拍| 亚洲一区在线视频观看| 亚洲欧洲日产国产最新| 亚洲黄色免费在线观看| 中文字幕亚洲色图| 亚洲综合激情九月婷婷| 亚洲无圣光一区二区| 亚洲国产精品久久丫| 亚洲乱码卡一卡二卡三| 亚洲婷婷第一狠人综合精品| 国产亚洲国产bv网站在线| 中日韩亚洲人成无码网站| 亚洲综合在线一区二区三区| 亚洲啪AV永久无码精品放毛片| 中文字幕亚洲综合久久综合| 亚洲AV无码之国产精品| 亚洲AⅤ男人的天堂在线观看| 亚洲av无码天堂一区二区三区| 亚洲Av无码乱码在线znlu| 不卡一卡二卡三亚洲| 亚洲AV无码久久精品色欲| 亚洲国产高清人在线| 亚洲经典在线观看| 久久精品国产亚洲av麻豆图片| 国产午夜亚洲精品国产| 国产精品亚洲一区二区三区在线观看| 亚洲?V无码乱码国产精品| 亚洲伊人久久综合中文成人网| 亚洲精品无码不卡在线播放HE| 亚洲av无码成h人动漫无遮挡| 亚洲第一精品在线视频| 亚洲成a人不卡在线观看| 亚洲成人激情小说| 国产亚洲美女精品久久久久| 国产精品亚洲不卡一区二区三区 | 人人狠狠综合久久亚洲88| 久久久久亚洲av无码专区蜜芽| 亚洲黄色中文字幕|