centos6.5kvm虚拟化安装部署
1
2
3
|
[root@chuck~] # grep -E "svm|vmx" /proc/cpuinfo flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts mmx fxsr sse sse2 ss ht syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts nopl xtopology tsc_reliable nonstop_tsc aperfmperf pni pclmulqdq vmx ssse3 cx16 pcid sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer xsave avx hypervisor lahf_lm arat epb pln pts dtherm tpr_shadow vnmi ept vpid tsc_adjust flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts mmx fxsr sse sse2 ss ht syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts nopl xtopology tsc_reliable nonstop_tsc aperfmperf pni pclmulqdq vmx ssse3 cx16 pcid sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer xsave avx hypervisor lahf_lm arat epb pln pts dtherm tpr_shadow vnmi ept vpid tsc_adjust |
1
|
[root@chuck~] # yum install qemu-kvm qemu-kvm-tools virt-manager libvirt -y |
1
2
|
[root@chuck opt] # qemu-img create -f raw /opt/CentOS-7.1-x86_64.raw 10G Formatting '/opt/CentOS-7.1-x86_64.raw' , fmt =raw size=10737418240 |
1
2
3
|
[root@chuck opt] # lsmod|grep kvm kvm_intel 148081 0 kvm 461126 1 kvm_intel |
1
2
3
4
5
6
|
[root@localhost opt] # dd if=/dev/cdrom of=/opt/CentOS-7.1-x86_64.iso 8419328+0 records in 8419328+0 records out 4310695936 bytes (4.3 GB) copied, 229.618 s, 18.8 MB /s [root@localhost opt] # ls /opt/ CentOS-7.1-x86_64.iso CentOS-7.1-x86_64.raw rh |
1
2
3
4
5
6
|
[root@chuck ~] # virt-install --name CentOS-7.1-x86_64 --virt-type kvm --ram 1024 --cdrom=/opt/CentOS-7.1-x86 --cdrom=/opt/CentOS-7.1-x86_64.iso --disk path=/opt/CentOS-7.1-x86_64.raw --nehics vnc,listen=0.0.0.0 --notwork network=default --graphics vnc,listen=0.0.0.0 --noautoconsole Starting install ... Creating domain... | 0 B 00:03 Domain installation still in progress. You can reconnect to the console to complete the installation process. |
1
2
3
4
5
|
[root@chuck ~] # ps -ef|grep kvm root 671 2 0 19:54 ? 00:00:00 [kvm-irqfd-clean] qemu 2829 1 75 20:09 ? 00:18:49 /usr/libexec/qemu-kvm -name CentOS-7.1-x86_64 -S -machine pc-i440fx-rhel7.0.0,accel=kvm,usb=off -cpu Nehalem -m 1024 -realtime mlock=off -smp 1,sockets=1,cores=1,threads=1 -uuid 1bd0464f-133b-4d51-b60b-5d33c5dde17f -no-user-config -nodefaults -chardev socket, id =charmonitor,path= /var/lib/libvirt/qemu/CentOS-7 .1-x86_64.monitor,server,nowait -mon chardev=charmonitor, id =monitor,mode=control -rtc base=utc,driftfix=slew -global kvm-pit.lost_tick_policy=discard -no-hpet -no-reboot -boot strict=on -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-7 .1-x86_64.raw, if =none, id =drive-virtio-disk0, format =raw -device virtio-blk-pci,scsi=off,bus=pci.0,addr=0x5,drive=drive-virtio-disk0, id =virtio-disk0,bootindex=2 -drive file = /opt/CentOS-7 .1-x86_64.iso, if =none, id =drive-ide0-0-0, readonly =on, format =raw -device ide- cd ,bus=ide.0,unit=0,drive=drive-ide0-0-0, id =ide0-0-0,bootindex=1 -netdev tap,fd=23, id =hostnet0,vhost=on,vhostfd=24 -device virtio-net-pci,netdev=hostnet0, id =net0,mac=52:54:00:99:1b:4e,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 2850 2 0 20:09 ? 00:00:00 [kvm-pit /2829 ] root 30667 2055 0 20:34 pts /0 00:00:00 grep --color=auto kvm |
1
2
|
[root@chuck ~] # virsh start CentOS-7.1-x86_64 Domain CentOS-7.1-x86_64 started |
1
2
|
[root@chuck ~] # virsh edit CentOS-7.1-x86_64 <vcpu placement= 'auto' current= "1" >4< /vcpu > 当前为1,自动扩容,最大为4 |
1
2
3
4
|
[root@chuck ~] # virsh shutdown CentOS-7.1-x86_64 Domain CentOS-7.1-x86_64 is being shutdown [root@chuck ~] # virsh start CentOS-7.1-x86_64 Domain CentOS-7.1-x86_64 started |
1
|
[root@chuck ~] # virsh setvcpus CentOS-7.1-x86_64 2 --live |
1
2
|
[root@chuck ~] # cat /sys/devices/system/cpu/cpu1/online 1 |
1
2
3
|
[root@chuck ~] # virsh edit CentOS-7.1-x86_64 <memory unit= 'KiB' >4194304< /memory >把最大内存改为4G <currentMemory unit= 'KiB' >1048576< /currentMemory >当前内存为1G |
1
2
|
[root@chuck ~] # virsh qemu-monitor-command CentOS-7.1-x86_64 --hmp --cmd info balloon balloon: actual=1024 |
1
2
3
4
|
[root@chuck ~] # virsh qemu-monitor-command CentOS-7.1-x86_64 --hmp --cmd balloon unexpected end of expression [root@chuck ~] # virsh qemu-monitor-command CentOS-7.1-x86_64 --hmp --cmd info balloon balloon: actual=2000 |
1
2
|
[root@chuck ~] # qemu-img --help |grep -i "formats:" Supported formats: vvfat vpc vmdk vhdx vdi sheepdog rbd raw host_cdrom host_floppy host_device file qed qcow2 qcow parallels nbd iscsi gluster dmg cloop bochs blkverify blkdebug |
1
|
[root@chuck ~] # brctl addbr br0 |
1
|
[root@chuck ~] # brctl addif br0 eth0 && ip addr del dev eth0 10.0.0.123/24 && ifconfig br0 10.0.0.123/24 up && route add default gw 10.0.0.2 && iptables -F |
1
2
3
4
5
|
[root@chuck ~]# virsh edit CentOS-7.1-x86_64 < interface type = "bridge" > <!--虚拟机网络连接方式--> < source bridge = "br0" /> <!-- 当前主机网桥的名称--> < mac address = "00:16:e4:9a:b3:6a" /> <!--为虚拟机分配mac地址,务必唯一,如果是dhcp获得同样ip,引起冲突--> </ interface > |
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
|
[root@chuck ~] # ifconfig br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 10.0.0.123 netmask 255.255.255.0 broadcast 10.0.0.255 inet6 fe80::20c:29ff:fe67:5a43 prefixlen 64 scopeid 0x20<link> ether 00:0c:29:67:5a:43 txqueuelen 0 (Ethernet) RX packets 5178 bytes 278872 (272.3 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 7599 bytes 862371 (842.1 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet6 fe80::20c:29ff:fe67:5a43 prefixlen 64 scopeid 0x20<link> ether 00:0c:29:67:5a:43 txqueuelen 1000 (Ethernet) RX packets 13641 bytes 973732 (950.9 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 21843 bytes 2417546 (2.3 MiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10<host> loop txqueuelen 0 (Local Loopback) RX packets 10 bytes 1044 (1.0 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 10 bytes 1044 (1.0 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500 inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255 ether 52:54:00:fc:d1:d1 txqueuelen 0 (Ethernet) RX packets 97 bytes 8122 (7.9 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 36 bytes 5157 (5.0 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 vnet0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet6 fe80::fc54:ff:fe99:1b4e prefixlen 64 scopeid 0x20<link> ether fe:54:00:99:1b:4e txqueuelen 500 (Ethernet) RX packets 42 bytes 7295 (7.1 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 45 bytes 4919 (4.8 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 |
1
2
3
4
5
|
[root@chuck ~] # lscpu|grep cache L1d cache: 32K L1i cache: 32K L2 cache: 256K L3 cache: 3072K |
1
2
|
[root@chuck ~] # ps aux|grep ksmd|grep -v grep root 286 0.0 0.0 0 0 ? SN 12:32 0:00 [ksmd] |
1
2
3
4
|
[root@chuck ~] # cat /sys/kernel/mm/transparent_hugepage/enabled [always] madvise never [root@chuck ~] # ps aux |grep khugepage|grep -v grep root 287 0.2 0.0 0 0 ? SN 12:32 0:21 [khugepaged] |
1
2
3
4
|
[root@chuck ~] # dmesg|grep -i "scheduler" [ 11.312549] io scheduler noop registered [ 11.312555] io scheduler deadline registered (default) [ 11.312606] io scheduler cfq registered |
1
2
3
4
5
|
[root@chuck ~] # cat /sys/block/sda/queue/scheduler noop [deadline] cfq [root@chuck ~] # echo cfq >/sys/block/sda/queue/scheduler [root@chuck ~] # cat /sys/block/sda/queue/scheduler noop deadline [cfq] |
1
2
|
[root@chuck ~] # vim /boot/grub/menu.lst kernel /boot/vmlinuz-3 .10.0-229.el7 ro root=LABEL=/ elevator=deadline rhgb quiet |
1
2
3
|
[root@chuck ~] # cd /opt/ [root@chuck opt] # ls CentOS-7.1-x86_64.iso CentOS-7.1-x86_64.raw rh |
user:Felix
mail:wudonghang@wudonghang.com
If you have questions or suggestions, please contact the author.