Install KVM on Ubuntu and build a virtual environment

Source: Internet
Author: User
Tags error code vps virtual environment xming
Original: http://blog.fens.me/vps-kvm/ 1. Environmental Preparedness

1) Two computers, one is Operation computer client, one is server

Client: Notebook PC, Win7 flagship, 64-bit, intranet ip:192.168.1.101

Server (Host): Servers, Ubuntu 12.04LTS 64-bit, 2-core cpu,4g memory, intranet ip:192.168.1.10,

2) on server startup, enter BIOS support for CPU virtualization

into the BIOS, in the config–> CPU option, Intel (R) virtualization technology (enabled) Intel (r) vt-d Feature (enabled)

Different BIOS menus are slightly different.

3) on the server, first install openssh-server,client to connect

~ sudo apt-get Install Openssh-server

Clinet connects to the server via Putty home.

Note: All of the following operations are done via SSH.

4) Server System environment

~ uname-a
Linux Conan 3.5.0-23-generic #35 ~precise1-ubuntu SMP Fri Jan 17:13:26 UTC x86_64 x86_64 x86_64 gnu/linux
~ cat/etc/issue
Ubuntu 12.04.2 LTS \ \l

5) View virtualization support for CPUs

~ egrep ' SVM|VMX '/proc/cpuinfo
FLAGS:FPU VME de PSE TSC MSR PAE MCE cx8 APIC Sep MTRR PGE MCA cmov Pat PSE36 clflush DTS ACPI MMX FXSR SSE SSE2 SS HT t M PBE syscall nx lm constant_tsc Arch_perfmon pebs BTS nopl aperfmperf pni dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx1 6 XTPR pdcm sse4_1 xsave lahf_lm ida dtherm Tpr_shadow Vnmi flexpriority
FLAGS:FPU VME de PSE TSC MSR PAE MCE cx8 APIC Sep MTRR PGE MCA cmov Pat PSE36 clflush DTS ACPI MMX FXSR SSE SSE2 SS HT t M PBE syscall nx lm constant_tsc Arch_perfmon pebs BTS nopl aperfmperf pni dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx1 6 XTPR pdcm sse4_1 xsave lahf_lm ida dtherm Tpr_shadow Vnmi flexpriority

My machine is Intel's CPU and can see the identity of the VMX

6) on the server, configure the Ubuntu download source sources.list, I use the Sohu source.

~ sudo vi/etc/apt/sources.list
Deb Http://mirrors.sohu.com/ubuntu/precise main restricted
DEB-SRC http://mirrors.sohu.com/ubuntu/precise Main restricted
Deb Http://mirrors.sohu.com/ubuntu/precise-updates main restricted
DEB-SRC http://mirrors.sohu.com/ubuntu/precise-updates Main restricted
Deb Http://mirrors.sohu.com/ubuntu/precise Universe
DEB-SRC Http://mirrors.sohu.com/ubuntu/precise Universe
Deb Http://mirrors.sohu.com/ubuntu/precise-updates Universe
DEB-SRC Http://mirrors.sohu.com/ubuntu/precise-updates Universe
Deb Http://mirrors.sohu.com/ubuntu/precise Multiverse
DEB-SRC Http://mirrors.sohu.com/ubuntu/precise Multiverse
Deb Http://mirrors.sohu.com/ubuntu/precise-updates Multiverse
DEB-SRC Http://mirrors.sohu.com/ubuntu/precise-updates Multiverse
Deb Http://mirrors.sohu.com/ubuntu/precise-backports main restricted universe multiverse
DEB-SRC http://mirrors.sohu.com/ubuntu/precise-backports main restricted universe multiverse
Deb Http://mirrors.sohu.com/ubuntu/precise-security main restricted
DEB-SRC http://mirrors.sohu.com/ubuntu/precise-security Main restricted
Deb Http://mirrors.sohu.com/ubuntu/precise-security Universe
DEB-SRC Http://mirrors.sohu.com/ubuntu/precise-security Universe
Deb Http://mirrors.sohu.com/ubuntu/precise-security Multiverse
DEB-SRC http://mirrors.sohu.com/ubuntu/precise-security Multiverse
Deb Http://extras.ubuntu.com/ubuntu Precise Main
Deb-src Http://extras.ubuntu.com/ubuntu Precise Main

#更新源
~ sudo apt-get update

2. Installing the KVM Software

1) on the server, install the KVM and virt management software

~ sudo apt-get install KVM QEMU
~ sudo apt-get install virtinst python-libvirt virt-viewer Virt-manager

It's really easy to install on Ubuntu.

3. Configure the bridge adapter

1) Here we use the NIC bridging method

~ sudo apt-get Install bridge-utils

2) View the settings for the network card

~ ifconfig
eth0 Link encap:ethernet HWaddr 00:1c:25:a1:99:fc
inet addr : 192.168.1.10 bcast:192.168.1.255 mask:255.255.255.0
Inet6 addr:fe80::21c:25ff:fea1:99fc/64 scope:link
Up Broadcast RUNNING multicast mtu:1500 metric:1
RX packets:736674 errors:0 dropped:0 overruns:0 frame:0
TX packets:1 098750 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:63783787 (63.7 MB) TX bytes:1 540374899 (1.5 GB)
Interrupt:20 memory:fc200000-fc220000

Lo Link encap:local Loopback
inet addr:127.0.0.1 mask:255.0.0.0
Inet6 addr::: 1/128 scope:host
Up LOOPBACK RUNNING mtu:16436 metric:1
RX packets:1156 errors:0 dropped:0 overruns:0 frame:0
TX packets:1156 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:114090 (114.0 KB) TX bytes:114090 (114.0 KB)

Virbr0 Link encap:ethernet HWaddr be:65:ec:88:86:3d
inet addr:192.168.122.1 bcast:192.168.122.255 mask:255.255.255.0
Up broadcast multicast mtu:1500 metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)

3) the existing network card eth0 is directly plugged into the Ethernet network cable, Lo is the LAN, local internal resources virbr0 is just after we loaded KVM, the virtual network card generated by ourselves

4) NIC Bridging
We add a virtual network card called Br0, so that the network card can be bridged with the Eth0 Ethernet network card

~ sudo vi/etc/network/interfaces
Auto Lo
Iface Lo inet Loopback
Auto Eth0
Iface eth0 inet Manual
Auto Br0
Iface br0 inet Static
Address 192.168.1.10
Netmask 255.255.255.0
Gateway 192.168.1.1
Bridge_ports eth0

Save, restart network card settings

~ sudo/etc/init.d/networking Restart

Check the network card settings again

~ ifconfig
Br0 Link encap:ethernet HWaddr 00:1C:25:A1:99:FC
inet addr:192.168.1.10 bcast:192.168.1.255 mask:255.255.255.0
Inet6 ADDR:FE80::21C:25FF:FEA1:99FC/64 Scope:link
Up broadcast RUNNING multicast mtu:1500 metric:1
RX packets:91 errors:0 dropped:0 overruns:0 frame:0
TX packets:100 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:6260 (6.2 kb) TX bytes:15470 (15.4 KB)

Eth0 Link encap:ethernet HWaddr 00:1C:25:A1:99:FC
Up broadcast RUNNING multicast mtu:1500 metric:1
RX packets:605 errors:0 dropped:0 overruns:0 frame:0
TX packets:425 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:112441 (112.4 kb) TX bytes:61529 (61.5 KB)
Interrupt:20 memory:fc200000-fc220000

Lo Link encap:local Loopback
inet addr:127.0.0.1 mask:255.0.0.0
Inet6 addr::: 1/128 scope:host
Up LOOPBACK RUNNING mtu:16436 metric:1
RX packets:36 errors:0 dropped:0 overruns:0 frame:0
TX packets:36 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:2100 (2.1 kb) TX bytes:2100 (2.1 KB)

Virbr0 Link encap:ethernet HWaddr 2a:b8:36:cf:cc:c6
inet addr:192.168.122.1 bcast:192.168.122.255 mask:255.255.255.0
Up broadcast multicast mtu:1500 metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)

This time eth0, there is no specific IP address. The IP address is on the BR0 virtual network.

Let's ping the public IP to see if it's a pass.

~ Ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8) bytes of data.
Bytes from 8.8.8.8:icmp_req=1 ttl=46 time=51.7 ms
Bytes from 8.8.8.8:icmp_req=2 ttl=46 time=50.8 ms
4. Create a virtual machine

Create a virtual machine (Guest) by virt the virtual machine management software.

Upload 2 installation images to Server:u1204.iso, Xp.iso

Placed under the/home/conan/os directory.

1) Create GUEST1, Ubuntu 64-bit LTS 12.04 version (command line, no visual interface)

Mount the U1204.iso file in a directory

~ sudo mount-o loop/home/conan/os/u1204.iso/home/conan/os/ubuntu
~ Ls/home/conan/os/ubuntu
Boot dists EFI isolinux pics preseed Ubuntu
Cdromupgrade doc install Md5sum.txt pool Readme.diskdefines

Create a virtual machine

~ sudo virt-install--connect=qemu:///system \
--name G1 \
--ram 2048 \
--vcpus=2 \
--os-type=linux \
--os-variant=ubuntuprecise \
--accelerate \
--HVM \
--disk path=/home/conan/os/g1.img,size=6,bus=virtio \
--location/home/conan/os/ubuntu \
--extra-args= ' console=tty0 console=ttys0 ' \
--network bridge=br0,model=virtio \
--graphics None

Enter the Installation interface

Lqqqqqqqqqqqqqqqqqqqqqqqu [!] Select a language Tqqqqqqqqqqqqqqqqqqqqqqqqk
x x
x Choose the language to is used for the installation process. The X
X selected language would also be the default language for the installed X
X System. X
x x
X language:x
x x
X C x
X 中文版 x
x x
x <go back> X
x x
Mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj
<Tab> moves; <Space> selects; <Enter> activates buttons

Installation system

Lqqqqqqqqqqqqqqqqqqqqqu [!] Configure the network Tqqqqqqqqqqqqqqqqqqqqqk
x x
x Please enter the hostname for this system. X
x x
X the hostname is a single word this identifies your system to the X
x network. If you don ' t know what your hostname should be, consult your X
x network administrator. If you is setting up your own home network, X
X can make something up here. X
x x
X hostname:x
x x
X localhost____________________________________________________________ x
x x
X <go back> <Continue> x
x x
Mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj
<Tab> moves; <Space> selects; <Enter> activates buttons

Installation Complete

2). Create GUEST2, Ubuntu 64-bit LTS 12.04 version (via VNC, with visual interface)

On the server side, I want to open port support for Vnc_listen

~ vi/etc/libvirt/qemu.conf
#打开注释
Vnc_listen= "0.0.0.0"

Restart Virt software

~ Sudo/etc/init.d/libvirt-bin Restart
~ Netstat-nlt|grep 5900
TCP 0 0 0.0.0.0:5900 0.0.0.0:* LISTEN

We need to use the xming and putty mates to let putty remotely transmit the VNC signal through the xming display.

In putty, we need to modify the configuration.

Start xming Software

Execute command

~ sudo virt-install--connect=qemu:///system \
--name G2 \
--ram 2048 \
--vcpus=2 \
--os-type=linux \
--os-variant=ubuntuprecise \
--accelerate \
--HVM \
--disk path=/home/conan/os/g2.img,size=6,bus=virtio \
--cdrom/home/conan/os/u1204.iso \
--network bridge=br0,model=virtio \
--graphics VNC



Xming shows the VNC interface, Ubuntu installation screen

Installation Complete

3. Create Guest3, Winxp (via VNC, with visual interface)

Note 1: WinXP must be installed here, Ghost is not.

Note 2:windows installation, you must use the VNC interface mode, no command direct installation method

Execute command

sudo virt-install--connect=qemu:///system \
--name g3 \
--ram 1024 \
--vcpus=1 \
--os-type=windows \
--OS-VARIANT=WINXP \
--accelerate \
--HVM \
--disk path=/home/conan/os/g3.img,size=4 \
--cdrom/home/conan/os/xp.iso \
--network BRIDGE=BR0,MODEL=NE2K_PCI \
--graphics VNC



xming display of VNC interface, WinXP installation screen

Installation complete virtual machines communicate with each other

We launch Guest1 (Ubuntu), Guest3 (WinXP). client:ip:192.168.1.101 server:ip:192.168.1.10 guest1:ip:192.168.1.11 guest3:ip:192.168.1.12

They are all in the same network segment, can ping each other, can also call each other.

If you experiment with the same results as me, congratulations, you've achieved the process of building your own VPS via KVM.

Error Resolution

1. Error code:

Libvirterror:internal error Process exited while reading console log Output:char device redirected TO/DEV/PTS/4
Could not access KVM kernel module:permission denied
Failed to initialize Kvm:permission denied
No Accelerator found!

Workaround:

~ sudo rmmod Kvm_intel
~ sudo modprobe-r Kvm_intel
~ sudo modprobe kvm_intel nested=1

http://blog.fens.me/vps-kvm/http://blog.fens.me/vps-kvm/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.