[root@vagrant ~]# yum -y install qemu libvirt libvirt-devel ruby-devel gcc qemu-kvm libguestfs-tools
[root@vagrant ~]# wget -y [<https://releases.hashicorp.com/vagrant/2.2.16/vagrant_2.2.16_x86_64.rpm>](<https://releases.hashicorp.com/vagrant/2.2.16/vagrant_2.2.16_x86_64.rpm>) [root@vagrant ~]# yum -y install vagrant_2.2.16_x86_64.rpm
[root@vagrant ~]# systemctl restart libvirtd
[root@vagrant ~]# mkdir vagrant
[root@vagrant ~]# cd vagrant/
[root@vagrant vagrant]# mkdir test
Vagrant를 통해 원하는 VM을 띄울 수 있다.
주의할 점은 그 디렉토리(여기서는 test)에 가서 명령어를 실행해야 한다는 것이다.
[root@vagrant vagrant]# cd vagrant -v
-bash: cd: vagrant: No such file or directory
[root@vagrant vagrant]# cd test
[root@vagrant test]# vagrant -v
Vagrant 2.2.16
[root@vagrant test]# vagrant init centos/7
[root@vagrant test]# vagrant init centos/7
==> vagrant: A new version of Vagrant is available: 2.3.4 (installed version: 2.2.16)!
==> 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.
centos7의 box(VM 이미지로 보면 됨)를 다운받는다.
[root@vagrant test]# vi Vagrantfile
# Every Vagrant development environment requires a box. You can search for
# boxes at <https://vagrantcloud.com/search>.
config.vm.box = "centos/7" #이미지 지정
[root@vagrant test]# vagrant plugin install vagrant-libvirt
[root@vagrant test]# vagrant up
근데 여기서 안되는 경우가 많았음
이유는 모르겠고 강사님이 한참 찾으신 후에 다음을 진행했음
[root@vagrant test]# vagrant plugin uninstall vagrant-libvirt
[root@vagrant test]# vagrant plugin install vagrant-libvirt --plugin-version 0.10.8
아까 설치한 거 지우고 재설치
아까 안 된 이유는 plugin 버전이 11.2인가 하여간 안 맞아서 그런 듯
[root@vagrant test]# vagrant up
[root@vagrant test]# vagrant status
[root@vagrant test]# vagrant status
Current machine states:
default running (libvirt)
The Libvirt domain is running. To stop this machine, you can run
`vagrant halt`. To destroy the machine, you can run `vagrant destroy`.
[root@vagrant test]# virsh list
[root@vagrant test]# virsh list
Id Name State
----------------------------------------------------
3 centos1 running
4 centos2 running
5 centos3 running
8 test_default running
[root@vagrant test]# vagrant halt
[root@vagrant test]# vagrant halt
==> default: Attempting graceful shutdown of VM...
중단됨
[root@vagrant test]# virsh list --all
[root@vagrant test]# virsh list --all
Id Name State
----------------------------------------------------
3 centos1 running
4 centos2 running
5 centos3 running
- test_default shut off
[root@vagrant test]# vagrant reload
[root@vagrant test]# vagrant reload
**==> default: Creating shared folders metadata...
==> default: Starting domain.
==> default: Waiting for domain to get an IP address...
==> default: Waiting for machine to boot. This may take a few minutes...**
default: SSH address: 192.168.121.114:22
default: SSH username: vagrant
default: SSH auth method: private key
default: Warning: Host unreachable. Retrying...
default: Warning: Connection refused. Retrying...
**==> default: Machine booted and ready!
==> default: Rsyncing folder: /root/vagrant/test/ => /vagrant
==> default: Machine already provisioned. Run `vagrant provision` or use the `--provision`
==> default: flag to force provisioning. Provisioners marked to run always will still run.**
[root@vagrant test]# vagrant destroy
[root@vagrant test]# vagrant destroy
default: Are you sure you want to destroy the 'default' VM? [y/N] y
==> default: Removing domain...
==> default: Deleting the machine folder
[root@vagrant test]# virsh list --all
[root@vagrant test]# virsh list --all
Id Name State
----------------------------------------------------
3 centos1 running
4 centos2 running
5 centos3 running
[root@vagrant test]# vagrant up
[root@vagrant test]# vagrant ssh
[root@vagrant test]# vagrant ssh
[vagrant@localhost ~]$
[vagrant@localhost ~]$ exit
logout
Connection to 192.168.121.180 closed.
[root@vagrant test]# cat /etc/libvirt/qemu/networks/vagrant-libvirt.xml
[root@vagrant test]# cat /etc/libvirt/qemu/networks/vagrant-libvirt.xml
<!--
WARNING: THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE LIKELY TO BE
OVERWRITTEN AND LOST. Changes to this xml configuration should be made using:
virsh net-edit vagrant-libvirt
or other application using the libvirt API.
-->
<network ipv6='yes'>
<name>vagrant-libvirt</name>
<uuid>c122d54b-7ff8-4fb2-8b61-20629bb850c3</uuid>
<forward mode='nat'/>
<bridge name='virbr1' stp='on' delay='0'/>
<mac address='52:54:00:d8:14:14'/>
<ip address='192.168.121.1' netmask='255.255.255.0'>
<dhcp>
<range start='192.168.121.1' end='192.168.121.254'/>
</dhcp>
</ip>
</network>
브라우저) 211.183.3.50:8000 → Wok 접속
[root@vagrant test]# vagrant destroy
[root@vagrant test]# vagrant destroy
default: Are you sure you want to destroy the 'default' VM? [y/N] y
==> default: Removing domain...
==> default: Deleting the machine folder