15.【オリジナル】vagrantを使用してVirtualBoxにlinuxミラーをインストールする
12221 ワード
vagrantは、仮想化開発環境の作成と導入に使用されるツールです.linuxインスタンスを初期化するのに便利ですが、あまり話さないで、具体的な操作手順を見てみましょう.
1.VirtualBoxのダウンロードインストール
VirtualBoxの公式サイトに直接ダウンロードすればいいです.基本的には難しくありません.インストールもバカです.マザーボードBoisの仮想化オプションをオンにするだけです(公式サイト:https://www.virtualbox.org/wiki/Downloads).
2.インストールVagrantをダウンロードする
2.1.Windowsの下でVagrantをインストールするのも比較的に簡単で、インストールディレクトリを選んで次のステップを狂点して、インストールした後にコンピュータ(住所:https://www.vagrantup.com/downloads).
2.2.コンピュータを再起動したら、cmdまたはpowershellを開いて「vagrant」コマンドを入力して少し待ってください.次の操作コマンドのプロンプトが表示されたら、インストールに成功します.
2.3.cmd(管理者として実行)でミラーを保存するディレクトリに切り替え、「vagrant init+ミラー名」を入力すると、ミラープロファイルをVirtualBoxに初期化できます.ミラー名はvagrantの公式サイトで確認できます.ここでは「ubuntu/trusty 64」(アドレス:https://app.vagrantup.com/boxes/search?provider=virtualbox).プロファイルが初期化されていることを示すプロンプトが表示されます.または、ファイルが生成されているかどうかを対応するディレクトリに確認します.(ここで「images」はミラーインストールフォルダであり、後のステップ3.1でミラーインストールアドレスが「VirtualBox」に切り替わる)
2.4.次に「vagrant up」コマンドを入力ミラーを起動し、最初の起動時にミラーファイルがないため、vagrantはそのリモートウェアハウスに対応するものをダウンロードする.box接尾辞のミラーは、ダウンロードが完了するとミラーが起動し、デフォルトで「vagrant」をミラーの管理者に設定します.「vagrant ssh」を使用して接続するか、sshツールを使用して接続すればいいです.しかし、実際の操作では、国内でvagrant公式倉庫からミラーをダウンロードするのは遅すぎることが分かった.従来の方法でlinuxを使用する2つのソリューションがありますiosファイルとVirtualBoxのインストールウィザードはインストールされていますが、この方法は今回の説明の範囲外です(この文書を参照してアリのミラーをダウンロードしてください:https://www.cnblogs.com/Nick-Hu/p/13277154.html).2つ目の方法はダウンロードすることです.boxはローカルにミラー化され、vagrantを使用してローカルのミラーをインポートします.次に、この方法について重点的に説明します.
3..以下の国内ミラーアドレスを使用してダウンロードする必要がある.boxミラー、vagrantを使用してローカルに追加します.
3.1.ダウンロードしてください.boxミラーリング後にミラーファイルをミラー格納ディレクトリに移動するには、以下のコマンドを使用して、このミラーリングをvagrantのミラーリストに追加します(VirtualBoxVmsはミラーインストールディレクトリ、コマンドフォーマット:vagrant box add{ミラーインスタンス名}{ミラーパス}).
3.2.ミラーを初期化するプロファイル(「ubuntu 16.04.001」は3.1ステップで定義したミラーインスタンス名)
3.3.ミラー・インスタンスの起動(「SSH address:127.0.0.1:2222」は、ミラー・インスタンスのアドレスとポート、「SSH username:vagrant」の初期化スーパー管理者のアカウント名とパスワードです)
3.4.「vagrant ssh」コマンドを使用してミラーインスタンスにアクセス
4.【付】Vagrant常用コマンド
シーケンス番号
コマンド#コマンド#
説明する
1
vagrant box list
既存のboxを表示
2
vagrant box add
新たにboxを追加
3
vagrant box remove
指定したboxを削除
4
vagrant init
vagrantfileの初期化
5
vagrant up
仮想マシンの起動
6
vagrant ssh ssh
仮想マシンへのログイン
7
vagrant suspend
仮想マシンを停止
8
vagrant reload
VMの再起動
9
vagrant halt
VMをシャットダウン
10
vagrant status
VMステータスの表示
11
vagrant destroy
VMの削除
1.VirtualBoxのダウンロードインストール
VirtualBoxの公式サイトに直接ダウンロードすればいいです.基本的には難しくありません.インストールもバカです.マザーボードBoisの仮想化オプションをオンにするだけです(公式サイト:https://www.virtualbox.org/wiki/Downloads).
2.インストールVagrantをダウンロードする
2.1.Windowsの下でVagrantをインストールするのも比較的に簡単で、インストールディレクトリを選んで次のステップを狂点して、インストールした後にコンピュータ(住所:https://www.vagrantup.com/downloads).
2.2.コンピュータを再起動したら、cmdまたはpowershellを開いて「vagrant」コマンドを入力して少し待ってください.次の操作コマンドのプロンプトが表示されたら、インストールに成功します.
Microsoft Windows [ 10.0.18362.900]
(c) 2019 Microsoft Corporation。 。
C:\Users\Nick>vagrant
Usage: vagrant [options] []
-h, --help Print this help.
Common commands:
box manages boxes: installation, removal, etc.
cloud manages everything related to Vagrant Cloud
destroy stops and deletes all traces of the vagrant machine
global-status outputs status Vagrant environments for this user
halt stops the vagrant machine
help shows the help for a subcommand
init initializes a new Vagrant environment by creating a Vagrantfile
login
package packages a running vagrant environment into a box
plugin manages plugins: install, uninstall, update, etc.
port displays information about guest port mappings
powershell connects to machine via powershell remoting
provision provisions the vagrant machine
push deploys code in this environment to a configured destination
rdp connects to machine via RDP
reload restarts vagrant machine, loads new Vagrantfile configuration
resume resume a suspended vagrant machine
snapshot manages snapshots: saving, restoring, etc.
ssh connects to machine via SSH
ssh-config outputs OpenSSH valid configuration to connect to the machine
status outputs status of the vagrant machine
suspend suspends the machine
up starts and provisions the vagrant environment
upload upload to machine via communicator
validate validates the Vagrantfile
version prints current and latest Vagrant version
winrm executes commands on a machine via WinRM
winrm-config outputs WinRM configuration to connect to the machine
For help on any individual command run `vagrant COMMAND -h`
Additional subcommands are available, but are either more advanced
or not commonly used. To see all subcommands, run the command
`vagrant list-commands`.
--[no-]color Enable or disable color output
--machine-readable Enable machine readable output
-v, --version Display Vagrant version
--debug Enable debug output
--timestamp Enable timestamps on log output
--debug-timestamp Enable debug output with timestamps
--no-tty Enable non-interactive output
2.3.cmd(管理者として実行)でミラーを保存するディレクトリに切り替え、「vagrant init+ミラー名」を入力すると、ミラープロファイルをVirtualBoxに初期化できます.ミラー名はvagrantの公式サイトで確認できます.ここでは「ubuntu/trusty 64」(アドレス:https://app.vagrantup.com/boxes/search?provider=virtualbox).プロファイルが初期化されていることを示すプロンプトが表示されます.または、ファイルが生成されているかどうかを対応するディレクトリに確認します.(ここで「images」はミラーインストールフォルダであり、後のステップ3.1でミラーインストールアドレスが「VirtualBox」に切り替わる)
G:\Vagrant\images>vagrant init ubuntu/trusty64
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.
2.4.次に「vagrant up」コマンドを入力ミラーを起動し、最初の起動時にミラーファイルがないため、vagrantはそのリモートウェアハウスに対応するものをダウンロードする.box接尾辞のミラーは、ダウンロードが完了するとミラーが起動し、デフォルトで「vagrant」をミラーの管理者に設定します.「vagrant ssh」を使用して接続するか、sshツールを使用して接続すればいいです.しかし、実際の操作では、国内でvagrant公式倉庫からミラーをダウンロードするのは遅すぎることが分かった.従来の方法でlinuxを使用する2つのソリューションがありますiosファイルとVirtualBoxのインストールウィザードはインストールされていますが、この方法は今回の説明の範囲外です(この文書を参照してアリのミラーをダウンロードしてください:https://www.cnblogs.com/Nick-Hu/p/13277154.html).2つ目の方法はダウンロードすることです.boxはローカルにミラー化され、vagrantを使用してローカルのミラーをインポートします.次に、この方法について重点的に説明します.
3..以下の国内ミラーアドレスを使用してダウンロードする必要がある.boxミラー、vagrantを使用してローカルに追加します.
CentOS 6/7/8 http://mirrors.ustc.edu.cn/centos-cloud/centos/6/vagrant/x86_64/images/
Ubuntu Server 14.04 https://mirrors.ustc.edu.cn/ubuntu-cloud-images/server/vagrant/trusty/current/
Ubuntu Server 16.04 https://mirrors.ustc.edu.cn/ubuntu-cloud-images/server/xenial/current/
Ubuntu Server 18.04 https://mirrors.ustc.edu.cn/ubuntu-cloud-images/server/bionic/current/
Ubuntu Server 20.04 http://mirrors.ustc.edu.cn/ubuntu-cloud-images/focal/current/
3.1.ダウンロードしてください.boxミラーリング後にミラーファイルをミラー格納ディレクトリに移動するには、以下のコマンドを使用して、このミラーリングをvagrantのミラーリストに追加します(VirtualBoxVmsはミラーインストールディレクトリ、コマンドフォーマット:vagrant box add{ミラーインスタンス名}{ミラーパス}).
G:\VirtualBoxVMs>vagrant box add ubuntu16.04.001 xenial-server-cloudimg-amd64-vagrant.box
==> box: Box file was not detected as metadata. Adding it directly...
==> box: Adding box 'ubuntu16.04.001' (v0) for provider:
box: Unpacking necessary files from: file://G:/VirtualBoxVMs/xenial-server-cloudimg-amd64-vagrant.box
box:
==> box: Successfully added box 'ubuntu16.04.001' (v0) for 'virtualbox'!
G:\VirtualBoxVMs>vagrant init ubuntu16.04.001
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.
3.2.ミラーを初期化するプロファイル(「ubuntu 16.04.001」は3.1ステップで定義したミラーインスタンス名)
G:\VirtualBoxVMs>vagrant init ubuntu16.04.001
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.
3.3.ミラー・インスタンスの起動(「SSH address:127.0.0.1:2222」は、ミラー・インスタンスのアドレスとポート、「SSH username:vagrant」の初期化スーパー管理者のアカウント名とパスワードです)
G:\VirtualBoxVMs>vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'ubuntu16.04.001'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: VirtualBoxVMs_default_1594313488822_28629
Vagrant is currently configured to create VirtualBox synced folders with
the `SharedFoldersEnableSymlinksCreate` option enabled. If the Vagrant
guest is not trusted, you may want to disable this option. For more
information on this option, please refer to the VirtualBox manual:
https://www.virtualbox.org/manual/ch04.html#sharedfolders
This option can be disabled globally with an environment variable:
VAGRANT_DISABLE_VBOXSYMLINKCREATE=1
or on a per folder basis within the Vagrantfile:
config.vm.synced_folder '/host/path', '/guest/path', SharedFoldersEnableSymlinksCreate: false
==> 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: Running 'pre-boot' VM customizations...
==> 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: Warning: Connection reset. Retrying...
default: Warning: Connection aborted. Retrying...
default: Warning: Remote connection disconnect. Retrying...
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: The guest additions on this VM do not match the installed version of
default: VirtualBox! In most cases this is fine, but in rare cases it can
default: prevent things such as shared folders from working properly. If you see
default: shared folder errors, please make sure the guest additions within the
default: virtual machine match the version of VirtualBox you have installed on
default: your host and reload your VM.
default:
default: Guest Additions Version: 5.1.38
default: VirtualBox Version: 6.1
==> default: Mounting shared folders...
default: /vagrant => G:/VirtualBoxVMs
3.4.「vagrant ssh」コマンドを使用してミラーインスタンスにアクセス
G:\VirtualBoxVMs>vagrant ssh
Welcome to Ubuntu 16.04.6 LTS (GNU/Linux 4.4.0-184-generic x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
0 packages can be updated.
0 updates are security updates.
New release '18.04.4 LTS' available.
Run 'do-release-upgrade' to upgrade to it.
Welcome to Ubuntu 16.04.6 LTS (GNU/Linux 4.4.0-184-generic x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
0 packages can be updated.
0 updates are security updates.
New release '18.04.4 LTS' available.
Run 'do-release-upgrade' to upgrade to it.
vagrant@ubuntu-xenial:/$ ls
bin dev home initrd.img.old lib64 media opt root sbin srv tmp vagrant vmlinuz
boot etc initrd.img lib lost+found mnt proc run snap sys usr var vmlinuz.old
vagrant@ubuntu-xenial:/$ exit
logout
Connection to 127.0.0.1 closed.
4.【付】Vagrant常用コマンド
シーケンス番号
コマンド#コマンド#
説明する
1
vagrant box list
既存のboxを表示
2
vagrant box add
新たにboxを追加
3
vagrant box remove
指定したboxを削除
4
vagrant init
vagrantfileの初期化
5
vagrant up
仮想マシンの起動
6
vagrant ssh ssh
仮想マシンへのログイン
7
vagrant suspend
仮想マシンを停止
8
vagrant reload
VMの再起動
9
vagrant halt
VMをシャットダウン
10
vagrant status
VMステータスの表示
11
vagrant destroy
VMの削除