Vagrant продукт компании HashiCorp, специализирующейся на инструментах для автоматизации разработки и эксплуатации
Скачать 435 Kb.
|
Настройка сетиДва сетевых интерфейса: NAT + BridgedОтредактируем файл Vagrantfile: Vagrant.configure(2) do |config| # образ системы Ubuntu 18/04 LTS (Bionic Beaver) config.vm.box = "bento/ubuntu-18.04" # не проверять репозиторий на наличие обновлений config.vm.box_check_update = false config.vm.provider "virtualbox" do |vb| # имя виртуальной машины vb.name = "ubuntu-1804-test" # объем оперативной памяти vb.memory = 2048 # количество ядер процессора vb.cpus = 1 end # hostname виртуальной машины config.vm.hostname = "ubuntu-1804-test" # настройка сети (сетевой мост на втором интерфейсе) config.vm.network "public_network" endКопировать И запустим виртуальную машину: $ vagrant up Bringing machine 'default' up with 'virtualbox' provider... ==> default: Importing base box 'bento/ubuntu-18.04'... ==> default: Matching MAC address for NAT networking... ==> default: Setting the name of the VM: ubuntu-1804-test ==> default: Clearing any previously set network interfaces... ==> default: Preparing network interfaces based on configuration... default: Adapter 1: nat default: Adapter 2: bridged ==> 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: Machine booted and ready! ==> default: Checking for guest additions in VM... ==> default: Setting hostname... ==> default: Configuring and enabling network interfaces... ==> default: Mounting shared folders... default: /vagrant => D:/vagrant/wwwКопировать Зайдем на виртуальную машину по ssh (по ключу): $ vagrant ssh Welcome to Ubuntu 18.04.3 LTS (GNU/Linux 4.15.0-65-generic x86_64) * Documentation: https://help.ubuntu.com * Management: https://landscape.canonical.com * Support: https://ubuntu.com/advantage System information as of Sat Nov 23 04:49:36 UTC 2019 System load: 0.41 Processes: 91 Usage of /: 2.5% of 61.80GB Users logged in: 0 Memory usage: 5% IP address for eth0: 10.0.2.15 Swap usage: 0% IP address for eth1: 192.168.110.14 * Overheard at KubeCon: "microk8s.status just blew my mind". https://microk8s.io/docs/commands#microk8s.status 0 packages can be updated. 0 updates are security updates. This system is built by the Bento project by Chef Software More information can be found at https://github.com/chef/bento/README.mdКопировать И посмотрим сетевые интерфейсы: $ ifconfig eth0: flags=4163 inet 10.0.2.15 netmask 255.255.255.0 broadcast 10.0.2.255 inet6 fe80::a00:27ff:fe6d:95c4 prefixlen 64 scopeid 0x20 ether 08:00:27:6d:95:c4 txqueuelen 1000 (Ethernet) RX packets 1745 bytes 687041 (687.0 KB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 1048 bytes 160253 (160.2 KB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 eth1: flags=4163 inet 192.168.110.14 netmask 255.255.255.0 broadcast 192.168.110.255 inet6 fe80::a00:27ff:febc:4f40 prefixlen 64 scopeid 0x20 ether 08:00:27:bc:4f:40 txqueuelen 1000 (Ethernet) RX packets 1614 bytes 97406 (97.4 KB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 16 bytes 1728 (1.7 KB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 lo: flags=73 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10 loop txqueuelen 1000 (Local Loopback) RX packets 20 bytes 1776 (1.7 KB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 20 bytes 1776 (1.7 KB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0Копировать У нас их два: eth0 (NAT, добавляется автоматически) и eth1 (сетевой мост, по нашему требованию). Виртуальная машина теперь является частью той же сети, что и хост-система и получает ip-адрес от роутера, на котором запущена служба DHCP. Два сетевых интерфейса: NAT + HostonlyОтредактируем файл Vagrantfile: Vagrant.configure(2) do |config| # образ системы Ubuntu 18/04 LTS (Bionic Beaver) config.vm.box = "bento/ubuntu-18.04" # не проверять репозиторий на наличие обновлений config.vm.box_check_update = false config.vm.provider "virtualbox" do |vb| # имя виртуальной машины vb.name = "ubuntu-1804-test" # объем оперативной памяти vb.memory = 2048 # количество ядер процессора vb.cpus = 1 end # hostname виртуальной машины config.vm.hostname = "ubuntu-1804-test" # настройки сети config.vm.network "private_network", type: "dhcp" endКопировать И запустим виртуальную машину: $ vagrant up Bringing machine 'default' up with 'virtualbox' provider... ==> default: Importing base box 'bento/ubuntu-18.04'... ==> default: Matching MAC address for NAT networking... ==> default: Setting the name of the VM: ubuntu-1804-test ==> default: Clearing any previously set network interfaces... ==> default: Preparing network interfaces based on configuration... default: Adapter 1: nat default: Adapter 2: hostonly ==> 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: Machine booted and ready! ==> default: Checking for guest additions in VM... ==> default: Setting hostname... ==> default: Configuring and enabling network interfaces... ==> default: Mounting shared folders... default: /vagrant => D:/vagrant/wwwКопировать Зайдем на виртуальную машину по ssh (по ключу): $ vagrant ssh Welcome to Ubuntu 18.04.3 LTS (GNU/Linux 4.15.0-65-generic x86_64) * Documentation: https://help.ubuntu.com * Management: https://landscape.canonical.com * Support: https://ubuntu.com/advantage System information as of Sat Nov 23 06:00:25 UTC 2019 System load: 0.0 Processes: 88 Usage of /: 2.5% of 61.80GB Users logged in: 0 Memory usage: 5% IP address for eth0: 10.0.2.15 Swap usage: 0% IP address for eth1: 172.28.128.3 * Overheard at KubeCon: "microk8s.status just blew my mind". https://microk8s.io/docs/commands#microk8s.status 0 packages can be updated. 0 updates are security updates. This system is built by the Bento project by Chef Software More information can be found at https://github.com/chef/bento/README.mdКопировать И посмотрим сетевые интерфейсы: $ ifconfig eth0: flags=4163 inet 10.0.2.15 netmask 255.255.255.0 broadcast 10.0.2.255 inet6 fe80::a00:27ff:fe6d:95c4 prefixlen 64 scopeid 0x20 ether 08:00:27:6d:95:c4 txqueuelen 1000 (Ethernet) RX packets 1473 bytes 653711 (653.7 KB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 847 bytes 126122 (126.1 KB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 eth1: flags=4163 inet 172.28.128.3 netmask 255.255.255.0 broadcast 172.28.128.255 inet6 fe80::a00:27ff:fefc:1a31 prefixlen 64 scopeid 0x20 ether 08:00:27:fc:1a:31 txqueuelen 1000 (Ethernet) RX packets 43 bytes 5179 (5.1 KB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 15 bytes 1698 (1.6 KB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 lo: flags=73 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10 loop txqueuelen 1000 (Local Loopback) RX packets 20 bytes 1776 (1.7 KB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 20 bytes 1776 (1.7 KB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0Копировать У нас их два: eth0 (NAT, добавляется автоматически) и eth1 (виртуальный адаптер хоста, по нашему требованию). У виртуальной машины есть выход в интернет через NAT и она в одной сети с хост-системой. ip-адрес виртуальной машины 172.28.128.3 ip-адрес DHCP-сервера 172.28.128.2 ip-адрес хост-системы 172.28.128.1 |