Устанавливаем пакеты:
# apt -y install qemu-kvm libvirt-daemon libvirt-daemon-system virtinst bridge-utils
Посмотреть список доменов:
# lsmod | grep vhost
vhost_net 20480 0
# apt -y install qemu-kvm libvirt-daemon libvirt-daemon-system virtinst bridge-utils
Для того, чтобы иметь возможность управлять
виртуальными машинами (ВМ) от обычного пользователя, вы должны добавить
этого пользователя в группы kvm и libvirt:
# adduser <youruser> kvm
# adduser <youruser> libvirt
или
# sudo gpasswd libvirt -a <username>
# sudo gpasswd kvm -a <username>
Посмотреть список доменов:
# virsh list --all
Включить vhost-net.
# modprobe vhost_net
# lsmod | grep vhost
vhost_net 20480 0
tun 28672 1 vhost_net
vhost 45056 1 vhost_net
macvtap 24576 1 vhost_net
# echo vhost_net >> /etc/modules
libvirt defaults to qemu:///session for non-root. So from <youruser> you'll need to do:
# virsh --connect qemu:///system list --all
You can use LIBVIRT_DEFAULT_URI to change this.
Создание гостевой ВМ
Самый простой способ для создания и управления гостевыми ВМ это использовать графическое приложение Virtual Machine Manager virt-manager.
Также,
вы можете создать гостевую ВМ в командной строке. Ниже приведен пример
для создания гостевой ВМ Debian Squeeze с именем squeeze-amd64:
# virt-install --virt-type kvm --name squeeze-amd64 --memory 512 --cdrom ~/iso/Debian/cdimage.debian.org_mirror_cdimage_archive_6.0.10_live_amd64_iso_hybrid_debian_live_6.0.10_amd64_gnome_desktop.iso --disk size=4 --os-variant debiansqueeze
Since the guest has no network connection yet, you will need to use the GUI virt-viewer to complete the install.
You can avoid pulling the ISO by using the --location option. To obtain text console for the installation you can also provide --extra-args "console=ttyS0":
# virt-install --virt-type kvm --name squeeze-amd64 \
--location http://httpredir.debian.org/debian/dists/squeeze/main/installer-amd64/ \
--extra-args "console=ttyS0" -v --os-variant debiansqueeze \
--disk size=4 --memory 512
Managing VMs from the command-line
You can then use the virsh(1) command to start and stop virtual machines. VMs can be generated using virtinst. For more details see the libvirt page. Virtual machines can also be controlled using the kvm command in a similar fashion to QEMU. Below are some frequently used commands:
Start a configured VM guest "VMGUEST":
# virsh start VMGUEST
Notify the VM guest "VMGUEST" to graceful shutdown:
# virsh shutdown VMGUEST
Force the VM guest "VMGUEST" to shutdown in case it is hanged, i.e. graceful shutdown not work:
# virsh destroy VMGUEST
Configure Bridge networking.
# vi /etc/network/interfaces
# This file describes the network interfaces available on your system # and how to activate them. For more information, see interfaces(5). source /etc/network/interfaces.d/* # The loopback network interface auto lo iface lo inet loopback # The primary network interface auto ens33
# change like follows
iface ens3 inet manual
#iface ens3 inet static
#address 10.0.0.30
#network 10.0.0.0
#netmask 255.255.255.0
#broadcast 10.0.0.255
#gateway 10.0.0.1
#dns-nameservers 10.0.0.30
# add bridge interface
iface br0 inet static
address 10.0.0.30 network 10.0.0.0 netmask 255.255.255.0 broadcast 10.0.0.255 gateway 10.0.0.1 dns-nameservers 10.0.0.30 bridge_ports ens3 bridge_stp off auto br0
#reboot
#ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: ens3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master br0 state UP group default qlen 1000 link/ether 52:54:00:99:d3:a8 brd ff:ff:ff:ff:ff:ff 3: br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000 link/ether 52:54:00:99:d3:a8 brd ff:ff:ff:ff:ff:ff inet 10.0.0.30/24 brd 10.0.0.255 scope global br0 valid_lft forever preferred_lft forever inet6 fe80::5054:ff:fe99:d3a8/64 scope link valid_lft forever preferred_lft forever |
Комментариев нет:
Отправить комментарий