linux搭建虚拟化平台报告,Centos部署KVM虚拟化平台(可跟做)
Centos部署KVM虛擬化平臺(可跟做)
發(fā)布時(shí)間:2020-08-19 05:47:46
來源:51CTO
閱讀:4210
作者:俊偉祺i
一、KVM概述
KVM是Kernel Virtual Machine的簡寫,目前Linux發(fā)行版必須在64位的系統(tǒng)環(huán)境才能運(yùn)行KVM,同時(shí)硬件需要支持VT技術(shù)。
1、案例前置知識點(diǎn)
KVM自Linux2.6.20版本后就直接整合到Linux內(nèi)核,它依托CPU虛擬化指令集(如Intel-VT、AMD-V)實(shí)現(xiàn)高性能的虛擬化支持。由于與Linux內(nèi)核高度整合,因此在性能、安全性、兼容性、穩(wěn)定性上都有很好的表現(xiàn)。
下圖是一個(gè)簡單的KVM虛擬化架構(gòu),在KVM環(huán)境中運(yùn)行的每個(gè)虛擬化操作系統(tǒng)都將表現(xiàn)位單個(gè)獨(dú)立的系統(tǒng)進(jìn)程。因此它可以 很方便地與Linux系統(tǒng)中的安全模塊進(jìn)行整合(SELinux),可以靈活地實(shí)現(xiàn)資源的管理及分配。
二、實(shí)施案例
1、環(huán)境需求:
Centos操作系統(tǒng)3臺;
Windiws 7操作系統(tǒng)1臺;
所需鏡像和工具請?jiān)L問:https://pan.baidu.com/s/1fPhMgWJAjnmgJI5w267QCA
提取碼:7x2p
2、編輯虛擬機(jī)支持虛擬化
1)修改處理器為2個(gè),勾選虛擬化引擎
2)檢查CPU是否支持虛擬化
[root@centos01 ~]# cat /proc/cpuinfo | grep vmx
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 syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts nopl xtopology tsc_reliable nonstop_tsc aperfmperf eagerfpu pni pclmulqdq vmx ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch epb tpr_shadow vnmi ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid rdseed adx smap xsaveopt dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp
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 syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts nopl xtopology tsc_reliable nonstop_tsc aperfmperf eagerfpu pni pclmulqdq vmx ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch epb tpr_shadow vnmi ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid rdseed adx smap xsaveopt dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp
3、安裝KVM所需軟件
[root@centos01 ~]# ln -sf /lib/systemd/system/graphical.target
/etc/systemd/system/default.target
[root@centos01 ~]# rm -rf /etc/yum.repos.d/CentOS-*
[root@centos01 ~]# mount /dev/cdrom /mnt/
mount: /dev/sr0 寫保護(hù),將以只讀方式掛載
[root@centos01 ~]# rpm -qa | grep qemu-kvm
qemu-kvm-1.5.3-141.el7.x86_64
qemu-kvm-common-1.5.3-141.el7.x86_64
[root@centos01 ~]# rpm -qa | grep qemu-kvm-tools
[root@centos01 ~]# yum -y install qemu-kvm-tools
[root@centos01 ~]# rpm -qa | grep qemu-kvm-tools
qemu-kvm-tools-1.5.3-141.el7.x86_64
[root@centos01 ~]# rpm -qa | grep virt-install
[root@centos01 ~]# yum -y install virt-install
[root@centos01 ~]# rpm -qa | grep virt-install
virt-install-1.4.1-7.el7.noarch
[root@centos01 ~]# rpm -qa | grep qemu-img
qemu-img-1.5.3-141.el7.x86_64
[root@centos01 ~]# rpm -qa | grep bridge-utils
bridge-utils-1.5-9.el7.x86_64
[root@centos01 ~]# rpm -qa | grep libvirt
libvirt-daemon-driver-qemu-3.2.0-14.el7.x86_64
libvirt-client-3.2.0-14.el7.x86_64
libvirt-daemon-driver-interface-3.2.0-14.el7.x86_64
libvirt-daemon-driver-storage-disk-3.2.0-14.el7.x86_64
libvirt-daemon-driver-storage-3.2.0-14.el7.x86_64
libvirt-daemon-driver-storage-core-3.2.0-14.el7.x86_64
libvirt-daemon-driver-storage-mpath-3.2.0-14.el7.x86_64
libvirt-daemon-driver-storage-iscsi-3.2.0-14.el7.x86_64
libvirt-daemon-kvm-3.2.0-14.el7.x86_64
libvirt-daemon-driver-nodedev-3.2.0-14.el7.x86_64
libvirt-gconfig-1.0.0-1.el7.x86_64
libvirt-daemon-driver-storage-rbd-3.2.0-14.el7.x86_64
libvirt-daemon-driver-storage-scsi-3.2.0-14.el7.x86_64
libvirt-libs-3.2.0-14.el7.x86_64
libvirt-daemon-driver-network-3.2.0-14.el7.x86_64
libvirt-daemon-driver-nwfilter-3.2.0-14.el7.x86_64
libvirt-glib-1.0.0-1.el7.x86_64
libvirt-daemon-driver-storage-gluster-3.2.0-14.el7.x86_64
libvirt-daemon-3.2.0-14.el7.x86_64
libvirt-daemon-config-network-3.2.0-14.el7.x86_64
libvirt-gobject-1.0.0-1.el7.x86_64
libvirt-daemon-driver-storage-logical-3.2.0-14.el7.x86_64
libvirt-python-3.2.0-3.el7.x86_64
libvirt-daemon-driver-secret-3.2.0-14.el7.x86_64
[root@centos01 ~]# rpm -qa | grep virt-manager
virt-manager-common-1.4.1-7.el7.noarch
[root@centos01 ~]# yum -y install virt-manager
[root@centos01 ~]# rpm -qa | grep virt-manager
virt-manager-1.4.1-7.el7.noarch
virt-manager-common-1.4.1-7.el7.noarch
[root@centos01 ~]# lsmod | grep kvm
kvm_intel 170086 0
kvm 566340 1 kvm_intel
irqbypass 13503 1 kvm
[root@centos01 ~]# systemctl start libvirtd
[root@centos01 ~]# systemctl enable libvirtd
4、使用WinSCP工具導(dǎo)入鏡像
1)使用winSCP將操作系統(tǒng)光盤導(dǎo)入到虛擬化管理器中(工具請?jiān)L問網(wǎng)盤自行提取)
2)輸入IP地址和用戶名密碼,登錄即可
3)跳過警告即可
4)導(dǎo)入操作系統(tǒng)
5)驗(yàn)證是否上傳成功
[root@centos01 ~]# pwd
/root
[root@centos01 ~]# ls
anaconda-ks.cfg CentOS-7.4-x86_64-1708.iso initial-setup-ks.cfg
5、虛擬化管理器創(chuàng)建虛擬機(jī)
1)打開虛擬化管理器
[root@centos01 ~]# virt-manager
2)創(chuàng)建新的虛擬機(jī)
3)瀏覽操作系統(tǒng)光盤
4)選擇光盤
5)保持默認(rèn),單擊前進(jìn)即可
6)自定義內(nèi)存大小
7)自定義磁盤大小
8)自定義虛擬機(jī)名稱,單擊完成即可
9)選擇第一行,回車鍵開始安裝
10)開始初始化配置
11)安裝完成,重啟虛擬機(jī)
12)接受許可協(xié)議
13)創(chuàng)建賬戶
14)賬戶設(shè)置密碼
三、虛擬化的基本管理使用
1)查看虛擬機(jī)運(yùn)行狀態(tài)
[root@centos01 ~]# virsh list --all
Id 名稱 狀態(tài)
----------------------------------------------------
2 centos running
2)關(guān)閉虛擬機(jī)
[root@centos01 ~]# virsh shutdown centos
域 centos 被關(guān)閉
3)啟動(dòng)虛擬機(jī)
[root@centos01 ~]# virsh start centos
域 centos 已開始
4)設(shè)置虛擬機(jī)開機(jī)自動(dòng)啟動(dòng)
[root@centos01 ~]# virsh autostart centos
域 centos標(biāo)記為自動(dòng)開始
5)強(qiáng)制關(guān)閉虛擬機(jī)
[root@centos01 ~]# virsh destroy centos
域 centos 被刪除
1、掛起和恢復(fù)虛擬機(jī)
1)掛起虛擬機(jī)
[root@centos01 ~]# virsh suspend centos
域 centos 被掛起
2)恢復(fù)掛起的虛擬機(jī)
[root@centos01 ~]# virsh resume centos
域 centos 被重新恢復(fù)
2、備份恢復(fù)虛擬機(jī)
1)備份虛擬機(jī)
[root@centos01 ~]# virsh dumpxml centos > /etc/libvirt/qemu/centos01.xml
2)刪除虛擬機(jī)
[root@centos01 ~]# virsh undefine centos
域 centos 已經(jīng)被取消定義
3)查看備份的虛擬機(jī)
[root@centos01 ~]# cd /etc/libvirt/qemu/
[root@centos01 qemu]# ls
autostart centos01.xml networks
4)恢復(fù)虛擬機(jī)
[root@centos01 qemu]# virsh define centos01.xml
定義域 centos(從 centos01.xml)
5)查看恢復(fù)虛擬機(jī)的運(yùn)行狀態(tài)
[root@centos01 ~]# virsh list --all
Id 名稱 狀態(tài)
----------------------------------------------------
4 centos running
6)修改虛擬機(jī)配置文件的兩種方法
[root@centos01 ~]# vim /etc/libvirt/qemu/centos.xml
[root@centos01 ~]# virsh edit centos
3、克隆和快照
1)克隆虛擬機(jī)
[root@centos01 ~]# virsh shutdown centos
域 centos 被關(guān)閉
[root@centos01 ~]# virt-clone -o centos -n centos02 -f /var/lib/libvirt/images/centos02.qcow2
正在分配 'centos02.qcow2' | 30 GB 00:11
成功克隆 'centos02'。
2)創(chuàng)建快照
[root@centos01 ~]# virsh snapshot-create centos
已生成域快照 1574274181
3)恢復(fù)快照
[root@centos01 ~]# virsh snapshot-revert centos 1574274181
4)查看快照
[root@centos01 ~]# virsh snapshot-list centos
名稱 生成時(shí)間 狀態(tài)
------------------------------------------------------------
1574274181 2019-11-21 02:23:01 +0800 shutoff
5)刪除快照
[root@centos01 ~]# virsh snapshot-delete centos 1574274181
已刪除域快照 1574274181
[root@centos01 ~]# virsh snapshot-list centos
名稱 生成時(shí)間 狀態(tài)
------------------------------------------------------------
—————— 本文至此結(jié)束,感謝閱讀 ——————
總結(jié)
以上是生活随笔為你收集整理的linux搭建虚拟化平台报告,Centos部署KVM虚拟化平台(可跟做)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 使用谷歌Colab(Colaborato
- 下一篇: 初识linux之进程