62[CentOS] CentOS6에 KVM설치하기Admin
출처: http://itscblog.tamu.edu/startup-guide-for-kvm-on-centos-6

 주의할 점은 저 같은 경우 브릿지 네트워크를 설정할 때, ifcfg-eth0에 static IP를
설정하려고 하는 실수를 하게되더군요.
 아래의 네트워크 브릿징 설명대로 eth0에는 아이피를 세팅하지 않고 br0
에 호스트
메인 IP를 세팅하여야 합니다.
(/etc/sysconfig/network-scripts/ifcfg-br0)

CentOS7에서는 재부팅 후 ifcfg-eth0(eno?, enp?)과 같은 환경파일이 사라지는
 현상도 발견됨.(아래 답글에서 해결책 확인요망)


출처에 가서 원본을 보기를 바라며 링크가 없어짐을 대비해 아래에 사본을 둡니다.

Installing KVM

If you choose the “Minimal” option during CentOS 6 then this step is necessary. To get the full set of tools there are 4 software groups to install…

  • Virtualization
  • Virtualization Client
  • Virtualization Platform
  • Virtualization Tools

To install run

1
yum groupinstall "Virtualization*"

dejavu-lgc-sans-fonts is necessary or all the fonts in virt-manager will show as squares

1
yum install dejavu-lgc-sans-fonts

Once the install is finished verify that the KVM kernel module is loaded.

1
lsmod | grep kvm

You should see either kvm_intel or kvm_amd depending  on your host’s CPU manufacturer.

At this point I chose to reboot the server. This allows services to be started and udev rules for KVM to be applied. This will also allow dbus to create the machine-id file, otherwise you would see something like the below when running virt-manager

1
2
3
4
5
6
# virt-manager
Xlib:  extension "RANDR" missing  on display "localhost:10.0".
process 1869: D-Bus library appears to be incorrectly set up; failed to read machine uuid: Failed to open "/var/lib/dbus/machine-id": No such file or directory
See the manual page for dbus-uuidgen to correct this issue.
  D-Bus not built with -rdynamic so unable to print a backtrace
Aborted

If you receive that D-Bus error and would prefer not to restart then run this command to generate the necessary machine-id file

1
dbus-uuidgen > /var/lib/dbus/machine-id

Final configuration steps

The server I run KVM  on is headless, but I still like using virt-manager. So we must install the necessary tools to do X11 forwarding through SSH.

1
2
3
4
yum install xorg-x11-xauth

# If you plan to use VNC to connect to the virtual machine's console locally
yum install tigervnc

Now when you connect through SSH be sure to pass the -X flag to enable X11 forwarding.

Optional: Using an alternate location for VM images with SELinux

With SELinux enabled, special steps must be taken to change the default VM store from /var/lib/libvirt/images. My particular server I choose to keep all images and ISOs for VMs under /vmstore. The steps below give your new store the correct security context for SELinux.

1
2
3
4
5
# this package is necessary to run semanage
yum install policycoreutils-python

semanage fcontext -a -t virt_image_t "/vmstore(/.*)?"
restorecon -R /vmstore

To activate this store you must open virt-manager, select your host, then do Edit-> Host Details. Under the Storage tab you can add your new storage volume.

Optional : Network Bridging for Virtual Machines

If you wish for your virtual machines to be accessible remotely then you must use network bridging to share your host’s network interface with the virtual machines. The setup requires linking  one of your host’s physical interfaces with a bridge device. First copy your physical interface’s ifcfg file to create the new bridge device, named br0.

1
cp /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-br0

Modify ifcfg-br0 to have the IP information in ifcfg-eth0 and remove, or comment out, that information in ifcfg-eth0. Below are examples of ifcfg-eth0 and ifcfg-br0. The highlighted lines are important.

/etc/sysconfig/network-scripts/ifcfg-eth0

1
2
3
4
DEVICE=eth0
HWADDR=00:18:8B:58:07:3B
ONBOOT=yes
BRIDGE=br0

/etc/sysconfig/network-scripts/ifcfg-br0

1
2
3
4
5
6
DEVICE=br0
TYPE=Bridge
BOOTPROTO=static
ONBOOT=yes
IPADDR=10.1.0.3
NETMASK=255.255.255.0

Once those two files are configured restart the network service

1
service network restart

Optional: Managing libvirt with standard user account

Beginning in CentOS 6 access to managing libvirt is handled by PolicyKit. It’s always a good practice to do your daily administration tasks as some user besides root, and using PolicyKit you can give access to libvirt functions to a standard account.

First we create the necessary config file to define the access controls. The file must begin with a numeric value and have the .pkla extension.

1
vim /etc/polkit-1/localauthority/50-local.d/50-libvirt-remote-access.pkla

