一、云计算概述 云计算主要是一种按需付费的网络模式,这种模式提供可用的、便捷的、按需的网络访问,进入可配置的计算资源共享池(资源包括网络,服务器,存储,应用软件,服务),这些资源能够被快速提供,只需投入很少的管理工作,或与服务供应商进行很少的交互。分为三大层:IaaS(基础设施即服务,面向运维人员)、PaaS(平台即服务,面向开发人员),SaaS(软件即服务,面向终端用户)。 虚拟化分类:服务器虚拟化、桌面虚拟化、应用虚拟化,私有云 1.1 云计算的特点和优势1)云计算是一种使用模式 2)云计算必须通过网络访问 3)弹性计算,按需付费 1.2 在云计算之前的模式或技术1)IDC托管 2)IDC租用 3)虚拟主机(卖空间的) 4)vps:虚拟专有主机,openvz超卖很坑人的,xen不支持超卖 1.3 相对于云计算,传统数据中心面临的问题1)资源利用率低(大部分机器cpu所占比率低于15%) 2)资源分配不合理 举例:由于某个活动,上线各种服务器,但是并未达到实际效果,导致服务器资源浪费 3)很难实现真正的运维自动化 1.4图解云计算的三层服务基础设施:计算,存储,网络服务 二、云计算与虚拟化 2.1 公有云、私有云和混合云
2.2云计算的层次
2.3 虚拟化的优势虚拟化可以虚拟出来多个操作系统:每个操作系统之间是相互独立的,所以每个操作系统上所跑的应用自然是相互不影响的。在这里用一个经典的例子说明,一台物理机跑8个tomcat和8个虚拟机上各跑一个tomcat,跑8个tomcat的物理机,如果其中一个tomcat出问题(内存有问题,jvm有问题等),势必会影响到其他7个tomcat,但是在8个虚拟机上跑分别各跑一个tomcat,他们之间是互不影响的,由于虚拟化一层原因占用了一些资源,效果并没有直接一台物理机跑8个tomcat效果好,但是虚拟机的互相独立互不影响是更重要的,而且便于管理,每个tomcat实例都会起3个端口(8080:对外服务端口,8009:AJP端口,8005:关闭端口),使用虚拟机之后,就不会担心多个tomcat端口冲突的情况。 2.4 虚拟化和云计算的简单总结虚拟化是一种技术,云计算是通过虚拟化技术实现的一种通过网络访问获取资源,流量,交付的使用模式,两者并不能相互比较,虚拟化相当于实干家,而云计算是思想家。 三、虚拟化的分类 3.1 全虚拟化与半虚拟化
3.2服务器虚拟化,桌面虚拟化,应用虚拟化
四、虚拟化之KVM 4.1kvm的虚拟化特性1)嵌入到linxu正式kernel(提高了兼容性) 4.2 支持虚拟化的条件inter的cpu:vmx 在cpuinfo中可以查看具体的支持虚拟化的信息 [root@localhost ~]# grep -E"svm|vmx" /proc/cpuinfo flags : fpu vme de pse tsc msr pae mce cx8apic sep mtrr pge mca cmov pat pse36 clflush dts mmx fxsr sse sse2 ss syscallnx rdtscp lm constant_tsc arch_perfmon pebs bts nopl xtopology tsc_reliablenonstop_tsc aperfmperf pni pclmulqdq vmx ssse3 cx16 pcid sse4_1 sse4_2 x2apicpopcnt tsc_deadline_timer xsave avx hypervisor lahf_lm arat epb pln pts dthermtpr_shadow vnmi ept vpid tsc_adjust 4.3 kvm安装实战安装kvm [root@localhost~]# yum install qemu-kvm qemu-kvm-tools virt-manager libvirt virt-install –y kvm: linux内核的一个模块,模块不需要安装,只需要加载 创建一个虚拟磁盘,-f 指定格式,路径是/opt/CentOS-7.1-x86_64.raw,大小为10G [root@localhost ~]# qemu- qemu-img qemu-io qemu-nbd [root@localhost ~]# qemu-img create -f raw/opt/CentOS-7-x86_64-Minimal-1511.raw 10G Formatting'/opt/CentOS-7-x86_64-Minimal-1511.raw', fmt=raw size=10737418240 显示内核中kvm的状态 [root@localhost ~]# lsmod|grep kvm kvm_intel 162153 0 kvm 525259 1 kvm_intel
启动libvirt,查看状态,关键字:active [root@localhost ~]# systemctl enablelibvirtd.service [root@localhost ~]# systemctl startlibvirtd.service [root@localhost ~]# systemctl statuslibvirtd.service libvirtd.service - Virtualization daemon Loaded: loaded (/usr/lib/systemd/system/libvirtd.service; enabled;vendor preset: enabled) Active: active (running) since Sat 2016-11-19 07:39:58 CST; 4s ago Docs: man:libvirtd(8) http:// MainPID: 3051 (libvirtd) CGroup: /system.slice/libvirtd.service ├─3051 /usr/sbin/libvirtd ├─3152 /sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.... └─3154 /sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default....
Nov 19 07:39:58 localhost.localdomainsystemd[1]: Started Virtualization daemon. Nov 19 07:40:00 localhost.localdomaindnsmasq[3152]: started, version 2.66 ca... Nov 19 07:40:00 localhost.localdomaindnsmasq[3152]: compile time options: IP... Nov 19 07:40:00 localhost.localdomaindnsmasq-dhcp[3152]: DHCP, IP range 192.... Nov 19 07:40:00 localhost.localdomain dnsmasq[3152]:reading /etc/resolv.conf Nov 19 07:40:00 localhost.localdomaindnsmasq[3152]: using nameserver 61.178.... Nov 19 07:40:00 localhost.localdomaindnsmasq[3152]: using nameserver 202.100... Nov 19 07:40:00 localhost.localdomaindnsmasq[3152]: read /etc/hosts - 2 addr... Nov 19 07:40:00 localhost.localdomaindnsmasq[3152]: read /var/lib/libvirt/dn... Nov 19 07:40:00 localhost.localdomaindnsmasq-dhcp[3152]: read /var/lib/libvi... Hint: Some lines were ellipsized, use -l toshow in full.
4.4 开始装一台虚拟机在vmvare上挂载一个镜像 导入到宿主机中,当然时间可能较长 [root@localhost ~]# dd if=/dev/cdromof=/opt/CentOS-7-x86_64-Minimal-1511.iso 1234944+0 records in 1234944+0 records out 632291328 bytes (632 MB) copied, 39.0131 s,16.2 MB/s [root@localhost ~]# ls /opt/ CentOS-7-x86_64-Minimal-1511.iso CentOS-7-x86_64-Minimal-1511.raw
[root@localhost ~]# virt-install --help usage:virt-install --name NAME --ram RAM STORAGE INSTALL [options] Createa new virtual machine from specified install media. optionalarguments: -h, --help show this help message and exit --version show program's version number andexit --connect URI Connect to hypervisor with libvirt URI GeneralOptions: -n NAME, --name NAME Name of the guest instance --memory MEMORY Configure guest memory allocation. Ex: --memory 1024 (in MiB) --memory512,maxmemory=1024 --vcpus VCPUS Number of vcpus to configure for yourguest. Ex: --vcpus 5 --vcpus5,maxcpus=10,cpuset=1-4,6,8 --vcpussockets=2,cores=4,threads=2, --cpu CPU CPU model and features. Ex: --cpu coreduo,+x2apic --cpu host --metadata METADATA Configure guest metadata. Ex: --metadataname=foo,title="My pretty title",uuid=... --metadatadescription="My nice long description"
InstallationMethod Options: --cdrom CDROM CD-ROM installation media -l LOCATION, --location LOCATION Installation source(eg, nfs:host:/path, http://host/path,ftp://host/path) --pxe Boot from the network usingthe PXE protocol --import Build guest around an existingdisk image --livecd Treat the CD-ROM media as a LiveCD -x EXTRA_ARGS, --extra-args EXTRA_ARGS Additional arguments topass to the install kernel booted from --location --initrd-inject INITRD_INJECT Add given file to rootof initrd from --location --os-variant DISTRO_VARIANT The OS variant beinginstalled guests, e.g. 'fedora18', 'rhel6','winxp', etc. --boot BOOT Configure guest boot settings. Ex: --boot hd,cdrom,menu=on --boot init=/sbin/init(for containers) --idmap IDMAP Enable user namespace for LXCcontainer. Ex: --idmapuid_start=0,uid_target=1000,uid_count=10
DeviceOptions: --disk DISK Specify storage with variousoptions. Ex. --disk size=10 (new10GiB image in default location) --disk/my/existing/disk,cache=none --diskdevice=cdrom,bus=scsi --disk=? -w NETWORK, --network NETWORK Configure a guestnetwork interface. Ex: --network bridge=mybr0 --networknetwork=my_libvirt_virtual_net --networknetwork=mynet,model=virtio,mac=00:11... --network none --network help --graphics GRAPHICS Configure guest display settings. Ex: --graphics vnc --graphicsspice,port=5901,tlsport=5902 --graphics none --graphicsvnc,password=foobar,port=5910,keymap=ja --controller CONTROLLER Configure a guestcontroller device. Ex: --controllertype=usb,model=ich9-ehci1 --input INPUT Configure a guest input device. Ex: --input tablet --inputkeyboard,bus=usb --serial SERIAL Configure a guest serial device --parallel PARALLEL Configure a guest parallel device --channel CHANNEL Configure a guest communication channel --console CONSOLE Configure a text console connectionbetween the guest and host --hostdev HOSTDEV Configure physical USB/PCI/etc hostdevices to be shared with the guest --filesystem FILESYSTEM Pass host directory tothe guest. Ex: --filesystem/my/source/dir,/dir/in/guest --filesystemtemplate_name,/,type=template --sound [SOUND] Configure guest sound device emulation --watchdog WATCHDOG Configure a guest watchdog device --video VIDEO Configure guest video hardware. --smartcard SMARTCARD Configure a guestsmartcard device. Ex: --smartcardmode=passthrough --redirdev REDIRDEV Configure a guest redirection device. Ex: --redirdevusb,type=tcp,server=192.168.1.1:4000 --memballoon MEMBALLOON Configure a guestmemballoon device. Ex: --memballoonmodel=virtio --tpm TPM Configure a guest TPM device. Ex: --tpm /dev/tpm --rng RNG Configure a guest RNG device. Ex: --rng /dev/random --panic PANIC Configure a guest panic device. Ex: --panic default
GuestConfiguration Options: --security SECURITY Set domain security driver configuration. --numatune NUMATUNE Tune NUMA policy for the domain process. --memtune MEMTUNE Tune memory policy for the domain process. --blkiotune BLKIOTUNE Tune blkio policy forthe domain process. --memorybacking MEMORYBACKING Set memory backing policyfor the domain process. Ex: --memorybackinghugepages=on --features FEATURES Set domain <features> XML. Ex: --features acpi=off --featuresapic=on,eoi=on --clock CLOCK Set domain <clock> XML. Ex: --clockoffset=localtime,rtc_tickpolicy=catchup --pm PM Configure VM power managementfeatures --events EVENTS Configure VM lifecycle management policy --resource RESOURCE Configure VM resource partitioning (cgroups)
VirtualizationPlatform Options: -v, --hvm This guest should be a fullyvirtualized guest -p, --paravirt This guest should be a paravirtualizedguest --container This guest should be a containerguest --virt-type HV_TYPE Hypervisor name to use (kvm, qemu, xen, ...) --arch ARCH The CPU architecture to simulate --machine MACHINE The machine type to emulate
MiscellaneousOptions: --autostart Have domain autostart on host bootup. --wait WAIT Minutes to wait for install tocomplete. --noautoconsole Don't automatically try to connect tothe guest console --noreboot Don't boot guest after completinginstall. --print-xml [XMLONLY] Print the generateddomain XML rather than create the guest. --dry-run Run through install process, butdo not create devices or define the guest. --check CHECK Enable or disable validation checks.Example: --check path_in_use=off --check all=off -q, --quiet Suppress non-error output [root@localhost ~]# virt virt-clone virtlockd virt-what virt-host-validate virt-manager virt-xml virt-install virt-pki-validate virt-xml-validate [root@localhost ~]# virt-install --nameCentOS-7-x86_64-Minimal-1511 --virt-type kvm --ram 1024--cdrom=/opt/CentOS-7-x86_64-Minimal-1511.iso --diskpath=/opt/CentOS-7-x86_64-Minimal-1511.raw --network network=default --graphicsvnc,listen=0.0.0.0 --noautoconsole
Starting install... Creating domain... | 0 B 00:01 Domain installation still in progress. Youcan reconnect to the console to complete the installationprocess. 4.5 虚拟机基本操作学习生成kvm虚拟机:virt-install 启动刚才创建的虚拟机 [root@localhost ~]# virsh startCentOS-7-x86_64-Minimal-1511 [root@localhost ~]# ps -ef|grep kvm //kvm就是一个进程 root 686 2 0 19:50 ? 00:00:00 [kvm-irqfd-clean] qemu 2353 1 91 19:55 ? 00:24:08/usr/libexec/qemu-kvm -name CentOS-7-x86_64-Minimal-1511 -S -machinepc-i440fx-rhel7.0.0,accel=kvm,usb=off -cpu Nehalem -m 1024 -realtime mlock=off-smp 1,sockets=1,cores=1,threads=1 -uuid cf30a98a-143c-4bca-bf61-f27b8799061b-no-user-config -nodefaults -chardevsocket,id=charmonitor,path=/var/lib/libvirt/qemu/domain-CentOS-7-x86_64-Minimal-1511/monitor.sock,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 -globalPIIX4_PM.disable_s3=1 -global PIIX4_PM.disable_s4=1 -boot strict=on -deviceich9-usb-ehci1,id=usb,bus=pci.0,addr=0x5.0x7 -deviceich9-usb-uhci1,masterbus=usb.0,firstport=0,bus=pci.0,multifunction=on,addr=0x5-device ich9-usb-uhci2,masterbus=usb.0,firstport=2,bus=pci.0,addr=0x5.0x1-device ich9-usb-uhci3,masterbus=usb.0,firstport=4,bus=pci.0,addr=0x5.0x2-device virtio-serial-pci,id=virtio-serial0,bus=pci.0,addr=0x4 -drivefile=/opt/CentOS-7-x86_64-Minimal-1511.raw,if=none,id=drive-virtio-disk0,format=raw-devicevirtio-blk-pci,scsi=off,bus=pci.0,addr=0x6,drive=drive-virtio-disk0,id=virtio-disk0,bootindex=2-drivefile=/opt/CentOS-7-x86_64-Minimal-1511.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 -devicevirtio-net-pci,netdev=hostnet0,id=net0,mac=52:54:00:f0:c7:f8,bus=pci.0,addr=0x3-chardev pty,id=charserial0 -device isa-serial,chardev=charserial0,id=serial0-chardevsocket,id=charchannel0,path=/var/lib/libvirt/qemu/channel/target/domain-CentOS-7-x86_64-Minimal-1511/org.qemu.guest_agent.0,server,nowait-devicevirtserialport,bus=virtio-serial0.0,nr=1,chardev=charchannel0,id=channel0,name=org.qemu.guest_agent.0-device usb-tablet,id=input0 -vnc 0.0.0.0:0 -vga cirrus -devicevirtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x7 -msg timestamp=on root 2411 2 0 19:55 ? 00:00:00 [kvm-pit/2353] root 2782 2265 0 20:21 pts/0 00:00:00 grep --color=auto kvm 4.6 编辑kvm的xml文件,更改虚拟机CPU配置
[root@localhost ~]# ll /etc/libvirt/qemu total 8 -rw-------. 1 root root 3938 Nov 19 19:55CentOS-7-x86_64-Minimal-1511.xml //kvm虚拟机配置文件 drwx------. 3 root root 4096 Nov 19 07:39networks [root@localhost ~]# virsh edit CentOS-7-x86_64-Minimal-1511 <vcpuplacement='auto'current="1">4</vcpu> 当前为1,自动扩容,最大为4
[root@localhost ~]# virsh shutdown CentOS-7-x86_64-Minimal-1511 DomainCentOS-7-x86_64-Minimal-1511 is being shutdown [root@localhost ~]# virsh start CentOS-7-x86_64-Minimal-1511 DomainCentOS-7-x86_64-Minimal-1511 started [root@localhost ~]# virsh setvcpus CentOS-7-x86_64-Minimal-1511 2 --live
[root@chuck ~]# cat/sys/devices/system/cpu/cpu1/online 1
4.7 编辑kvm的xml文件,更改虚拟机内存配置
[root@localhost ~]# virsh edit CentOS-7-x86_64-Minimal-1511 <memoryunit='KiB'>4194304</memory> //把最大内存改为4G <currentMemoryunit='KiB'>1048576</currentMemory> //当前内存为1G 重启虚拟机并查看当前状态的内存使用情况 [root@localhost ~]# virsh qemu-monitor-command CentOS-7-x86_64-Minimal-1511--hmp --cmd info balloon balloon: actual=1024
对内存进行热添加并查看 [root@localhost ~]# virsh qemu-monitor-commandCentOS-7-x86_64-Minimal-1511 --hmp --cmd balloon 2000 [root@localhost ~]# virsh qemu-monitor-commandCentOS-7-x86_64-Minimal-1511 --hmp --cmd info balloon balloon: actual=2260
更改虚拟机中存储,硬盘设置(不建议在生产环境使用硬盘的扩大收缩模式,很容易产生故障) [root@localhost ~]# qemu-img --help |grep -i "formats:" Supported formats: vvfat vpc vmdk vhdx vdi ssh sheepdog rbd rawhost_cdrom host_floppy host_device file qed qcow2 qcow parallels nbd iscsigluster dmg tftp ftps ftp https http cloop bochs blkverify blkdebug
4.8 编辑kvm的xml文件,更改虚拟机网桥连接配置
修改eth0(这里Centos7的eth0在装机的时候就指定,不需要特意指定了) · 添加一个网桥并查看 [root@localhost ~]# brctl show //查看网桥 bridge name bridge id STP enabled interfaces virbr0 8000.5254007c0675 yes virbr0-nic vnet0 [root@localhost ~]# brctl addbr br0 //添加网桥 [root@localhost ~]# brctl show bridge name bridge id STP enabled interfaces br0 8000.000000000000 no virbr0 8000.5254007c0675 yes virbr0-nic vnet0 把eth0加入网桥,使用桥接模式,给br设置ip,添加路由网关,关闭防火墙 [root@localhost ~]# ifconfig eth0:flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.8.113 netmask255.255.255.0 broadcast 192.168.8.255 inet6 fe80::20c:29ff:fe3f:2a6d prefixlen 64 scopeid0x20<link> ether 00:0c:29:3f:2a:6d txqueuelen 1000 (Ethernet) RX packets 25918 bytes 2063267(1.9 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 33036 bytes 5049008(4.8 MiB) TX errors 0 dropped 0 overruns0 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 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 0 bytes 0 (0.0 B) TX errors 0 dropped 0 overruns0 carrier 0 collisions 0 virbr0:flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.122.1 netmask255.255.255.0 broadcast 192.168.122.255 ether 52:54:00:7c:06:75 txqueuelen 0 (Ethernet) RX packets 28 bytes 1204 (1.1KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 0 bytes 0 (0.0 B) TX errors 0 dropped 0 overruns0 carrier 0 collisions 0 vnet0:flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet6 fe80::fc54:ff:fef0:c7f8 prefixlen 64 scopeid0x20<link> ether fe:54:00:f0:c7:f8 txqueuelen 500 (Ethernet) RX packets 28 bytes 1596 (1.5KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 1132 bytes 59096 (57.7KiB) TX errors 0 dropped 0 overruns0 carrier 0 collisions 0 [root@localhost ~]# brctl addif bro eth0 //把eth0加入网桥,注意!此时网络会断掉 [root@localhost ~]# brctl addif br0 eth0 && ip addr del deveth0 192.168.8.113/24 && ifconfig br0 192.168.8.113/24 up &&route add default gw 192.168.8.2 && iptables –F //用此命令网络不会终断
编辑虚拟机的网络配置使用br0网桥模式 [root@localhost ~]# 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>
[root@localhost ~]# ifconfig br0:flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.8.113 netmask255.255.255.0 broadcast 192.168.8.255 inet6 fe80::20c:29ff:fe3f:2a6d prefixlen 64 scopeid0x20<link> ether 00:0c:29:3f:2a:6d txqueuelen 0 (Ethernet) RX packets 44 bytes 5895 (5.7KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 47 bytes 5434 (5.3KiB) TX errors 0 dropped 0 overruns0 carrier 0 collisions 0 eth0:flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet6 fe80::20c:29ff:fe3f:2a6d prefixlen 64 scopeid0x20<link> ether 00:0c:29:3f:2a:6d txqueuelen 1000 (Ethernet) RX packets 26325 bytes 2108762(2.0 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 33358 bytes 5095692(4.8 MiB) TX errors 0 dropped 0 overruns0 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 scopeid0x10<host> loop txqueuelen 0 (Local Loopback) RX packets 8 bytes 800 (800.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 8 bytes 800 (800.0 B) TX errors 0 dropped 0 overruns0 carrier 0 collisions 0 virbr0:flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.122.1 netmask255.255.255.0 broadcast 192.168.122.255 ether 52:54:00:7c:06:75 txqueuelen 0 (Ethernet) RX packets 28 bytes 1204 (1.1KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 0 bytes 0 (0.0 B) TX errors 0 dropped 0 overruns0 carrier 0 collisions 0 vnet0:flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet6 fe80::fc54:ff:fef0:c7f8 prefixlen 64 scopeid0x20<link> ether fe:54:00:f0:c7:f8 txqueuelen 500 (Ethernet) RX packets 28 bytes 1596 (1.5KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 1248 bytes 65128 (63.6KiB) TX errors 0 dropped 0 overruns0 carrier 0 collisions 0 删除虚拟机,删除前先关闭虚拟机,不要轻易的删除,因为删除后无法恢复 [root@localhost ~]# virsh undefine CentOS-7-x86_64-Minimal-1511 //彻底删除虚拟机 如果想删除后,再恢复所删除的虚拟机,在删除前可以先备份虚拟机的.xml文件,然后再通过.xml文件重建虚拟机就可以。 导出虚拟机(.xml) [root@localhost ~]# virsh--help|grep dump dump dump the core of a domain to a file for analysis dumpxml domain information in XML save-image-dumpxml saved state domain information in XML iface-dumpxml interface information in XML nwfilter-dumpxml network filter information in XML net-dumpxml network information in XML nodedev-dumpxml node device details in XML secret-dumpxml secret attributes in XML snapshot-dumpxml Dump XML for a domain snapshot pool-dumpxml pool information in XML vol-dumpxml volinformation in XML 关闭虚拟机: //也可以用kill -9来关闭(相当于拔掉电源) [root@localhost ~]# virsh --help|grepdestroy destroy destroy (stop) a domain iface-destroy destroy a physical host interface (disable it / "if-down") net-destroy destroy (stop) a network nodedev-destroy destroy (stop) a device on the node pool-destroy destroy (stop) a pool
五、KVM的优化 5.1 cpu的优化
· Ring3的用户态是没有权限管理硬件的,需要切换到内核态Ring0,这样的切换(系统调用)称之为上下文切换,物理机到虚拟机多次的上下文切换,势必会导致性能出现问题。对于全虚拟化,inter实现了技术VT-x,在cpu硬件上实现了加速转换,CentOS7默认是不需要开启的。 · cpu的缓存绑定cpu的优化 [root@localhost ~]# lscpu|grep cache L1d cache: 32K L1i cache: 32K L2 cache: 256K L3 cache: 3072K L1 L2 L3 三级缓存和CPU绑定 5.2内存的优化
在此之际,Inter在最新的Core I7系列处理器上集成了EPT技术(对应AMD的为RVI技术),以硬件辅助的方式完成客户物理内存到机器物理内存的转换,完成内存虚拟化,并以有效的方式弥补了影子页表的缺陷,该技术默认是开启的,如下图为EPT技术的原理 KSM内存合并 [root@localhost ~]# ps aux|grep ksmd|grep -vgrep root 297 0.0 0.0 0 0 ? SN 21:45 0:00 [ksmd] 大页内存,CentOS7默认开启的 [root@localhost ~]# cat/sys/kernel/mm/transparent_hugepage/enabled [always] madvise never [root@localhost ~]# ps aux |grepkhugepage|grep -v grep root 298 0.4 0.0 0 0 ? SN 21:45 0:26 [khugepaged] Linux平台默认的内存页面大小都是4K,HugePage进程会将默认的的每个内存页面可以调整为2M。 5.3 磁盘IO的优化
[root@localhost ~]# dmesg|grep -i"scheduler" [ 16.298583] io scheduler noop registered [ 16.298587] io scheduler deadline registered (default) [ 16.298804] io scheduler cfq registered 临时更改某个磁盘的IO调度算法,将deadling模式改为cfq模式 [root@localhost ~]# cat/sys/block/sda/queue/scheduler noop [deadline] cfq [root@localhost ~]# echo cfq>/sys/block/sda/queue/scheduler [root@localhost ~]# cat/sys/block/sda/queue/scheduler noop deadline [cfq] 使更改的IO调度算法永久生效,需要更改内核参数 5.4 cache的优化关于write through和write back,默认write through即可
Write through 六、创建虚拟机镜像 6.1 虚拟磁盘及镜像由于在一开始创建了虚拟磁盘,并命名为CentOS-7-x86_64-Minimal-1511.raw,这就是虚拟机的镜像喽。 [root@localhost ~]# ll /opt total 1936076 -rw-r--r--. 1 qemu qemu 632291328 Nov 19 19:52CentOS-7-x86_64-Minimal-1511.iso -rw-r--r--. 1 qemu qemu 5368709120 Nov 2000:19 CentOS-7-x86_64-Minimal-1511.raw 6.2 镜像制作原则
本文出自 “云计算与大数据” 博客,请务必保留此出处http://linuxzkq.blog.51cto.com/9379412/1876988 |
|