728x90
반응형

 

Vagrantfile 설정

 

# -*- mode: ruby -*-
# vi: set ft=ruby :
# Prometheus & Grafana monitoring 

Vagrant.configure("2") do |config|
  config.vm.define "Prometheus_Grafana" do |cfg|
    cfg.vm.box = "alvistack/ubuntu-22.04"
    cfg.vm.provider "virtualbox" do |vb|
      vb.name = "ProGra_SVR(Prometheus_Grafana)"
      vb.cpus = 2
      vb.memory = 2048
      vb.customize ["modifyvm", :id, "--groups", "/ProGra(Prometheus_Grafana)"]
    end
    cfg.vm.host_name = "ProGra-SVR"
    cfg.vm.network "private_network", ip: "192.168.56.125"
    cfg.vm.synced_folder "../data", "/vagrant", disabled: true 
    cfg.vm.provision "shell", path: "config.sh"
  end
end

 

# vagrant 파일 설명

 

 

# -*- mode: ruby -*-
# vi: set ft=ruby :
# Prometheus & Grafana monitoring 

Vagrant.configure("2") do |config|
  config.vm.define "Prometheus_Grafana" do |cfg|    # vagrant global-status 에서 나오는 명칭

<Vagrnat name : Prometheus_Grafana>

 

    cfg.vm.box = "alvistack/ubuntu-22.04"      # vagrant 사이트에 검색해서 설치화려는 Vagrant VM box 설치명

<&nbsp; https://app.vagrantup.com/boxes/search 검색해서 설치하려는 Vagrant 설정 파일 이름 >


    cfg.vm.provider "virtualbox" do |vb|
      vb.name = "ProGra_SVR(Prometheus_Grafana)"      #  Oracle VM에 설치되는 가성 서버 이름

<Oracle VM에 설치되는 가상 서버 이름>

      vb.cpus = 2    # Oralce VM에 설정되는 CPU Core 수

<Oralce VM에 설정되는 CPU 수>

      vb.memory = 2048       # Oralce VM에 설정되는 memory 수(값)

<Oracle VM에 설치되는 메모리 수>

      vb.customize ["modifyvm", :id, "--groups", "/ProGra(Prometheus_Grafana)"]  # Oralce VM에 설정되는 가성 서버 그룹 이름

※ 그룹이름 설정시 앞에 / 표시를 꼭 해야 됨 (안하면 에러남) 

<Oracle VM에 설정되는 가상 서버 그룹 이름>


    end     #    cfg.vm.provider "virtualbox" do |vb|     do|vb|를 닫는다
    cfg.vm.host_name = "ProGra-SVR"  #   가상 서버 호스트 명
  

    cfg.vm.network "private_network", ip: "192.168.56.125"  #   가상 서버 ip

 

    cfg.vm.synced_folder "../data", "/vagrant", disabled: true 

 

    cfg.vm.provision "shell", path: "config.sh" #   가상 서버 설치시 사용되는 추가 파일 

 

  end     #    config.vm.define "Prometheus_Grafana" do |cfg|    do|cfg|를 닫는다

 

end     # Vagrant.configure("2") do |config|    #do |config|를 닫는다

 

 

# config.sh (Vagrant 파일과 같은 폴더에 설치하면 됨)
C:\Users\shim>type config.sh
# config.sh
# 수동 시간 맞추기
ln -sf /usr/share/zoneinfo/Asia/Seoul /etc/localtime

# centOS 8에서 필요한 내용 (YUM 레포사이트 주소변경)
sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*
sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*

# net-tools 설치
yum install net-tools -y

# yum-utils 설치
yum install yum-utils -y 

# dnf 설치
yum install dnf -y 

# docker compose 설치
dnf install python3 python3-pip -y
pip3 install docker-compose

# docker repo
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo


# config DNS  
cat <<EOF > /etc/resolv.conf
nameserver 1.1.1.1 #cloudflare DNS
nameserver 8.8.8.8 #Google DNS
EOF

 

 

# 기타 설명
# https://app.vagrantup.com/boxes/search 기본 설정

Vagrant.configure("2") do |config|
  config.vm.define "ubuntu/trusty64"
  config.vm.box = "ubuntu/trusty64"
end



# config.vm.define 설정을 안해주면 기본적으로 vagrant global-status 했을때 default로 나옴 

C:\Users\shim>vagrant global-status
id       name              provider   state   directory
-----------------------------------------------------------------------------
73ef706  default           virtualbox running C:/Users/shim

