목차
로컬 환경에서의 테스트를 위한 가상환경 세팅
회사에서 8vCPU/128GB RAM/2TB SSD 서버를 제공해줘서 가상환경 세팅을 하려고 한다
os는 윈도우가 설치되어있고 크롬 원격 데스크톱과 openssh server 세팅을 끝냈다.
https://yeonwoo97.tistory.com/434
Window Openssh Server Setting
목차 desktop 서버를 받아서 window 11 home 을 설치해서 사용해보려고 한다. 추후 ubuntu 를 멀티부팅으로 설치하려고 함 1. Openssh 선택적 기능 설치 windows 시작버튼 > 앱 및 기능 > 선택적 기능 > 기능추
yeonwoo97.tistory.com
1. 설치
1.1 VirtualBox 설치
https://www.virtualbox.org/wiki/Downloads
Downloads – Oracle VM VirtualBox
Download VirtualBox Here you will find links to VirtualBox binaries and its source code. VirtualBox binaries By downloading, you agree to the terms and conditions of the respective license. If you're looking for the latest VirtualBox 6.1 packages, see Virt
www.virtualbox.org
로컬 환경에 맞게 설치
1.2 Vagrant 설치
https://www.vagrantup.com/downloads
Install | Vagrant | HashiCorp Developer
Explore Vagrant product documentation, tutorials, and examples.
developer.hashicorp.com
로컬 환경에 맞게 설치
2. 가상 머신 실행
vagrant --help
다른 자세한 vagrant 명령어는 링크 참고
https://www.vagrantup.com/docs/cli
Command-Line Interface | Vagrant | HashiCorp Developer
Almost all interaction with Vagrant is done via the command-line interface.
developer.hashicorp.com
2.1 Vargrantfile
vagrant init
위 명령을 실행하면 현재 디렉토리에 Vargrantfile 이 생성됨
# Vargrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.synced_folder ".", "/vagrant-ubuntu"
config.vm.define :ubuntu do |host|
host.vm.box = "bento/ubuntu-22.04"
host.vm.hostname = "ubuntu"
host.vm.network :private_network, ip: "192.168.2.10"
host.vm.disk :disk, size: "20GB", primary: true
host.vm.provision :shell, path: "bootstrap.sh"
# Set system settings
host.vm.provider :virtualbox do |vb|
vb.customize ["modifyvm", :id, "--memory", "8192"]
vb.customize ["modifyvm", :id, "--cpus", "8"]
vb.customize [ "guestproperty", "set", :id, "/VirtualBox/GuestAdd/VBoxService/--timesync-set-threshold", 10000 ]
end
end
end
vagrantfile 예시
config.vm.synced_folder - 호스트 pc의 폴더와 가상 머신 환경에서 /home/vagrant 폴더로 마운트 됨
host.vm.box - 가상머신 환경에서 사용할 기본 이미지
https://app.vagrantup.com/boxes/search
Vagrant Cloud by HashiCorp
Vagrant Cloud by HashiCorp
app.vagrantup.com
위 링크에서 필요한 이미지 검색해서 사용
host.vm.network - 가상머신에서 사용할 private ip 주소 설정
host.vm.disk - 가상머신이 사용할 disk 크기 설정
host.vm.provision - 가상머신이 실행되고 초기 provision 을 하기위한 shell 파일 설정, 사용자 데이터
host.vm.provider - 가상머신의 CPU, Memory 사용량을 할당하며, 호스트 PC 와 가상머신 환경의 시간 동기화를 위해 설정
더 많은 설정:
https://www.vagrantup.com/docs/vagrantfile
Vagrantfile | Vagrant | HashiCorp Developer
The primary function of the Vagrantfile is to describe the type of machine required for a project, and how to configure and provision these machines. Vagrantfiles are called Vagrantfiles because the actual literal filename for the file is "Vagrantfile".
developer.hashicorp.com
bootstrap.sh
# bootstrap.sh
#!/bin/bash
apt-get upgrade -y
apt-get dist-upgrade -y
apt-get update -y
apt update && apt upgrade -y
apt-get install vim -y
2.2 여러 개의 가상 머신 생성
Vargrantfile 은 ruby 언어를 지원함. for 문과 변수를 통해 생성
...
$num_instances = 3
(1..$num_instances).each do |i|
config.vm.define "node#{i}" do |node|
node.vm.box = "centos/7"
node.vm.hostname = "node#{i}"
ip = "192.168.8.#{i+100}"
node.vm.network "private_network", ip: ip
node.vm.provider "virtualbox" do |vb|
vb.memory = "3072"
vb.cpus = 1
vb.name = "node#{i}"
end
node.vm.provision "shell", path: "bootstrap.sh", args: [i, ip]
end
end
...
루비를 잘 몰라서 나중에 뜯어보기로 함
2.3 Vargrant 실행
Vagrantfile, bootstrap.sh 파일을 동일 폴더에 생성 후 vagrant up 실행
vagrant up
vagrant up --help #up 명령에 대한 추가 옵션
3. 접속 및 테스트
3.1 vagrant list
\EFK-stack> vagrant box list
bento/ubuntu-22.04 (virtualbox, 202303.13.0)
3.2 ssh 접속
EFK-stack\vagrant-ubuntu> vagrant ssh ubuntu
Welcome to Ubuntu 22.04.2 LTS (GNU/Linux 5.15.0-67-generic x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
System information as of Mon May 15 03:50:05 AM UTC 2023
System load: 0.44580078125 Processes: 204
Usage of /: 14.3% of 30.34GB Users logged in: 0
Memory usage: 4% IPv4 address for eth0: 10.0.2.15
Swap usage: 0% IPv4 address for eth1: 192.168.2.10
This system is built by the Bento project by Chef Software
More information can be found at https://github.com/chef/bento
Last login: Mon May 15 03:50:05 2023 from 10.0.2.2
vagrant@ubuntu:~$
3.3 local pc 연결 확인
vagrant@ubuntu:~$ pwd
/home/vagrant
vagrant@ubuntu:~$ ping 192.168.31.161
PING 192.168.31.161 (192.168.31.161) 56(84) bytes of data.
64 bytes from 192.168.31.161: icmp_seq=1 ttl=127 time=0.544 ms
64 bytes from 192.168.31.161: icmp_seq=2 ttl=127 time=0.711 ms
64 bytes from 192.168.31.161: icmp_seq=3 ttl=127 time=2.92 ms
^C
--- 192.168.31.161 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2084ms
rtt min/avg/max/mdev = 0.544/1.393/2.924/1.084 ms
vagrant@ubuntu:~$
3.4 가상 머신 환경에 Nginx 서버 설치하기
vagrant@ubuntu:~$ sudo su
root@ubuntu:/home/vagrant# apt-get install nginx
3.5 vagrant 종료 관련 명령어
vagrant suspend
- 현재 실행 상태를 저장하고 종료한다. 다시 vagrant up 하면 10초면 다시 실행 시킬수있다. 디스크와 램을 사용하고 있는 상태로 종료된다.
vagrant halting
- 컴퓨터를 종료하는것과 같다. 디스크에는 남겨두고 램에서는 삭제한다. vagrant up 하면 다시 램에 올리고 실행한다.
vagrant destroy
- 완전히 디스크에서 지워버린다. vagrant up 하면 다시 설치해서 실행하므로 오래걸린다.
4. 참고
https://rangken.github.io/blog/2015/vagrant-1/
Vagrant 1.기본 설정 & 기본 명령어
Vagrant란? configure, reproducible, portable work VirtualBox, VMware, AWS 같은 Vitual machine 이용 Shell Script, Puppet, Chef 같은 자동화 설치툴 사용 설치 brew-cask 로 설치 brew cask install virtualbox vagrant vagrant init : Vagrantfile
rangken.github.io
Virtual Box, Vagrant를 이용한 가상 머신 환경 만들기
제가 대학교 다닐 때 윈도우 환경에 가상화 프로그램 설치 후 리눅스 설치하거나, 멀티 부팅으로 윈도 또는 리눅스 설치해서 개발을 했는데요. 설치도 쉽지 않고, 설치해도 잘 동작을 하지 않아
medium.com
https://developer.hashicorp.com/vagrant
Vagrant | HashiCorp Developer
Explore Vagrant product documentation, tutorials, and examples.
developer.hashicorp.com
'IT etc > 개발 환경' 카테고리의 다른 글
데스크탑 RAM, SSD 업그레이드 (0) | 2023.11.18 |
---|---|
프로젝트 협업 툴 - 노션 (0) | 2023.06.19 |
ubuntu open-ssh 로컬+원격 접속 (0) | 2023.06.13 |
Window Openssh Server Setting (0) | 2023.06.05 |