(1).虛擬化產品對比介紹html
虛擬化技術有如下三種:仿真虛擬化,這是一種對系統硬件沒有要求,但性能最低的虛擬化技術;半虛擬化,這是一種直接使用物理硬件,性能高,但須要修改內核的虛擬化技術;全虛擬化,這是一種直接使用物理硬件,性能高的虛擬化技術。python
VMware支持仿真虛擬化,xen支持半虛擬化,KVM支持全虛擬化。其中VMware安裝在Windows上,支持虛擬機系統與物理機系統不一樣;xen在REHL5中自帶,安裝時須要安裝內核kernel-xen,只支持與物理機同樣的操做系統;KVM在REHL6中自帶,支持虛擬機系統與物理機系統不一樣。linux
KVM全稱Kernel-based Virtual Machine,中文名基於內核的虛擬機,是一個開源的系統虛擬化模塊,自Linux 2.6.20以後集成在 以後集成在Linux的各個主要發行版本中,是第一個整合到Linux內核的虛擬化技術。它使用 Linux自身的調度器進行管理,因此相對於Xen,其核心源碼不多。KVM目前已成爲學術界的主流 VMM(虛擬機監控器 )之一。KVM的虛擬化須要硬件支持(如Intel VT技術或者AMD V技術 )。是基於硬件的徹底虛擬化。而Xen早期則是基於軟件模擬的Para-Virtualization。在KVM模型中,每個虛擬機都是一個由Linux調度程序管理的標準進程,你能夠在用戶空間啓動客戶機操做系統。另外,一個普通的 Linux 進程有兩種運行模式:內核和用戶。KVM增長了第三種模式:客戶模式(有本身的內核和用戶模式)。sql
擴展:QEMUshell
QEMU和vmware同樣都是支持仿真虛擬化,但效率比較低。它是一套由Fabrice Bellard所編寫的以GPL許可證分發源碼的模擬處理器,在GNU/Linux平臺上使用普遍。QEMU具備高速度和跨平臺的特性,QEMU能模擬至接近真實電腦的速度。vim
(2).安裝KVM前的準備centos
因爲我是在VMware裏的CentOS7中安裝KVM,首先須要確保系統是64位的。api
其次虛擬機設置,內存須要調大一點(我這裏給的是4G),處理器核心數也多一點(我這裏給到了物理核心數),處理器中還要開啓虛擬化Intel VT-x/EPT或AMD-V/RVI,以及虛擬化CPU性能計數器(官方說明:若是您打算使用性能監控應用程序(如 VTune 或 OProfile)優化或調試虛擬機中運行的軟件,能夠打開此功能),最後加一塊硬盤(我給的是50G)緩存
VMware官方文檔:https://docs.vmware.com/cn/VMware-Workstation-Pro/index.html服務器
以上作完後登陸系統,若是是Intel的CPU可使用cat /proc/cpuinfo | grep --color vmx命令查看CPU是否支持全虛擬化,若是是AMD的CPU可使用cat /proc/cpuinfo | grep --color svm命令查看CPU是否支持全虛擬化。若是是物理機也能夠經過上網查找CPU型號來查看是否支持全虛擬化。
[root@youxi1 ~]# cat /proc/cpuinfo | grep --color 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 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 aes xsave avx f16c rdrand hypervisor lahf_lm epb tpr_shadow vnmi ept vpid fsgsbase tsc_adjust smep dtherm ida arat pln pts 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 aes xsave avx f16c rdrand hypervisor lahf_lm epb tpr_shadow vnmi ept vpid fsgsbase tsc_adjust smep dtherm ida arat pln pts 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 aes xsave avx f16c rdrand hypervisor lahf_lm epb tpr_shadow vnmi ept vpid fsgsbase tsc_adjust smep dtherm ida arat pln pts 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 aes xsave avx f16c rdrand hypervisor lahf_lm epb tpr_shadow vnmi ept vpid fsgsbase tsc_adjust smep dtherm ida arat pln pts [root@youxi1 ~]# cat /proc/cpuinfo | grep --color svm
在確認CPU支持虛擬化以後,進入BIOS界面開啓虛擬化支持,通常在設置或高級設置裏面,找找有沒有虛擬技術(Virtual Technology)。
(3).安裝KVM
配置本地系統鏡像yum源(詳見:配置本地yum源)和阿里雲yum源,本地系統鏡像yum源只須要臨時掛載便可
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo //基礎源 wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo //epel源 yum clean all //清空yum緩存 yum list //根據新的yum源從新緩存
安裝KVM模塊、管理工具和虛擬化服務,並啓動
[root@youxi1 ~]# yum -y install qemu-kvm virt-install virt-manager libvirt libguestfs-tools libvirt-python [root@youxi1 ~]# systemctl start libvirtd [root@youxi1 ~]# systemctl is-enabled libvirtd //安裝完成後,默認開機自啓,若是顯示disable請手動設置 enabled [root@youxi1 ~]# ip a sh 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 link/ether 00:0c:29:e6:d6:27 brd ff:ff:ff:ff:ff:ff inet 192.168.5.101/24 brd 192.168.5.255 scope global noprefixroute ens33 valid_lft forever preferred_lft forever inet6 fe80::201:7257:85b:7dc8/64 scope link noprefixroute valid_lft forever preferred_lft forever 3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000 link/ether 52:54:00:4b:93:10 brd ff:ff:ff:ff:ff:ff inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0 valid_lft forever preferred_lft forever 4: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN group default qlen 1000 link/ether 52:54:00:4b:93:10 brd ff:ff:ff:ff:ff:ff
說明:qemu-kvm,KVM主程序,KVM虛擬化模塊;virt-install,安裝虛擬機的工具;virt-manager,KVM圖形化管理工具;libvirt,虛擬化服務;libguestfs-tools,虛擬機的系統管理工具;libvirt-python,python調用libvirt虛擬化服務的api接口庫文件。
啓動libvirtd後,會出現一塊virbr0網卡,IP地址默認192.168.122.1/24。
(4).配置KVM網絡橋接功能
咱們常常所說的Bridge設備其實就是網橋設備,也就至關於如今的二層交換機,用於鏈接同一網段內的全部機器,因此咱們的目的就是將網絡設備ens33添加到br0,此時br0就成爲了所謂的交換機設備,咱們物理機的ens33也是鏈接在上面的。
安裝網橋設備工具,並進行配置
[root@youxi1 ~]# yum -y install bridge-utils [root@youxi1 ~]# cp /etc/sysconfig/network-scripts/ifcfg-ens33 . //備份 [root@youxi1 ~]# ls anaconda-ks.cfg ifcfg-ens33 [root@youxi1 ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33 #IPADDR="192.168.5.101" #PREFIX="24" #GATEWAY="192.168.5.2" #DNS1="192.168.5.2" BRIDGE="br0" //添加 [root@youxi1 ~]# vim /etc/sysconfig/network-scripts/ifcfg-br0 //新建網橋配置文件 DEVICE="br0" NM_CONTROLLED="yes" ONBOOT="yes" TYPE="Bridge" //Bridge開頭的B必須大寫 BOOTPROTO=none IPADDR=192.168.5.101 //須要與ens33註釋的信息一致 NETMASK=255.255.255.0 GATEWAY=192.168.5.2 DNS1=192.168.5.2
重啓網絡,並進行查看
[root@youxi1 ~]# systemctl restart network [root@youxi1 ~]# ip a sh 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master br0 state UP group default qlen 1000 link/ether 00:0c:29:e6:d6:27 brd ff:ff:ff:ff:ff:ff 3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000 link/ether 52:54:00:4b:93:10 brd ff:ff:ff:ff:ff:ff inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0 valid_lft forever preferred_lft forever 4: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN group default qlen 1000 link/ether 52:54:00:4b:93:10 brd ff:ff:ff:ff:ff:ff 5: br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000 link/ether 00:0c:29:e6:d6:27 brd ff:ff:ff:ff:ff:ff inet 192.168.5.101/24 brd 192.168.5.255 scope global noprefixroute br0 valid_lft forever preferred_lft forever inet6 fe80::20c:29ff:fee6:d627/64 scope link valid_lft forever preferred_lft forever [root@youxi1 ~]# ping www.baidu.com //測試網絡是否正常 PING www.a.shifen.com (180.101.49.12) 56(84) bytes of data. 64 bytes from 180.101.49.12 (180.101.49.12): icmp_seq=1 ttl=128 time=7.59 ms 64 bytes from 180.101.49.12 (180.101.49.12): icmp_seq=2 ttl=128 time=6.06 ms 64 bytes from 180.101.49.12 (180.101.49.12): icmp_seq=3 ttl=128 time=6.30 ms ^C --- www.a.shifen.com ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2005ms rtt min/avg/max/mdev = 6.062/6.652/7.594/0.679 ms
(5).建立一臺虛擬機
KVM能夠直接使用命令建立虛擬機,也能夠在圖形用戶界面建立虛擬機,不過通常會直接使用命令安裝,由於比較節省資源。
不過在那以前,首先須要將sdb進行分區,格式化並掛載。
[root@youxi1 ~]# fdisk /dev/sdb //新建分區 歡迎使用 fdisk (util-linux 2.23.2)。 更改將停留在內存中,直到您決定將更改寫入磁盤。 使用寫入命令前請三思。 Device does not contain a recognized partition table 使用磁盤標識符 0x5ddf8670 建立新的 DOS 磁盤標籤。 命令(輸入 m 獲取幫助):n Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): p 分區號 (1-4,默認 1): 起始 扇區 (2048-104857599,默認爲 2048): 將使用默認值 2048 Last 扇區, +扇區 or +size{K,M,G} (2048-104857599,默認爲 104857599): 將使用默認值 104857599 分區 1 已設置爲 Linux 類型,大小設爲 50 GiB 命令(輸入 m 獲取幫助):w The partition table has been altered! Calling ioctl() to re-read partition table. 正在同步磁盤。 [root@youxi1 ~]# mkfs.xfs /dev/sdb1 //格式化 meta-data=/dev/sdb1 isize=512 agcount=4, agsize=3276736 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0, sparse=0 data = bsize=4096 blocks=13106944, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal log bsize=4096 blocks=6399, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 [root@youxi1 ~]# mount /dev/sdb1 /var/lib/libvirt/images/ //掛載 [root@youxi1 ~]# blkid //查看sdb1的UUID /dev/sda1: UUID="037d87f8-b6dd-426c-9d71-7ce5ec0d4103" TYPE="xfs" /dev/sda2: UUID="qryeOm-pb2K-SeE0-10tR-0jSL-x15s-4yI6cl" TYPE="LVM2_member" /dev/sdb1: UUID="771ee3b3-ba49-49bc-b3be-3736a329f532" TYPE="xfs" /dev/sr0: UUID="2018-05-03-20-55-23-00" LABEL="CentOS 7 x86_64" TYPE="iso9660" PTTYPE="dos" /dev/mapper/vg1-root: UUID="dffa058f-4c86-480b-8ff9-bfe973f7ca95" TYPE="xfs" /dev/mapper/vg1-swap: UUID="289bf00b-3804-4b11-8c8d-1dc964fc3a8b" TYPE="swap" [root@youxi1 ~]# echo "UUID=771ee3b3-ba49-49bc-b3be-3736a329f532 /var/lib/libvirt/images/ xfs defaults 0 0" >> /etc/fstab
1)圖形界面新建虛擬機
首先確保有圖形界面,沒有的使用以下命令進行安裝。在安裝過程的同時,能夠上傳一個系統鏡像
[root@youxi1 ~]# yum -y groupinstall "GNOME Desktop" //若是遇到以下錯誤,請使用下面的升級包命令 Transaction check error: file /boot/efi/EFI/centos from install of fwupdate-efi-12-5.el7.centos.x86_64 conflicts with file from package grub2-common-1:2.02-0.65.el7.centos.2.noarch [root@youxi1 ~]# yum -y upgrade //該命令升級全部包,但不改變軟件和系統設置,內核不變 //接着從新安裝圖形界面 [root@youxi1 ~]# yum -y groupinstall "GNOME Desktop" [root@youxi1 ~]# init 5 //轉到圖形化界面
而後通過一系列的設置,註銷新建的用戶,回到root用戶下總算能夠開始新建虛擬機了。使用命令virt-manager調出虛擬系統管理器,固然也能夠在應用程序-->系統工具-->虛擬系統管理器來調出。
選中QEMU/KVM,右鍵新建
接着出現以下界面,選擇本地安裝介質,前進(Next)
使用ISO映像,點擊瀏覽
會出現一個新的界面,點擊本地瀏覽
找到上傳的ISO位置,最後點擊打開便可
此時又會回到以前的「使用ISO映像」的頁面,點擊前進。若是是在/root/目錄下會提示可能沒有權限
設置內存和CPU,而後點擊前進
設置硬盤大小,前進
設置虛擬機名稱,選擇網絡,完成
最後會跳出一個CentOS7的安裝界面,正常安裝便可。
在這個界面的菜單欄下方,小燈泡標誌就是設置界面。
2)字符界面新建虛擬機
在安裝前,請先看(6).擴展。我看了不少都是僞字符界面安裝,都是用的VNC安裝,找了一段時間看到了這位大佬的文章:https://blog.csdn.net/qeeezz11224/article/details/84575910
能夠在新建KVM虛擬機以前使用命令指定虛擬機存儲格式,最多見的是qemu-img命令。
使用virt-install新建一個KVM虛擬機。注意:因爲我是複製下來的,因此看到的設置菜單的格式會有問題,大概看看,很簡單的。感嘆號!表示有問題,須要修改或等待刷新根據下方提示進行操做。
[root@youxi1 ~]# virt-install --virt-type kvm \ --name centos75 \ --vcpus 1 \ --memory 1024 \ --location /root/CentOS-7-x86_64-DVD-1804.iso \ --disk /var/lib/libvirt/images/centos75.img,size=10 \ --network bridge=br0 \ --graphics none \ --extra-args='console=ttyS0' \ --force ...... //中間跑一段時間,出現第一個界面 Installation 1) [x] Language settings 2) [!] Time settings (English (United States)) (Timezone is not set.) 3) [!] Installation source 4) [!] Software selection (Processing...) (Processing...) 5) [!] Installation Destination 6) [x] Kdump (No disks selected) (Kdump is enabled) 7) [ ] Network configuration 8) [!] Root password (Not connected) (Password is not set.) 9) [!] User creation (No user will be created) Please make your choice from above ['q' to quit | 'b' to begin installation | 'r' to refresh]:1 //光標是在這個位置,輸入1設置語言,<Enter>回車 [anaconda] 1:main* 2:shell 3:log 4:storage-lo> Switch tab: Alt+Tab | Help: F1 //出現以下頁面 ================================================================================ ================================================================================ Language settings Available languages 1) Afrikaans 25) Hindi 48) Oriya 2) Amharic 26) Croatian 49) Punjabi 3) Arabic 27) Hungarian 50) Polish 4) Assamese 28) Interlingua 51) Portuguese 5) Asturian 29) Indonesian 52) Romanian 6) Belarusian 30) Icelandic 53) Russian 7) Bulgarian 31) Italian 54) Sinhala 8) Bengali 32) Japanese 55) Slovak 9) Bosnian 33) Georgian 56) Slovenian 10) Catalan 34) Kazakh 57) Albanian 11) Czech 35) Kannada 58) Serbian 12) Welsh 36) Korean 59) Swedish 13) Danish 37) Lithuanian 60) Tamil 14) German 38) Latvian 61) Telugu 15) Greek 39) Maithili 62) Tajik 16) English 40) Macedonian 63) Thai 17) Spanish 41) Malayalam 64) Turkish 18) Estonian 42) Marathi 65) Ukrainian 19) Basque 43) Malay 66) Urdu 20) Persian 44) Norwegian Bokmål 67) Vietnamese 21) Finnish 45) Nepali 68) Chinese 22) French 46) Dutch 69) Zulu Press ENTER to continue //沒顯示完,<Enter>回車一下 23) Galician 47) Northern Sotho 24) Gujarati [b to return to language list, c to continue, q to quit]:68 //輸入68中文,<Enter>回車 [anaconda] 1:main* 2:shell 3:log 4:storage-lo> Switch tab: Alt+Tab | Help: F1 //出現以下頁面 ================================================================================ ================================================================================ Language settings Available locales 1) Simplified Chinese 3) Traditional Chinese 4) Simplified Chinese (China) (Hong Kong) (Singapore) 2) Traditional Chinese (Republic of China) Please select language support to install. [b to return to language list, c to continue, q to quit]: //輸入1簡體中文,<Enter>回車 [anaconda] 1:main* 2:shell 3:log 4:storage-lo> Switch tab: Alt+Tab | Help: F1 //以後會回到設置菜單界面,能夠看到語言設置下方變成了簡體中文 ================================================================================ ================================================================================ Installation 1) [x] Language settings 2) [!] Time settings (Simplified Chinese (China)) (Timezone is not set.) 3) [x] Installation source 4) [x] Software selection (Local media) (Minimal Install) 5) [!] Installation Destination 6) [x] Kdump (No disks selected) (Kdump is enabled) 7) [ ] Network configuration 8) [!] Root password (Not connected) (Password is not set.) 9) [!] User creation (No user will be created) Please make your choice from above ['q' to quit | 'b' to begin installation | 'r' to refresh]:2 //光標在此處,輸入2設置時間,<Enter>回車 [anaconda] 1:main* 2:shell 3:log 4:storage-lo> Switch tab: Alt+Tab | Help: F1 //出現以下頁面 ================================================================================ ================================================================================ Time settings Timezone: not set NTP servers:not configured 1) Set timezone 2) Configure NTP servers Please make your choice from above ['q' to quit | 'c' to continue | 'r' to refresh]: 1 //輸入1設置時區,<Enter>回車 [anaconda] 1:main* 2:shell 3:log 4:storage-lo> Switch tab: Alt+Tab | Help: F1 //出現以下頁面 ================================================================================ ================================================================================ Timezone settings Available regions 1) Europe 6) Pacific 10) Arctic 2) Asia 7) Australia 11) US 3) America 8) Atlantic 12) Etc 4) Africa 9) Indian 5) Antarctica Please select the timezone. Use numbers or type names directly [b to region list, q to quit]: 2 //選擇大區,輸入2亞洲,<Enter>回車 [anaconda] 1:main* 2:shell 3:log 4:storage-lo> Switch tab: Alt+Tab | Help: F1 //出現以下頁面 ================================================================================ ================================================================================ Timezone settings Available timezones in region Asia 1) Aden 29) Hong_Kong 56) Pontianak 2) Almaty 30) Hovd 57) Pyongyang 3) Amman 31) Irkutsk 58) Qatar 4) Anadyr 32) Jakarta 59) Qyzylorda 5) Aqtau 33) Jayapura 60) Riyadh 6) Aqtobe 34) Jerusalem 61) Sakhalin 7) Ashgabat 35) Kabul 62) Samarkand 8) Atyrau 36) Kamchatka 63) Seoul 9) Baghdad 37) Karachi 64) Shanghai 10) Bahrain 38) Kathmandu 65) Singapore 11) Baku 39) Khandyga 66) Srednekolymsk 12) Bangkok 40) Kolkata 67) Taipei 13) Barnaul 41) Krasnoyarsk 68) Tashkent 14) Beirut 42) Kuala_Lumpur 69) Tbilisi 15) Bishkek 43) Kuching 70) Tehran 16) Brunei 44) Kuwait 71) Thimphu 17) Chita 45) Macau 72) Tokyo 18) Choibalsan 46) Magadan 73) Tomsk 19) Colombo 47) Makassar 74) Ulaanbaatar 20) Damascus 48) Manila 75) Urumqi 21) Dhaka 49) Muscat 76) Ust-Nera 22) Dili 50) Nicosia 77) Vientiane Press ENTER to continue //<Enter>回車一下,還有區域沒顯示 23) Dubai 51) Novokuznetsk 78) Vladivostok 24) Dushanbe 52) Novosibirsk 79) Yakutsk 25) Famagusta 53) Omsk 80) Yangon 26) Gaza 54) Oral 81) Yekaterinburg 27) Hebron 55) Phnom_Penh 82) Yerevan 28) Ho_Chi_Minh Please select the timezone. Use numbers or type names directly [b to region list, q to quit]:64 //選擇具體地點,輸入64上海,<Enter>回車 [anaconda] 1:main* 2:shell 3:log 4:storage-lo> Switch tab: Alt+Tab | Help: F1 //以後會回到設置菜單界面,能夠看到時間設置下方變成了亞洲/上海時區 ================================================================================ ================================================================================ Installation 1) [x] Language settings 2) [x] Time settings (Simplified Chinese (China)) (Asia/Shanghai timezone) 3) [x] Installation source 4) [x] Software selection (Local media) (Minimal Install) 5) [!] Installation Destination 6) [x] Kdump (No disks selected) (Kdump is enabled) 7) [ ] Network configuration 8) [!] Root password (Not connected) (Password is not set.) 9) [!] User creation (No user will be created) Please make your choice from above ['q' to quit | 'b' to begin installation | 'r' to refresh]:5 //這裏輸入5安裝地址,<Enter>回車。3是安裝源,4軟件選擇,有須要的能夠設置 [anaconda] 1:main* 2:shell 3:log 4:storage-lo> Switch tab: Alt+Tab | Help: F1 //出現以下頁面 ================================================================================ ================================================================================ Probing storage... Installation Destination [x] 1) : 10 GiB (vda) 1 disk selected; 10 GiB capacity; 10 GiB free ... Please make your choice from above ['q' to quit | 'c' to continue | 'r' to refresh]: c //輸入c繼續,<Enter>回車 [anaconda] 1:main* 2:shell 3:log 4:storage-lo> Switch tab: Alt+Tab | Help: F1 //出現以下頁面 ================================================================================ ================================================================================ Autopartitioning Options [ ] 1) Replace Existing Linux system(s) [x] 2) Use All Space [ ] 3) Use Free Space Installation requires partitioning of your hard drive. Select what space to use for the install target. Please make your choice from above ['q' to quit | 'c' to continue | 'r' to refresh]: c //這個須要根據本身選擇,我這裏就使用全部空間,輸入c繼續,<Enter>回車 [anaconda] 1:main* 2:shell 3:log 4:storage-lo> Switch tab: Alt+Tab | Help: F1 //出現以下頁面 ================================================================================ ================================================================================ Partition Scheme Options [ ] 1) Standard Partition [ ] 2) Btrfs [x] 3) LVM [ ] 4) LVM Thin Provisioning Select a partition scheme configuration. Please make your choice from above ['q' to quit | 'c' to continue | 'r' to refresh]: c //這裏也是根據須要選擇,我使用LVM,輸入c繼續,<Enter>回車 [anaconda] 1:main* 2:shell 3:log 4:storage-lo> Switch tab: Alt+Tab | Help: F1 //須要等待一段時間,回到菜單設置頁面 ================================================================================ ================================================================================ Installation 1) [x] Language settings 2) [x] Time settings (Simplified Chinese (China)) (Asia/Shanghai timezone) 3) [x] Installation source 4) [x] Software selection (Local media) (Minimal Install) 5) [x] Installation Destination 6) [x] Kdump (Automatic partitioning (Kdump is enabled) selected) 8) [!] Root password 7) [ ] Network configuration (Password is not set.) (Not connected) 9) [!] User creation (No user will be created) Please make your choice from above ['q' to quit | 'b' to begin installation | 'r' to refresh]: 8 //輸入8設置root密碼,<Enter>回車。6是內核崩潰轉儲機制,能夠開啓也能夠關閉 [anaconda] 1:main* 2:shell 3:log 4:storage-lo> Switch tab: Alt+Tab | Help: F1 //出現以下頁面 ================================================================================ ================================================================================ Please select new root password. You will have to type it twice. Password: //輸入root密碼,我這裏是123456,<Enter>回車 Password (confirm): //回車後纔會出現,重複密碼 [anaconda] 1:main* 2:shell 3:log 4:storage-lo> Switch tab: Alt+Tab | Help: F1 //出現以下頁面,提示的是密碼太簡單了,是否繼續使用,我是實驗不要緊因此yes ================================================================================ ================================================================================ Question The password you have provided is weak: The password fails the dictionary check - it is too simplistic/systematic. Would you like to use it anyway? Please respond 'yes' or 'no': yes //輸入yes,<Enter>回車 //以後回到設置菜單頁面 ================================================================================ ================================================================================ Installation 1) [x] Language settings 2) [x] Time settings (Simplified Chinese (China)) (Asia/Shanghai timezone) 3) [x] Installation source 4) [x] Software selection (Local media) (Minimal Install) 5) [x] Installation Destination 6) [x] Kdump (Automatic partitioning (Kdump is enabled) selected) 8) [x] Root password 7) [ ] Network configuration (Password is set.) (Not connected) 9) [ ] User creation (No user will be created) Please make your choice from above ['q' to quit | 'b' to begin installation | 'r' to refresh]: 7 //輸入7設置網絡,<Enter>回車 [anaconda] 1:main* 2:shell 3:log 4:storage-lo> Switch tab: Alt+Tab | Help: F1 //出現以下頁面 ================================================================================ ================================================================================ Network configuration Wired (eth0) disconnected Host name: localhost.localdomain //這是默認的主機名 Current host name: localhost 1) Set host name 2) Configure device eth0 Please make your choice from above ['q' to quit | 'c' to continue | 'r' to refresh]: 1 //輸入1設置主機名,<Enter>回車 [anaconda] 1:main* 2:shell 3:log 4:storage-lo> Switch tab: Alt+Tab | Help: F1 //出現以下頁面 ================================================================================ ================================================================================ Enter new value for 'Host name' and press enter kvm-CentOS7.5 //注意只能使用大小寫字母、數值、減號、小數點,而且不能以減號開頭或結尾 [anaconda] 1:main* 2:shell 3:log 4:storage-lo> Switch tab: Alt+Tab | Help: F1 //設置完成後,回到以前的界面 ================================================================================ ================================================================================ Network configuration Wired (eth0) disconnected Host name: kvm-CentOS7.5 //能夠看到主機名改了 Current host name: localhost 1) Set host name 2) Configure device eth0 Please make your choice from above ['q' to quit | 'c' to continue | 'r' to refresh]: 2 //輸入2設置eth0網卡設備,<Enter>回車 [anaconda] 1:main* 2:shell 3:log 4:storage-lo> Switch tab: Alt+Tab | Help: F1 //出現以下頁面 ================================================================================ ================================================================================ Device configuration 1) IPv4 address or "dhcp" for DHCP dhcp 2) IPv4 netmask 3) IPv4 gateway 4) IPv6 address[/prefix] or "auto" for automatic, "dhcp" for DHCP, "ignore" to turn off auto 5) IPv6 default gateway 6) Nameservers (comma separated) 7) [ ] Connect automatically after reboot 8) [ ] Apply configuration in installer Configuring device eth0. Please make your choice from above ['q' to quit | 'c' to continue | 'r' to refresh]: //太多了,我這裏整合一下 [anaconda] 1:main* 2:shell 3:log 4:storage-lo> Switch tab: Alt+Tab | Help: F1 //輸入1設置IPv4地址,出現以下頁面 ================================================================================ ================================================================================ Enter new value for 'IPv4 address or "dhcp" for DHCP' and press enter 192.168.5.151 //輸入一個IPv4地址 [anaconda] 1:main* 2:shell 3:log 4:storage-lo> Switch tab: Alt+Tab | Help: F1 //輸入2設置子網掩碼,出現以下頁面 ================================================================================ ================================================================================ Enter new value for 'IPv4 netmask' and press enter 255.255.255.0 //輸入子網掩碼 [anaconda] 1:main* 2:shell 3:log 4:storage-lo> Switch tab: Alt+Tab | Help: F1 //輸入3設置IPv4網關,出現以下頁面 ================================================================================ ================================================================================ Enter new value for 'IPv4 gateway' and press enter 192.168.5.2 [anaconda] 1:main* 2:shell 3:log 4:storage-lo> Switch tab: Alt+Tab | Help: F1 //輸入6設置DNS服務器,出現以下頁面 ================================================================================ ================================================================================ Enter new value for 'Nameservers (comma separated)' and press enter 192.168.5.2 [anaconda] 1:main* 2:shell 3:log 4:storage-lo> Switch tab: Alt+Tab | Help: F1 //輸入7設置從新啓動後自動鏈接 //輸入8設置在安裝程序中應用配置 //最後設置完成的界面以下 ================================================================================ ================================================================================ Device configuration 1) IPv4 address or "dhcp" for DHCP 192.168.5.151 2) IPv4 netmask 255.255.255.0 3) IPv4 gateway 192.168.5.2 4) IPv6 address[/prefix] or "auto" for automatic, "dhcp" for DHCP, "ignore" to turn off auto 5) IPv6 default gateway 6) Nameservers (comma separated) 192.168.5.2 7) [x] Connect automatically after reboot 8) [x] Apply configuration in installer Configuring device eth0. Please make your choice from above ['q' to quit | 'c' to continue | 'r' to refresh]: c //輸入c繼續,<Enter>回車 [anaconda] 1:main* 2:shell 3:log 4:storage-lo> Switch tab: Alt+Tab | Help: F1 //回到上一個界面 ================================================================================ ================================================================================ Network configuration Wired (eth0) connected IPv4 Address: 192.168.5.151 Netmask: 255.255.255.0 Gateway: 192.168.5.2 DNS: 192.168.5.2 //網絡信息 Host name: kvm-CentOS7.5 //主機名 Current host name: localhost 1) Set host name 2) Configure device eth0 Please make your choice from above ['q' to quit | 'c' to continue | 'r' to refresh]: c //輸入c繼續,<Enter>回車 [anaconda] 1:main* 2:shell 3:log 4:storage-lo> Switch tab: Alt+Tab | Help: F1 //回到菜單設置頁面 ================================================================================ ================================================================================ Installation 1) [x] Language settings 2) [x] Time settings (Simplified Chinese (China)) (Asia/Shanghai timezone) 3) [x] Installation source 4) [!] Software selection (Local media) (Source changed - please 5) [x] Installation Destination verify) (Automatic partitioning 6) [x] Kdump selected) (Kdump is enabled) 7) [x] Network configuration 8) [x] Root password (Wired (eth0) connected) (Password is set.) 9) [ ] User creation (No user will be created) Please make your choice from above ['q' to quit | 'b' to begin installation | 'r' to refresh]: 4 //輸入4軟件選擇,<Enter>回車。見鬼4怎麼變了,跑一下吧 [anaconda] 1:main* 2:shell 3:log 4:storage-lo> Switch tab: Alt+Tab | Help: F1 //出現以下頁面 ================================================================================ ================================================================================ Base environment Software selection Base environment 1) [x] Minimal Install 7) [ ] Server with GUI 2) [ ] Compute Node 8) [ ] GNOME Desktop 3) [ ] Infrastructure Server 9) [ ] KDE Plasma Workspaces 4) [ ] File and Print Server 10) [ ] Development and Creative 5) [ ] Basic Web Server Workstation 6) [ ] Virtualization Host Please make your choice from above ['q' to quit | 'c' to continue | 'r' to refresh]: c //就用最小化安裝。輸入c繼續,<Enter>回車 [anaconda] 1:main* 2:shell 3:log 4:storage-lo> Switch tab: Alt+Tab | Help: F1 //回到設置菜單頁面 ================================================================================ ================================================================================ Installation 1) [x] Language settings 2) [x] Time settings (Simplified Chinese (China)) (Asia/Shanghai timezone) 3) [!] Installation source 4) [!] Software selection (Processing...) (Processing...) 5) [x] Installation Destination 6) [x] Kdump (Automatic partitioning (Kdump is enabled) selected) 8) [x] Root password 7) [x] Network configuration (Password is set.) (Wired (eth0) connected) 9) [ ] User creation (No user will be created) Please make your choice from above ['q' to quit | 'b' to begin installation | 'r' to refresh]: r //正在加載等一下子,輸入r刷新一下,<Enter>回車 [anaconda] 1:main* 2:shell 3:log 4:storage-lo> Switch tab: Alt+Tab | Help: F1 //再看設置菜單頁面 ================================================================================ ================================================================================ Installation 1) [x] Language settings 2) [x] Time settings (Simplified Chinese (China)) (Asia/Shanghai timezone) 3) [x] Installation source 4) [x] Software selection (Local media) (Minimal Install) 5) [x] Installation Destination 6) [x] Kdump (Automatic partitioning (Kdump is enabled) selected) 8) [x] Root password 7) [x] Network configuration (Password is set.) (Wired (eth0) connected) 9) [ ] User creation (No user will be created) Please make your choice from above ['q' to quit | 'b' to begin installation | 'r' to refresh]: b //正常了,輸入b開始安裝,<Enter>回車 [anaconda] 1:main* 2:shell 3:log 4:storage-lo> Switch tab: Alt+Tab | Help: F1 //下面就等待安裝,時間會比較長,請耐心等待。最後會出現 Use of this product is subject to the license agreement found at /usr/share/centos-release/EULA Installation complete. Press return to quit //這裏按回車 //而後會出現一堆中止或關閉參數,不用管他,這是虛擬機在關閉。最後還會出現一個報錯,以下 誤:操做失敗: 這個域有活躍控制檯會話 //這個報錯是沒有關係的,代表這個虛擬關機了
查看一下新建的centos75虛擬機,以及默認鏡像格式
[root@youxi1 ~]# virsh list --all Id 名稱 狀態 ---------------------------------------------------- 2 centos75 running - centos7.0 關閉 [root@youxi1 ~]# qemu-img info /var/lib/libvirt/images/centos75.img image: /var/lib/libvirt/images/centos75.img file format: qcow2 //默認格式就是qcow2的,因此我沒有先建立系統鏡像 virtual size: 10G (10737418240 bytes) disk size: 1.3G cluster_size: 65536 Format specific information: compat: 1.1 lazy refcounts: true
啓動了,那麼咱們使用遠程工具鏈接一下試試
----->---->----->
能夠看到是成功鏈接了,隨便輸入個命令試試
[root@kvm-CentOS7 ~]# ip a sh 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 link/ether 52:54:00:71:3c:50 brd ff:ff:ff:ff:ff:ff inet 192.168.5.151/24 brd 192.168.5.255 scope global noprefixroute eth0 valid_lft forever preferred_lft forever inet6 fe80::4bf9:e184:aff2:ec5f/64 scope link noprefixroute valid_lft forever preferred_lft forever
上面是直連KVM虛擬機,但有時候會須要從物理機上進入KVM虛擬機,以下。但這有一個問題,我不知道怎麼從KVM虛擬機上回到物理,除了關機。因此我建議使用遠程軟件連入物理機,再進入KVM虛擬機,使用完成後關閉窗口便可。
[root@youxi1 ~]# virsh console centos75 //此時是物理機 鏈接到域 centos75 換碼符爲 ^] quit 密碼: Login incorrect kvm-CentOS7 login: root 密碼: Last login: Mon Sep 9 09:25:33 on ttyS0 [root@kvm-CentOS7 ~]# //進入到KVM虛擬機
(6).擴展:
1)KVM虛擬機管理經常使用命令
virsh list查看正在運行的虛擬機,virsh list --all
[root@youxi1 ~]# virsh list --all Id 名稱 狀態 ---------------------------------------------------- - centos7.0 關閉 [root@youxi1 ~]# virsh list Id 名稱 狀態 ----------------------------------------------------
virsh start [虛擬機名稱]啓動虛擬機,virsh shutdown [虛擬機名稱]關閉虛擬機,virsh autostart [虛擬機名稱]設置虛擬機隨物理機啓動,virsh autostart --disable [虛擬機名稱]取消虛擬機隨物理機啓動。注意:使用virsh autostart [虛擬機名稱]時,請確保KVM虛擬機服務(服務名爲libvirtd)開機啓動。
[root@youxi1 ~]# virsh start centos7.0 域 centos7.0 已開始 [root@youxi1 ~]# virsh list Id 名稱 狀態 ---------------------------------------------------- 1 centos7.0 running [root@youxi1 ~]# virsh shutdown centos7.0 域 centos7.0 被關閉 [root@youxi1 ~]# virsh list --all Id 名稱 狀態 ---------------------------------------------------- - centos7.0 關閉 [root@youxi1 ~]# systemctl is-enabled libvirtd enabled [root@youxi1 ~]# virsh autostart centos7.0 域 centos7.0標記爲自動開始 [root@youxi1 ~]# virsh autostart --disable centos7.0 域 centos7.0取消標記爲自動開始
2)KVM虛擬機建立命令
virt-install --name [虛擬機名稱] --memory [內存分配] [options]
經常使用選項:
--virt-type [管理程序名稱] 使用的管理程序名稱,取代了之前的--accelerate選項,包含kvm、qemu、xen等 -n [虛擬機名稱],--name [虛擬機名稱] 指定虛擬機名稱 --memory [內存分配] 指定內存大小分配 例如:--memory 1024 (in MiB) --memory 512,maxmemory=1024 --memory 512,maxmemory=1024,hotplugmemorymax=2048,hotplugmemoryslots=2 --vcpus [CPU分配] 指定虛擬CPU數量 例如:--vcpus 5 --vcpus 5,maxcpus=10,cpuset=1-4,6,8 --vcpus sockets=2,cores=4,threads=2 --disk [存儲分配] 指定虛擬機磁盤存儲文件路徑 例如:--disk size=10 (在默認位置建立 10GiB 鏡像) --disk /my/existing/disk,cache=none --disk device=cdrom,bus=scsi --disk=? --cdrom [光盤鏡像] 指定安裝系統的光盤鏡像 -l [系統鏡像],--location [系統鏡像] 這個鏡像能夠是網絡,也能夠是本地 例如:nfs:host:/path, http://host/path,ftp://host/path -w [網絡接口],--network [網絡接口] 指定虛擬機的網絡接口 例如: --network bridge=mybr0 --network network=my_libvirt_virtual_net --network network=mynet,model=virtio,mac=00:11... --network none --network help -x [額外參數],--extra-args [額外參數] 將附加參數添加到--location引導的內核中,提供額外的內核命令行參數,好比用於無人值守安裝
3)VMware遷移到KVM
須要安裝virt-v2v,命令yum -y install virt-v2v