73ef706  ubuntu/trusty64   virtualbox running C:/Users/shim

 

# 설치 로그 
C:\Users\shim>vagrant up
Bringing machine 'Prometheus_Grafana' up with 'virtualbox' provider...
==> Prometheus_Grafana: Importing base box 'alvistack/ubuntu-22.04'...
==> Prometheus_Grafana: Matching MAC address for NAT networking...
==> Prometheus_Grafana: Checking if box 'alvistack/ubuntu-22.04' version '20240120.1.1' is up to date...
==> Prometheus_Grafana: A newer version of the box 'alvistack/ubuntu-22.04' for provider 'virtualbox' is
==> Prometheus_Grafana: available! You currently have version '20240120.1.1'. The latest is version
==> Prometheus_Grafana: '20240202.1.1'. Run `vagrant box update` to update.
==> Prometheus_Grafana: Setting the name of the VM: ProGra_SVR(Prometheus_Grafana)
==> Prometheus_Grafana: Clearing any previously set network interfaces...
==> Prometheus_Grafana: Preparing network interfaces based on configuration...
    Prometheus_Grafana: Adapter 1: nat
    Prometheus_Grafana: Adapter 2: hostonly
==> Prometheus_Grafana: Forwarding ports...
    Prometheus_Grafana: 22 (guest) => 2222 (host) (adapter 1)
==> Prometheus_Grafana: Running 'pre-boot' VM customizations...
==> Prometheus_Grafana: Booting VM...
==> Prometheus_Grafana: Waiting for machine to boot. This may take a few minutes...
    Prometheus_Grafana: SSH address: 127.0.0.1:2222
    Prometheus_Grafana: SSH username: vagrant
    Prometheus_Grafana: SSH auth method: private key
    Prometheus_Grafana: Warning: Connection reset. Retrying...
    Prometheus_Grafana: Warning: Connection aborted. Retrying...
    Prometheus_Grafana:
    Prometheus_Grafana: Vagrant insecure key detected. Vagrant will automatically replace
    Prometheus_Grafana: this with a newly generated keypair for better security.
    Prometheus_Grafana:
    Prometheus_Grafana: Inserting generated public key within guest...
    Prometheus_Grafana: Removing insecure key from the guest if it's present...
    Prometheus_Grafana: Key inserted! Disconnecting and reconnecting using new SSH key...
==> Prometheus_Grafana: Machine booted and ready!
==> Prometheus_Grafana: Checking for guest additions in VM...
    Prometheus_Grafana: The guest additions on this VM do not match the installed version of
    Prometheus_Grafana: VirtualBox! In most cases this is fine, but in rare cases it can
    Prometheus_Grafana: prevent things such as shared folders from working properly. If you see
    Prometheus_Grafana: shared folder errors, please make sure the guest additions within the
    Prometheus_Grafana: virtual machine match the version of VirtualBox you have installed on
    Prometheus_Grafana: your host and reload your VM.
    Prometheus_Grafana:
    Prometheus_Grafana: Guest Additions Version: 6.0.0 r127566
    Prometheus_Grafana: VirtualBox Version: 7.0
==> Prometheus_Grafana: Setting hostname...
==> Prometheus_Grafana: Configuring and enabling network interfaces...
==> Prometheus_Grafana: Running provisioner: shell...
    Prometheus_Grafana: Running: C:/Users/shim/AppData/Local/Temp/vagrant-shell20240204-16936-1upqxy3.sh

C:\Users\shim>

 

728x90
반응형
LIST

'vagrant' 카테고리의 다른 글

Vagrant로 가상머신 설치(추가설치) 하기  (1) 2024.01.28
728x90
반응형
Vagrant 라 가상머신 설치할때 여러가지 가상머신을 설치하고 싶은데 방법을 몰라서

예) centos7 가상머신 설치후 centos8 가상머신을 추가 설치할 때

vagrant_2.3.4_windows_i686.exe(Vagrant 설치파일) 삭제, 추가 반복했다.
아래는 가상머신 설치(추가설치) 하는 방법을 설명한다.

 

 

자주 쓰는 명령어

 

명령어 설명
vagrant init 프로비저닝을 위한 기초 파일을 생성
vagrant up Vagrantfile을 읽어 들여 프로비저닝을 진행
vagrant halt 가상머신 종료
vagrant destory 가상머신 삭제
vagrant provision 가상머신 변경된 설정 적
vagrant box list 
vagrant box remove [머신명]
가상머신 원본 이미지 저장 폴더 확인
가상머신 원본 이미지 삭제 

 

홈 디렉토리가  C:\Users\shim 인경우

 

C:\HashiCorp                       # vagrant가 설치되어 있는 폴더

C:\Users\shim\Vagrantfile          # vagrantfile이 저장되는 기본 폴더

C:\Users\shim\.vagrant.d\boxes     # vagrant 원본 이미지가 저장되는 폴더
                                   # vagrant init up 이후 원본 이미지가 저장되는 폴더

C:\Users\shim\VirtualBox VMs       # vagrant 가상머신이 저장되는 폴더

 

- C:\HashiCorp 


C:\Users\shim\Vagrantfile         

 


C:\Users\shim\.vagrant.d\boxes     
 

                          

C:\Users\shim\VirtualBox VMs

 

 

 

 

가상이미지를 다운받아서 설치하기 

 

o 설치하고 싶은 vagrant 파일을 찾아서 C:\Users\shim\Vagrantfile 을 수정한다.

https://app.vagrantup.com/

# C:\Users\shim\Vagrantfile file (centos/7) 수정

Vagrant.configure("2") do |config|
  config.vm.box = "centos/7"
end

 

 

#  가상머신(centos/7)을 설치한다

C:\Users\shim>vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Checking if box 'centos/7' version '2004.01' is up to date...
==> default: Clearing any previously set forwarded ports...
==> 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)
C:\Users\shim>==> default: Waiting for cleanup before exiting...
==> default: Booting VM...
https://app.vagrantup.com/==> 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

 

 

# 다른 가상이미지를 추가 설치하고 싶은 경우 C:\Users\shim\Vagrantfile 파일 삭제후 vagrant init 실행

   가끔 Vagrant init 파일이 안먹히는 경우가 있음

# C:\Users\shim\Vagrantfile 파일이 있으면 안먹힘

C:\Users\shim>vagrant init
`Vagrantfile` already exists in this directory. Remove it before
running `vagrant init`.

# C:\Users\shim\Vagrantfile 파일삭제후 다시 vagrant init 실행

C:\Users\shim>vagrant init
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.

 

 

#  다시 C:\Users\shim\Vagrantfile file (rockylinux/9) 수정

Vagrant.configure("2") do |config|
 config.vm.box = "rockylinux/9"
end

 

 

가상머신(rockylinux/9) 설치한다

C:\Users\shim>vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Box 'rockylinux/9' could not be found. Attempting to find and install...
    default: Box Provider: virtualbox
    default: Box Version: >= 0
==> default: Loading metadata for box 'rockylinux/9'
    default: URL: https://vagrantcloud.com/rockylinux/9
==> default: Adding box 'rockylinux/9' (v3.0.0) for provider: virtualbox
    default: Downloading: https://vagrantcloud.com/rockylinux/boxes/9/versions/3.0.0/providers/virtualbox/unknown/vagrant.box
Download redirected to host: dl.rockylinux.org
    default:
    default: Calculating and comparing box checksum...
==> default: Successfully added box 'rockylinux/9' (v3.0.0) for 'virtualbox'!
==> default: Importing base box 'rockylinux/9'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'rockylinux/9' version '3.0.0' is up to date...
==> default: Setting the name of the VM: shim_default_1706426848952_97525
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...

 

 

 

# vagrant box  list 관리 및 삭제

 

C:\Users\shim\.vagrant.d\boxes>vagrant box list
alvistack/ubuntu-22.04 (virtualbox, 20240120.1.1)
centos/7               (virtualbox, 2004.01)
rockylinux/9           (virtualbox, 3.0.0)

C:\Users\shim\.vagrant.d\boxes>vagrant box remove centos/7
Removing box 'centos/7' (v2004.01) with provider 'virtualbox'...

C:\Users\shim\.vagrant.d\boxes>vagrant box remove rockylinux/9
Removing box 'rockylinux/9' (v3.0.0) with provider 'virtualbox'...

C:\Users\shim\.vagrant.d\boxes>vagrant box list
alvistack/ubuntu-22.04 (virtualbox, 20240120.1.1)

 

 

 

 

 

 

728x90
반응형
LIST

'vagrant' 카테고리의 다른 글

Vagrant(베이그런트) Vagrantfile 설정  (0) 2024.02.01

+ Recent posts