선 밖에 선 자유인

Vagrant Simple Test Lab 구성 본문

IT/Cloud & DevOps

Vagrant Simple Test Lab 구성

Hotman 2019. 4. 6. 16:51

- Vagrantfile

--------------------------------------

#-*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure(2) do |config|
    config.vm.provision "shell", inline: "echo X2"
    config.ssh.insert_key = false

    config.vm.define "lab1" do |cfg|
        cfg.vm.box = "bento/centos-8"
        cfg.vm.hostname = "lab1"
        cfg.vm.network "private_network", ip:"192.168.56.101"

        cfg.vm.synced_folder  "/Users/user/vagrant", "/vagrant"

        cfg.vm.provision  "shell", path: "user_ready.sh"
        # cpu, mem
        cfg.vm.provider "virtualbox" do |vb|
            vb.name = "lab1"
        end
    end

    config.vm.define "lab2" do |cfg|
        cfg.vm.box = "bento/centos-8"
        cfg.vm.hostname = "lab2"
        cfg.vm.network "private_network", ip:"192.168.56.102"

        cfg.vm.synced_folder  "/Users/user/vagrant", "/vagrant"

        cfg.vm.provision  "shell", path: "user_ready.sh"
        # cpu, mem
        cfg.vm.provider "virtualbox" do |vb|
            vb.name = "lab2"
        end
    end

    config.vm.define "lab3" do |cfg|
        cfg.vm.box = "bento/centos-8"
        cfg.vm.hostname = "lab3"
        cfg.vm.network "private_network", ip:"192.168.56.103"

        cfg.vm.synced_folder  "/Users/user/vagrant", "/vagrant"

        cfg.vm.provision  "shell", path: "user_ready.sh"
        # cpu, mem
        cfg.vm.provider "virtualbox" do |vb|
            vb.name = "lab3"
        end
    end

    config.vm.define "lab4" do |cfg|
        cfg.vm.box = "bento/centos-8"
        cfg.vm.hostname = "lab4"
        cfg.vm.network "private_network", ip:"192.168.56.104"

        cfg.vm.synced_folder  "/Users/user/vagrant", "/vagrant"

        cfg.vm.provision  "shell", path: "user_ready.sh"
        # cpu, mem
        cfg.vm.provider "virtualbox" do |vb|
            vb.name = "lab4"
        end
    end

    config.vm.define "lab5" do |cfg|
        cfg.vm.box = "bento/centos-8"
        cfg.vm.hostname = "lab5"
        cfg.vm.network "private_network", ip:"192.168.56.105"

        cfg.vm.synced_folder  "/Users/user/vagrant", "/vagrant"

        cfg.vm.provision  "shell", path: "user_ready.sh"
        # cpu, mem
        cfg.vm.provider "virtualbox" do |vb|
            vb.name = "lab5"
        end

    end

 

    config.vm.define "win10" do |cfg|
        config.vm.box = "gusztavvargadr/windows-10"

        cfg.vm.hostname = "win10"

        cfg.vm.network "private_network", ip:"192.168.56.110"

        cfg.vm.synced_folder  "/Users/user/vagrant", "/vagrant"
        # cpu, mem

        cfg.vm.provider "virtualbox" do |vb|
            vb.name = "win10"
        end    

    end
end

--------------------------------------

 

- user_ready.sh 

--------------------------------------

#!/bin/bash

 

# Vagrant 사용자 설정
sudo useradd -d /home/user -s /bin/bash user
sudo mkdir /home/user
sudo chown -R user.user /home/user
sudo echo 'user:pass' | chpasswd
sudo echo "user ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers.d/user
sudo sed -i -e 's/PasswordAuthentication no/PasswordAuthentication yes/g' /etc/ssh/sshd_config
sudo systemctl restart sshd

--------------------------------------

 

- VM 생성

$ vagrant up 

 

- SSH 접속

$ vagrant ssh lab1

 

- 종료

$ vagrant halt lab1

 

- 특정 VM 실행

$ vagrant up lab1

 

Comments