Vagrant bir geliştirici aracıdır. Linux, Mac ve Windows ortamlarını kolay ve hızlı bir şekilde ayağa kaldırabilir. Bir Vagrantfile üzerinden tanımlanan ayarlar üzerinden işlemlerimizi gerçekleştiririz. Aynı zamanda bu işlemlerin dosya üzerinden gitmesinden ötürü paylaşıldığı durumda anlaşılması kolaydır.
Vagrant’ın çalışması için bir sanallaştırma ortamına ihtiyaç vardır. Bu virtualbox veya vmware olabilir.
Vahrant içerisinde çalışacak olan box’lara https://app.vagrantup.com/boxes üzerinden ulaşılabilir.
-
Kurulum (VirtualBox)
Öncelikle sistemi güncellemeleri ve vagrant’ın üzerinde çalışacağı sanallaştırma katmanını kurmalıyız.
apt update && apt upgrade -y apt install virtualbox
Daha sonra vagrant dosyasını çekip onun üzerinden kurulum yapabiliriz.
curl -O https://releases.hashicorp.com/vagrant/2.2.9/vagrant_2.2.9_x86_64.deb apt install ./vagrant_2.2.9_x86_64.deb
Kurulum sonrasında versiyonu kontrol edelim.
vagrant --version Vagrant 2.2.9
-
Proje Oluşturmak
Bir dizin oluşturup içine girelim. Sonrasında aşağıdaki komut ile bir box indirelim.
vagrant init centos/8 ==> vagrant: A new version of Vagrant is available: 2.3.4 (installed version: 2.2.9)! ==> vagrant: To upgrade visit: https://www.vagrantup.com/downloads.html 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.
Bu işlem sonucunda burada bir
Vagrantfile
dosyası oluşacaktır. Bu dosya varsayılan olarak Ruby dosya tanımlayıcısı ile birlikte gelecektir. Şimdi bunu ayağa kaldırmak için yapmamız gereken tek şey;vagrant up Bringing machine 'default' up with 'virtualbox' provider... ==> default: Box 'centos/8' could not be found. Attempting to find and install... default: Box Provider: virtualbox default: Box Version: >= 0 ==> default: Loading metadata for box 'centos/8' default: URL: https://vagrantcloud.com/centos/8 ==> default: Adding box 'centos/8' (v2011.0) for provider: virtualbox default: Downloading: https://vagrantcloud.com/centos/boxes/8/versions/2011.0/providers/virtualbox.box Download redirected to host: cloud.centos.org default: Calculating and comparing box checksum... ==> default: Successfully added box 'centos/8' (v2011.0) for 'virtualbox'! ==> default: Importing base box 'centos/8'... ==> default: Matching MAC address for NAT networking... ==> default: Checking if box 'centos/8' version '2011.0' is up to date... ==> default: Setting the name of the VM: centos-test_default_1673384215218_9454 ==> 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. ==> default: Rsyncing folder: /home/sergen/centos-test/ => /vagrant
Çıktılar okunduğunda anlaşılabileceği gibi öncelikle gidip centos 8 imajını çekti, sonra onu virtualbox üzerinde çalışırtırdı ve bize erişim için bir ssh key üretti. Son olarak yaptığı işlemleri Vagrantfile ile erişledi ve çıktı. Sonrasında sanal makineye erişmek için yapmamız gereken;
vagrant ssh
Kapatmak için
vagrant halt ==> default: Attempting graceful shutdown of VM...
Silmek için
vagrant destroy default: Are you sure you want to destroy the 'default' VM? [y/N] y ==> default: Destroying VM and associated drives...
-
Kaynaklar
Vagrant Nedir? Nasıl Kullanılır? - ByPolat - muhammedpolat.com.tr