1원팁: Vagrant와 VirtualBox 호환 버전 - 2018.05.02기준 > 개발자팁

개발자팁

개발과 관련된 유용한 정보를 공유하세요.
질문은 QA에서 해주시기 바랍니다.

1원팁: Vagrant와 VirtualBox 호환 버전 - 2018.05.02기준 정보

OS 1원팁: Vagrant와 VirtualBox 호환 버전 - 2018.05.02기준

본문

Virtual Box 5.2 로 업데이트 이후 Vagrant 2.0.3이상 동작합니다. 

 

버추어박스 5.1.x에서 5.2로 업그레이드한 후 Vagrant 2.0 이 동작하지 않더군요. 

두 개 버전을 최신으로 바꿔주니 제대로 동작합니다. 

 

* ip 지정, 포트포워딩 없이 putty접속, 고정ip로 웹브라우저접속, FTP접속등... 을 위해 삽질을 많이 했는데, 드디어 성공했습니다. 나중에 동영상으로라도 올려드리고 싶지만 능력이 안되어... 그냥 개인 위키에 남긴 글을 조금 정리해서 남겨봅니다. 

참고로 버처박스만 사용해왔던, 부족한 vagrant 초보입니다. Docker도 아직 경험이 없지만, 곧 또 연구해볼 생각이네요. 

 

 

 

 

 

================= 아래는 그냥 참고를 위해 주저리 주저리 ====================

(담에 조금더  정리를 해서 올려볼께요. 미루다가 놓칠 수 있어서, 안남기려다 러프하게나마 일단 남겨봅니다. 반말체라 양해를 구합니다.)

 

 

부제: Vagrant로 시작한 가상머신(Box)에 IP공유기에서 부여한 IP로 putty SSH로 접속하기, 브라우저에서 바로 붙어서 개발하기 (아직 프로비저닝까지는 못가고 있는... )

 
 

도움입은 링크 - 일부

 

중요!

 

베이그런트 설치는 마친 상태에서 Vagrant 파일을 수정해야 함

중요한 부분이, PC의 랜카드 이름을 넣어주어야한다. bridge로 이어주는 부분의 코드가 중요!

 

공유기의 아이피가 192.168.30.1 인데

베이그런트로 만든 가상서버(박스)의 IP를 192.168.30.120 로 주고 싶었고,

현재 Vagrant가 깔린 윈도우10 PC의 IP는 192.168.30.14 임

 

현재, 윈도우 10이 깔린 PC의 실제 랜카드 이름이 Realtek PCIe GBE Family Controller

(윈도우10에서 지정해준 이름 / 아래 이미지에서 붉은 색부분 full text)

 

1981879674_1525206069.8707.png

 

 

Vagrant 파일의 중간에 아래의 코드를 넣어준 것 밖에는 없음.

config.vm.network "public_network", ip: "192.168.30.120", bridge: "Realtek PCIe GBE Family Controller"

 

Vagrant 설정파일 전체부분 (중간즈음에 위 코드가 들어감, 빨간색 코드)

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

# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure("2") do |config|
  # The most common configuration options are documented and commented below.
  # For a complete reference, please see the online documentation at
  # https://docs.vagrantup.com.

  # Every Vagrant development environment requires a box. You can search for
  # boxes at https://vagrantcloud.com/search.
  config.vm.box = "bento/centos-7.4"

  # Disable automatic box update checking. If you disable this, then
  # boxes will only be checked for updates when the user runs
  # `vagrant box outdated`. This is not recommended.
  # config.vm.box_check_update = false

  # Create a forwarded port mapping which allows access to a specific port
  # within the machine from a port on the host machine. In the example below,
  # accessing "localhost:8080" will access port 80 on the guest machine.
  # NOTE: This will enable public access to the opened port
  # config.vm.network "forwarded_port", guest: 80, host: 8080


  # Create a forwarded port mapping which allows access to a specific port
  # within the machine from a port on the host machine and only allow access
  # via 127.0.0.1 to disable public access
  # config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1"

  # Create a private network, which allows host-only access to the machine
  # using a specific IP.
  # config.vm.network "private_network", ip: "192.168.33.80"
   

  # Create a public network, which generally matched to bridged network.
  # Bridged networks make the machine appear as another physical device on
  # your network.
  # config.vm.network "public_network"

    config.vm.network "public_network", ip: "192.168.30.120", bridge: "Realtek PCIe GBE Family Controller"

  # Share an additional folder to the guest VM. The first argument is
  # the path on the host to the actual folder. The second argument is
  # the path on the guest to mount the folder. And the optional third
  # argument is a set of non-required options.
  # config.vm.synced_folder "../data", "/vagrant_data"

  # Provider-specific configuration so you can fine-tune various
  # backing providers for Vagrant. These expose provider-specific options.
  # Example for VirtualBox:
  #
  # config.vm.provider "virtualbox" do |vb|
  #   # Display the VirtualBox GUI when booting the machine
  #   vb.gui = true
  #
  #   # Customize the amount of memory on the VM:
  #   vb.memory = "1024"
  # end
  #
  # View the documentation for the provider you are using for more
  # information on available options.

  # Enable provisioning with a shell script. Additional provisioners such as
  # Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the
  # documentation for more information about their specific syntax and use.
  # config.vm.provision "shell", inline: <<-SHELL
  #   apt-get update
  #   apt-get install -y apache2
  # SHELL
