0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
$ modprobe kvm $ lsmod | grep kvm kvm 578518 0 irqbypass 13503 1 kvm $ yum install qemu-kvm libvirt virt-install -y # $ qemu-img create -f raw /opt/CentOS-6.4-x86_64.raw 10G $ systemctl start libvirtd #桥接网卡,启动libvirtd、dnsmasq服务 $ virt-install --virt-type kvm --name Centos-6.4-x86_model --ram 512 --cdrom=/opt/CentOS-6.4-x86_64-minimal.iso --disk path=/opt/CentOS-6.4-x86_64.raw --network network=default --graphics vnc,listen=0.0.0.0 --noautoconsole --os-type=linux --os-variant=rhel6 $ cat route.sh #!/bin/bash brctl addbr br0 brctl addif br0 ens33 ip addr del dev ens33 10.4.0.21/8 ifconfig br0 10.4.0.21/8 up route add default gw 10.0.0.2 $ ll /etc/libvirt/qemu/Centos-6.4-x86_model.xml #相关的kvm配置 $ virsh edit Centos-6.4-x86_model 将<interface type='network'>修改为<interface type='bridge'> 将<source network='default'/>修改为<source bridge='br0'/> $ virsh list --all $ virsh start Centos-6.4-x86_model $ yum install acpid -y # $ virsh qemu-monitor-command Centos-6.4-x86_model --hmp --cmd info balloon balloon: actual=512 $ virsh qemu-monitor-command Centos-6.4-x86_model --hmp --cmd balloon 384 |
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
[root@openstack02 ~]# egrep '(vmx|svm)' /proc/cpuinfo [root@kvm ~]# yum install epel-release -y [root@kvm ~]# cp /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo.bk sed -i "s#\#baseurl#baseurl#g" /etc/yum.repos.d/epel.repo sed -i "s#mirrorlist#\#mirrorlist#" /etc/yum.repos.d/epel.repo [root@kvm ~]# sed -i "s#\#baseurl#baseurl#g" /etc/yum.repos.d/epel.repo [root@kvm ~]# sed -i "s#mirrorlist#\#mirrorlist#" /etc/yum.repos.d/epel.repo [root@kvm ~]# yum install qemu-kvm qemu-kvm-tools virt-manager libvirt [root@kvm01 ~]# ifconfig | grep 192 inet addr:192.168.122.1 Bcast:192.168.122.255 Mask:255.255.255.0 [root@kvm01 ~]# brctl show bridge name bridge id STP enabled interfaces virbr0 8000.52540088e051 yes virbr0-nic [root@kvm01 ~]# qemu-img create -f raw /opt/CentOS-6.4-x86_64.raw Image creation needs a size parameter [root@kvm01 ~]# qemu-img create -f raw /opt/CentOS-6.4-x86_64.raw 5G Formatting '/opt/CentOS-6.4-x86_64.raw', fmt=raw size=5368709120 [root@kvm01 opt]# virt-install --virt-type kvm --name Centos-6.4-x86 --ram 512 --cdrom=/opt/CentOS-6.4-x86_64-minimal.iso --disk path=/opt/CentOS-6.4-x86_64.raw --network network=default --graphics vnc,listen=0.0.0.0 --noautoconsole --os-type=linux --os-variant=rhel6 [root@kvm01 opt]# netstat -tunlp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:5900 0.0.0.0:* LISTEN 1819/qemu-kvm [root@kvm01 opt]# ps aux | grep kvm root 828 0.0 0.0 0 0 ? S 18:04 0:00 [kvm-irqfd-clean] qemu 1819 7.3 2.9 879528 29336 ? Sl 18:07 0:05 /usr/libexec/qemu-kvm -name Centos-6.4-x86 -S -M rhel6.6.0 -enable-kvm -m 512 -realtime mlock=off -smp 1,sockets=1,cores=1,threads=1 -uuid 6a72c200-ef98-7905-20fa-00040e293bf9 -nodefconfig -nodefaults -chardev socket,id=charmonitor,path=/var/lib/libvirt/qemu/Centos-6.4-x86.monitor,server,nowait -mon chardev=charmonitor,id=monitor,mode=control -rtc base=utc -no-reboot -no-shutdown -device ich9-usb-ehci1,id=usb,bus=pci.0,addr=0x4.0x7 -device ich9-usb-uhci1,masterbus=usb.0,firstport=0,bus=pci.0,multifunction=on,addr=0x4 -device ich9-usb-uhci2,masterbus=usb.0,firstport=2,bus=pci.0,addr=0x4.0x1 -device ich9-usb-uhci3,masterbus=usb.0,firstport=4,bus=pci.0,addr=0x4.0x2 -drive file=/opt/CentOS-6.4-x86_64.raw,if=none,id=drive-virtio-disk0,format=raw,cache=none -device virtio-blk-pci,scsi=off,bus=pci.0,addr=0x5,drive=drive-virtio-disk0,id=virtio-disk0,bootindex=2 -drive file=/opt/CentOS-6.4-x86_64-minimal.iso,if=none,media=cdrom,id=drive-ide0-1-0,readonly=on,format=raw -device ide-drive,bus=ide.1,unit=0,drive=drive-ide0-1-0,id=ide0-1-0,bootindex=1 -netdev tap,fd=22,id=hostnet0,vhost=on,vhostfd=23 -device virtio-net-pci,netdev=hostnet0,id=net0,mac=52:54:00:6c:4e:da,bus=pci.0,addr=0x3 -chardev pty,id=charserial0 -device isa-serial,chardev=charserial0,id=serial0 -device usb-tablet,id=input0 -vnc 0.0.0.0:0 -vga cirrus -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x6 -msg timestamp=on [root@kvm01 opt]# virsh list --all Id Name State ---------------------------------------------------- - Centos-6.4-x86 shut off [root@kvm01 opt]# virsh start Centos-6.4-x86 Domain Centos-6.4-x86 started [root@kvm01 qemu]# yum install virt-top [root@kvm01 ~]# brctl addbr br0 [root@kvm01 ~]# brctl show bridge name bridge id STP enabled interfaces br0 8000.000000000000 no virbr0 8000.52540088e051 yes virbr0-nic [root@kvm01 ~]# >/etc/udev/rules.d/70-persistent-net.rules [root@kvm01 ~]# brctl addif br0 eth0 && ip addr del dev eth0 1.1.1.110/24 && ifconfig br0 1.1.1.110/24 up [root@kvm01 ~]# [root@kvm01 ~]# [root@kvm01 ~]# [root@kvm01 ~]# [root@kvm01 ~]# ifconfig br0 Link encap:Ethernet HWaddr 00:0C:29:02:14:8E inet addr:1.1.1.110 Bcast:1.1.1.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:fe02:148e/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:22 errors:0 dropped:0 overruns:0 frame:0 TX packets:18 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:1458 (1.4 KiB) TX bytes:1872 (1.8 KiB) eth0 Link encap:Ethernet HWaddr 00:0C:29:02:14:8E inet6 addr: fe80::20c:29ff:fe02:148e/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:252 errors:0 dropped:0 overruns:0 frame:0 TX packets:183 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:23466 (22.9 KiB) TX bytes:22809 (22.2 KiB) [root@kvm01 ~]# virsh list --all Id Name State ---------------------------------------------------- 1 Centos-6.4-x86 running [root@kvm01 ~]# virsh edit Centos-6.4-x86 Domain Centos-6.4-x86 XML configuration edited. [root@kvm01 etc]# grep "bridge" /etc/libvirt/qemu/Centos-6.4-x86.xml <interface type='bridge'> <source bridge='br0'/> [root@kvm01 etc]# virsh destroy Centos-6.4-x86 [root@kvm01 etc]# virsh start Centos-6.4-x86 Domain Centos-6.4-x86 started [root@kvm01 etc]# brctl show bridge name bridge id STP enabled interfaces br0 8000.000c2902148e no eth0 vnet0 virbr0 8000.52540088e051 yes virbr0-nic |
报错:
0 1 2 |
[root@kvm01 ~]# /etc/init.d/libvirtd start Starting libvirtd daemon: libvirtd: relocation error: libvirtd: symbol dm_task_get_info_with_deferred_remove, version Base not defined in file libdevmapper.so.1.02 with link time reference [FAILED] |
解决:
0 |
yum upgrade device-mapper-libs |
报错:
0 1 |
[root@kvm01 opt]# ping www.baidu.com connect: Network is unreachable |
解决:
0 1 2 3 4 5 6 |
[root@kvm01 opt]# route add default gw 1.1.1.2 [root@kvm01 opt]# route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 1.1.1.0 0.0.0.0 255.255.255.0 U 0 0 0 br0 192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0 0.0.0.0 1.1.1.2 0.0.0.0 UG 0 0 0 br0 |
报错:
0 |
ERROR Host does not support domain type kvm for virtualization type 'hvm' arch 'x86_64' |
解决:
0 |
未开启硬件CPU内存虚拟化 |
报错:
0 |
ERROR Guest name 'Centos-6.4-x86_model' is already in use. |
解决:
0 |
virsh undefine Centos-6.4-x86_model |
备注:
1:https://www.tightvnc.com/download.phpSourceByrd's Weblog-https://note.t4x.org/cloud/config-virt-kvm/
SourceByrd's Weblog-https://note.t4x.org/cloud/config-virt-kvm/
申明:除非注明Byrd's Blog内容均为原创,未经许可禁止转载!详情请阅读版权申明!