Here’s an example of the file I used to give access to a single user. Be sure to put your desired username in place of username  on the highlighted line.

1
2
3
4
5
6
[libvirt Management Access]
Identity=unix-user:username
Action=org.libvirt.unix.manage
ResultAny=yes
ResultInactive=yes
ResultActive=yes
  • You can optionally replace Identity=unix-user:username with Identity=unix-group:groupname to allow access to a group of users.

Finally restart the libvirtd daemon to apply your changes.

1
/etc/init.d/libvirtd restart

Creating the first virtual machine

You are now ready to create your virtual machines.

Create the virtual disk

With the version of virt-manager shipped with CentOS 6 you cannot create qcow2 images from within the GUI. If you wish to create your new VM with a qcow2 format virtual disk you must do so from the command line, or see the next section for RPMs to upgrade virt-manager.

Update: Through some testing I’ve found that performance can be greatly improved if the preallocation is set when creating a qcow2 image. See my recent post at Improve disk I/O performance in KVM for more information  on improving performance in KVM.

1
2
3
4
5
# With preallocation
qemu-img create -f qcow2 -o preallocation=metadata CentOS-6.0-x86_64-Template.qcow2 20G

# Without preallocation
qemu-img create -f qcow2 CentOS-6.0-x86_64-Template.qcow2 20G
  • NOTE: Replace the filename “CentOS-6.0-x86_64-Template” with your desired name, and also replace “20G” with the desired max size of the virtual disk.

Now when creating your virtual machine select to use an existing virtual disk.

virt-manager-0.8.7

See my blog post virt-manager 0.8.7 for CentOS 6 Updated to get RPMs to upgrade the version of virt-manager that comes with CentOS 6. With this version you can change / specify the virtual disk format from within the GUI.

Re[CentOS] vmware이미지를 QEMU/Xen이미지로 변경Admin
출처: http://unixfoo.blogspot.com/2008/12/vmware-to-xen-conversion.html
        http://www.mytechdocs.com/convert-vmware-vm-to-kvmxenqemu/


기존에 사용하던 vmware이미지를 QEMU/Xen이미지로 변경하는 법

1) Delete any old Snapshots.

2) Halt the vmware VM . Check the format of the vmware vmdk file

# qemu-img info mtdhost-xp.vmdk
image: mtdhost-xp.vmdk
file format: raw
virtual size: 15G
disk size: 15G

3) If the file format is “raw”, we need not convert the image file using qemu-img convert, just rename to .img file. If it is not “raw”, use “qemu-img” to convert the image to raw format. Otherwise skip step 4.

4) How to convert using qemu-img.

# qemu-img convert mtdhost-xp.vmdk -O raw /VM/mtdhost-xp.img

4-2) Hyper-V이미지를 qemu-img로 변경하는 법
# qemu-img convert -f vpc ./ww-dlp.vhd -O raw ./ww-dlp.img

5) Create xen config file in /etc/xen/mtdhost-xp (or use the virt-manager utility and choose the newly converted file as the harddrive image), with the renamed/converted image file as disk.

disk = [ 'file:/VM/mtdhost-xp.img,hda,w' ]

6) Boot up the xen domU guest. It should boot up fine.





Re네트워크 설정 후, network restart할 때 에러가 난다면....Admin
* 브릿지 설정 후 재부팅하면 최초부팅 시에만 되고 네트웤을 재시작하면 Failed to start LSB 또는 master connection not found와 같은 에러가 발생되어 IP가 올라오지 않는 현상이 특정 서버에서 발견되었다.

* 심지어는 ifcfg-eno0(eth0)와 같은 환경파일마저 삭제되어버리고 없어지는 경우도 있는데, 이때는 직접 수작업으로 다시 생성해주고 아래와 같이 처리하자


NetworkManager 데몬이 너무 친절해서 간섭하여 발생되는 에러이므로 내리고 재시작하자.

service NetworkManager stop
service network restart


chkconfig로 아예 부팅시 실행이 안되게 설정해두는 것도 좋다.
 
br0와 eno0(eth0)에 모두 IP가 보이면 잘못된 것임. 차라리 NetworkManager를 삭제하는 것도 좋음


*****************************************************
ipv6를 사용하지 않는데 겹쳐서 인터넷이 안될 수도 있음(이때는 disable시키자)
/etc/sysctl.conf에 아래와같이 기록하자
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1

'sysctl -p'를 실행하여 적용하고 network데몬 리스타트하자
*****************************************************

Re우분투서버에서 kvm설치하기Admin
출처: http://antonio-bonifati.blogspot.kr/2013/04/kvm-tutorial-on-ubuntu-server.html
http://wiki.libvirt.org/page/Networking
Debian/Ubuntu Bridging부문 참조

1. 아래와 같은 명령으로 kvm설치하고 원격관리할 수 있도록 root암호도 걸어주자.

sudo apt-get install qemu-kvm libvirt-bin ubuntu-vm-builder bridge-utils qemu-systemsudo apt-get kvm

만일 서버가 GUI로 되어있다면 virt-manager도 설치하자.
sudo apt-get install virt-manager

sudo adduser root libvirtd
sudo adduser root kvm

sudo passwd root

2.네트워크 설정을 아래샘플 처럼하자.(/etc/network/interfaces)
auto lo
iface lo inet loopback
auto br0
iface br0 inet static
address 192.168.1.1
netmask 255.255.255.0

network 192.168.1.0
broadcast 192.168.1.255

gateway 192.168.1.254
dns-nameservers 168.126.63.1
bridge_ports eth0
bridge_stp  on
bridge_fd 0
bridge_maxwait 0


3. '/etc/sysctl.conf' settings
아래설정을 추가한 후 'sysctl -p /etc/sysctl.conf'를 실행하여 적용하자.

net.bridge.bridge-nf-call-ip6tables = 0 net.bridge.bridge-nf-call-iptables = 0 net.bridge.bridge-nf-call-arptables = 0

4. 네트워크 인터페이스는 브릿지 장치(vnet0(br0))가 보이면 선택하고 장치모델은
hypervisor기본값으로 선택하지만, 만약 보이지 않는다면 아래처럼 세팅하자.
원본장치: 공유장치 이름을 지정
브릿지 이름: br0
장치모델: hypervisor기본값 --혹시 안된다면 virtio로 해보도록.


5. 이미지 스토리지에 권한이 없어서 생성이 불가능하다면 아래처럼 처리하자.
chmod go+rx /var/lib/libvirt/images chmod o-rwx /var/lib/libvirt/images/*

*. 콘솔명령으로 제어하려면 아래와 같이 접속하면 되지만, 어차피 GUI로 봐야하므로
 원격접속하여 편하게 virt-manager로 해결하자.

# virsh --connect qemu:///system


ReCentOS7일 경우...Admin

추천: http://www.charleslabri.com/installing-and-working-with-centos-7-x64-and-kvm/

시간나면 확인: http://www.server-world.info/en/note?os=CentOS_7&p=kvm



요약:
-- KVM 지원되는지 확인(출력값이 아무것도 없으면 지원안함 T_T)
egrep '(vmx|svm)' --color=always /proc/cpuinfo

-- KVM 설치
yum -y install kvm virt-manager libvirt virt-install qemu-kvm xauth dejavu-lgc-sans-fonts virt-viewer
KVM: A full virtualization solution for Linux  on x86 hardware containing virtualization extensions (Intel VT or AMD-V).
Virt-Manager: A desktop user interface for managing virtual machines through libvirt.
Libvirt: A toolkit to interact with the virtualization capabilities of recent versions of Linux.
Virt-Install: A command line tool for creating new KVM container guests using the "libvirt"hypervisor management library.
Qemu-kvm: A Linux kernel module that allows a user space program to utilize the hardware virtualization features of various processors.
Dejavu-lgc-sans-fonts: A font family based  on the Vera Fonts.
virt-viewer: A minimal tool for displaying the graphical console of a virtual machine.

-- NAT기능 사용(필요한 경우만): 하나의 IP를 공유하려면 아래와 같이 포워딩 설정하자
echo "net.ipv4.ip_forward = 1"|sudo tee /etc/sysctl.d/99-ipforward.conf
sudo sysctl -p /etc/sysctl.d/99-ipforward.conf

-- 가상OS에 각각 공인 IP를 부여할 수 있는 브릿지 기능을 사용하기

vi /etc/sysconfig/network-scripts/ifcfg-eth0(장치에 따라 다름)
DEVICE=em1
BOOTPROTO=static
ONBOOT=yes
BRIDGE=br0
TYPE=Ethernet

vi /etc/sysconfig/network-scripts/ifcfg-br0
DEVICE=br0
TYPE=Bridge
BOOTPROTO=static
ONBOOT=yes
IPADDR=xxx.xxx.xxx.xxx
NETMASK=xxx.xxx.xxx.xxx
GATEWAY=xxx.xxx.xxx.xxx
DNS1=xxx.xxx.xxx.xxx


-- 서비스 시작하고 enable시켜두기

systemctl start libvirtd
systemctl enable libvirtd

-- 네트웤재시작해보거나 재부팅해보고 정상으로 kvm올라왔는지 확인해보기
lsmod|grep kvm
ip a show br0 | grep UP
sudo virsh -c qemu:///system list

나머진 클라이언트에서 접속해본다.