end


 

이렇게 작업했을 때,제대로 시동이 됨 (아래는 시동 로그)

 

S:\vagrant\centos72>vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Box 'bento/centos-7.4' could not be found. Attempting to find and install...
    default: Box Provider: virtualbox
    default: Box Version: >= 0
==> default: Loading metadata for box 'bento/centos-7.4'
    default: URL: https://vagrantcloud.com/bento/centos-7.4
==> default: Adding box 'bento/centos-7.4' (v201803.24.0) for provider: virtualbox
    default: Downloading: https://vagrantcloud.com/bento/boxes/centos-7.4/versions/201803.24.0/providers/virtualbox.box
    default:
==> default: Successfully added box 'bento/centos-7.4' (v201803.24.0) for 'virtualbox'!
==> default: Importing base box 'bento/centos-7.4'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'bento/centos-7.4' is up to date...
==> default: Setting the name of the VM: centos72_default_1525199404953_16447
==> default: Fixed port collision for 22 => 2222. Now on port 2200.
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
==> default: Forwarding ports...
    default: 22 (guest) => 2200 (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:2200
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: Warning: Connection reset. Retrying...
    default: Warning: Connection aborted. Retrying...
    default: Warning: Connection reset. Retrying...
    default: Warning: Connection aborted. Retrying...
    default: Warning: Connection reset. Retrying...
    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: Mounting shared folders...
    default: /vagrant => S:/vagrant/centos72

 

그리고 이제 실제 putty에서 접속이 됨.  address에 ip를 넣되,

아래의 명령어로 만들어진 키(빨간색 부분 경로)를 

* 명령어: vagrant ssh-config 

(IdentityFile 만들고 경로 확인해주는 명령 -> 이걸로 나중에 puttygen에서 private key를 만들어야 함)

 

S:\vagrant\centos72>vagrant ssh-config
Host default
  HostName 127.0.0.1
  User vagrant
  Port 2222
  UserKnownHostsFile /dev/null
  StrictHostKeyChecking no
  PasswordAuthentication no
  IdentityFile S:/vagrant/centos72/.vagrant/machines/default/virtualbox/private_key
  IdentitiesOnly yes
  LogLevel FATAL


puttygen 을 실행해서 위의 키를 load한후에 private key로 저장하면 ppk 파일이 만들어지는데, 이걸로 putty에서 접속해야함. 

방법 관련 링크 (나중에 다시 추가할 예정)  putty에서 접속할 때 옵션에서 auto login 에 vagrant 를 ssh -> key 에 아까 만든 key를 넣고 

save한 후에 그걸로 로그인하면 passthrough를 물어보는데 아까 키생성할 때 넣은 것을 넣으면 로그인 됨.. passthrough를 넣지 않고 키를 만든경우에는 그냥 로그인이 됨

(키를 만들 때 보안을 위해 passthrough 를 넣어야… 나는 쉽게 기억하기위해 짧은 단어 ***로 넣음.)

 

장점 (이걸 위해서... ㅜㅜ; 이런 수고를... )

여튼, 이렇게 하면 장점이 바로 위에서 부여한 아이피로 접속가능해서 포트포워딩을 하지 않아서 좋고,

웹도 마찬가지…  :8800 등의 아이피를 붙여서 개발하지 않아도 되고, 여러대의 vagrant 박스를 만들고, 여러 putty를 동시에 띄워작업도 가능함. 

FTP등 각각 박스마다 고유아이피(내부) 부여 가능... 

(VirtualBox로 Box 복제기능을 이용해서 해도 되기는 하지만, Vagrant 로도 해볼 필요가 있었다고 사료되어)

 

ifconfig 결과

(빨간색 부분 제대로 아이피가 지정이되고 박스에서 피씨로, 피씨에서 박스로 접속이 다 됨)

[root@localhost ~]# ifconfig -a
enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.0.2.15  netmask 255.255.255.0  broadcast 10.0.2.255
        inet6 fe80::b190:c275:9386:917b  prefixlen 64  scopeid 0x20<link>
        ether 08:00:27:11:ad:d2  txqueuelen 1000  (Ethernet)
        RX packets 1132  bytes 113647 (110.9 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 917  bytes 103822 (101.3 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

enp0s8: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.30.120  netmask 255.255.255.0  broadcast 192.168.30.255
        inet6 fe80::a00:27ff:fe56:b77d  prefixlen 64  scopeid 0x20<link>
        ether 08:00:27:56:b7:7d  txqueuelen 1000  (Ethernet)
        RX packets 227  bytes 22807 (22.2 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 150  bytes 22759 (22.2 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1  (Local Loopback)
        RX packets 76  bytes 6552 (6.3 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 76  bytes 6552 (6.3 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

 

추천
1

댓글 0개

전체 8
개발자팁 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT