User Tools

Site Tools


технология_vagrant

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
технология_vagrant [2023/07/24 12:02]
val [Multi-Machine Vagrant Environments]
технология_vagrant [2025/02/11 13:00] (current)
val [Provision с использованием внешних скриптов]
Line 12: Line 12:
 ===== Установка ===== ===== Установка =====
  
-  * [[https://​val.bmstu.ru/​unix/​HashiCorp/​vagrant_2.2.10_x86_64.msi]] ​+  ​* [[https://​hashicorp-releases.yandexcloud.net/​vagrant/​]] 
 + 
 +  ​* [[https://​val.bmstu.ru/​unix/​HashiCorp/​vagrant_2.4.3_windows_amd64.msi]] ​
   * Можно не перезагружать систему,​ но нужно перезапустить Cmder   * Можно не перезагружать систему,​ но нужно перезапустить Cmder
  
Line 37: Line 39:
  
   * [[https://​val.bmstu.ru/​unix/​HashiCorp/​ubuntu_20.04.box]]   * [[https://​val.bmstu.ru/​unix/​HashiCorp/​ubuntu_20.04.box]]
 +  * [[https://​val.bmstu.ru/​unix/​HashiCorp/​debian12-generic.box]]
  
   * [[Переменные окружения]]   * [[Переменные окружения]]
Line 44: Line 47:
 $ vagrant box list $ vagrant box list
  
-$ vagrant box add debian/bullseye64+### vagrant box add /c/​distrs/​ubuntu_20.04.box --name specialist/​ubuntu20
  
-$ vagrant box list+### vagrant box add generic/​debian12
  
-$ ### vagrant package --base ubuntu_20.04_03 --output /​c/​distrs/​ubuntu_20.04.box +$ vagrant box add /c/distrs/debian12-generic.box --name ​generic/debian12
- +
-$ vagrant box add /c/distrs/ubuntu_20.04.box --name ​specialist/ubuntu20+
  
 $ vagrant box list $ vagrant box list
- 
-$ ### vagrant box remove specialist/​ubuntu20 
 </​code>​ </​code>​
  
Line 64: Line 63:
 $ cd ~/nodes $ cd ~/nodes
  
-$ vagrant init specialist/​ubuntu20+###vagrant init specialist/​ubuntu20 
 +$ vagrant init generic/​debian12
  
 $ less Vagrantfile $ less Vagrantfile
 ... ...
-    config.vm.box = "specialist/​ubuntu20"+    config.vm.box = "........"
 ... ...
  
 $ vagrant up $ vagrant up
 +
 +$ ssh -p 2NNN vagrant@localhost
  
 $ vagrant ssh $ vagrant ssh
Line 77: Line 79:
 $ vagrant global-status $ vagrant global-status
  
-$ vagrant global-status --prune+###vagrant global-status --prune
  
 $ vagrant halt $ vagrant halt
Line 120: Line 122:
 #      vb.customize ['​createhd',​ '​--filename',​ file_to_disk,​ '​--size',​ 4 * 1024] #      vb.customize ['​createhd',​ '​--filename',​ file_to_disk,​ '​--size',​ 4 * 1024]
 #    end #    end
-#    vb.customize ['​storageattach',​ :id, '​--storagectl',​ '​SATA',​ '​--port',​ 2, '​--device',​ 0, '​--type',​ '​hdd',​ '​--medium',​ file_to_disk]+#    vb.customize ['​storageattach',​ :id, '​--storagectl',​ '​SATA ​или SATA Controller', '​--port',​ 2, '​--device',​ 0, '​--type',​ '​hdd',​ '​--medium',​ file_to_disk]
  
   end   end
Line 166: Line 168:
 $ date $ date
  
-λ vagrant reload --provision+λ vagrant up --provision 
 +λ ###vagrant provision --provision-with provision_once 
 +λ ###vagrant reload --provision
  
 λ vagrant ssh λ vagrant ssh
 +
 $ date $ date
 +$ ip a
 </​code>​ </​code>​
  
Line 175: Line 181:
  
   * [[https://​stackoverflow.com/​questions/​15461898/​passing-variable-to-a-shell-script-provisioner-in-vagrant|Passing variable to a shell script provisioner in vagrant]]   * [[https://​stackoverflow.com/​questions/​15461898/​passing-variable-to-a-shell-script-provisioner-in-vagrant|Passing variable to a shell script provisioner in vagrant]]
 +
 +<​code>​
 +vagrant.exe ssh node2 -c 'sudo apt install open-iscsi -y'
 +
 +vagrant.exe ssh node3 -c 'sudo apt install open-iscsi -y'
 +</​code>​
  
 <​code>​ <​code>​
 λ touch provision_once.sh λ touch provision_once.sh
 </​code><​code>​ </​code><​code>​
 +#!/bin/sh
 +
 #echo '​root:​strongpassword'​ | chpasswd #echo '​root:​strongpassword'​ | chpasswd
 #sed -i '​s/​PasswordAuthentication no/​PasswordAuthentication yes/g' /​etc/​ssh/​sshd_config #sed -i '​s/​PasswordAuthentication no/​PasswordAuthentication yes/g' /​etc/​ssh/​sshd_config
Line 189: Line 203:
 timedatectl set-timezone Europe/​Moscow timedatectl set-timezone Europe/​Moscow
  
-apt update +apt-get update 
-#apt install -y docker.io+ 
 +apt-get purge resolvconf 
 +rm /​etc/​resolv.conf 
 +touch /​etc/​resolv.conf 
 + 
 +#apt-get install -y docker.io
 </​code><​code>​ </​code><​code>​
 λ touch provision_onstart.sh λ touch provision_onstart.sh
 </​code><​code>​ </​code><​code>​
 +#!/bin/bash
 +
 X=$1 X=$1
  
-echo $X+echo "$X"
  
-route add default gw 192.168.$X.1+route add default gw 192.168."$X".1
  
-eval `route -n | awk '{ if ($8 =="​eth0"​ && $2 != "​0.0.0.0"​) print "route del default gw " $2; }'`+eval "$(route -n | awk '{ if ($8 =="​eth0"​ && $2 != "​0.0.0.0"​) print "route del default gw " $2; }')"
  
 chattr -i /​etc/​resolv.conf chattr -i /​etc/​resolv.conf
Line 211: Line 232:
 </​code><​code>​ </​code><​code>​
 ... ...
 +  config.vm.synced_folder "​.",​ "/​vagrant",​ disabled: false
 +...
 +### My provision ###
 +### /My provision ###
 +...
 +</​code><​code>​
 +vagrant@node1:​~$ ls /vagrant/
 +
 +vagrant@node1:​~$ tr -d '​\r'​ < /​vagrant/​provision_once.sh ​ | shellcheck -
 +vagrant@node1:​~$ tr -d '​\r'​ < /​vagrant/​provision_onstart.sh ​ | shellcheck -
 +</​code><​code>​
 +λ cat Vagrantfile
 +</​code><​code>​
 ### My provision ### ### My provision ###
  
Line 225: Line 259:
  
 server# ssh vagrant@node1 server# ssh vagrant@node1
- 
-vagrant@node1:​~$ ls /vagrant/ 
 </​code>​ </​code>​
  
Line 303: Line 335:
  
 λ vagrant ssh node2 λ vagrant ssh node2
 +
 +λ vagrant halt node2
  
 λ vagrant destroy node1 λ vagrant destroy node1
Line 310: Line 344:
 λ cd ~/​conf/​vagrant/​nodes λ cd ~/​conf/​vagrant/​nodes
  
-λ nano Vagrantfile ​  #!!! set X+λ nano Vagrantfile ​  #!!! set X and mem 1024
  
 λ cat provision_once.sh ​  # look passwords λ cat provision_once.sh ​  # look passwords
Line 319: Line 353:
 ===== Дополнительные возможности ===== ===== Дополнительные возможности =====
  
-==== Использование синхронизируемых каталогов ==== 
  
-<​code>​ 
-λ cat Vagrantfile 
-</​code><​code>​ 
-... 
-#  config.vm.synced_folder "​.",​ "/​vagrant",​ type: "​rsync",​ rsync__exclude:​ "​.git/"​ 
-... 
-</​code><​code>​ 
-λ npp SomeFile 
-... 
- 
-λ vagrant rsync 
- 
-λ vagrant ssh 
- 
-vagrant@node3:​~$ ls /vagrant/ 
-</​code><​code>​ 
-... 
-Vagrantfile 
-... 
-SomeFile 
-... 
-</​code>​ 
  
 ==== Еще варианты Multi-Machine Vagrant Environments ==== ==== Еще варианты Multi-Machine Vagrant Environments ====
технология_vagrant.1690189355.txt.gz · Last modified: 2023/07/24 12:02 by val