天天看點

Centos7搭建 KVM 指令行安裝虛拟機

[toc]

作者:sre運維部落格 部落格位址: https://www.cnsre.cn/ 文章位址:https://www.cnsre.cn/posts/211105852095/ 相關話題:https://www.cnsre.cn/tags/kvm/ 本文将介紹centos7 環境如何搭建一個kvm 環境并且建立windows,linux等虛拟機。

如果結果中有vmx(intel)或svm(amd)字樣,就說明cpu的支援的。

Centos7搭建 KVM 指令行安裝虛拟機

将<code>/etc/sysconfig/selinux</code> 中的 <code>selinux=enforcing</code> 修改為 <code>selinux=disabled</code>

Centos7搭建 KVM 指令行安裝虛拟機

可選項,因為我是剛安裝好的centos,是以為了下面友善點,先把一些必要的工具安裝下

Centos7搭建 KVM 指令行安裝虛拟機
Centos7搭建 KVM 指令行安裝虛拟機

下圖說明已經成功安裝了

Centos7搭建 KVM 指令行安裝虛拟機

并且設定其開機自動啟動

如下圖所示,說明運作情況良好

Centos7搭建 KVM 指令行安裝虛拟機
Centos7搭建 KVM 指令行安裝虛拟機

先将 <code>/etc/sysconfig/network-scripts/</code> 目錄下的網卡配置檔案備份一份

建立的 <code>br0</code>檔案的ip位址要和實體網卡的ip位址一緻,指令 <code>ipconfig</code> 檢視實體網卡将不會顯示<code>ip</code>

内容如下:

使用 <code>ifconfig</code> 驗證操作結果,多了一塊網卡 <code>br0</code> ,現在通路主控端 使用 <code>192.168.1.130</code> 就可以了。

Centos7搭建 KVM 指令行安裝虛拟機

在本文中将使用和宿主環境一樣的 <code>centos7.2</code>,把該檔案放到 <code>/home/iso</code> 目錄下

挂載u盤

Centos7搭建 KVM 指令行安裝虛拟機

執行完這段指令

感歎号為待選項

c儲存 q退出 b開始執行安裝

Centos7搭建 KVM 指令行安裝虛拟機

選擇地區時間

Centos7搭建 KVM 指令行安裝虛拟機
Centos7搭建 KVM 指令行安裝虛拟機
Centos7搭建 KVM 指令行安裝虛拟機
Centos7搭建 KVM 指令行安裝虛拟機

選則之後c儲存

Centos7搭建 KVM 指令行安裝虛拟機

自動傳回首頁面

Centos7搭建 KVM 指令行安裝虛拟機

選擇硬碟

Centos7搭建 KVM 指令行安裝虛拟機

選擇到硬碟 c儲存

Centos7搭建 KVM 指令行安裝虛拟機

全新安裝 c儲存

Centos7搭建 KVM 指令行安裝虛拟機

選則添加ip位址和添加主機名稱

Centos7搭建 KVM 指令行安裝虛拟機
Centos7搭建 KVM 指令行安裝虛拟機

輸入 回車

Centos7搭建 KVM 指令行安裝虛拟機

添加ip位址

Centos7搭建 KVM 指令行安裝虛拟機

選則ipv4

Centos7搭建 KVM 指令行安裝虛拟機

添加ip位址回車

Centos7搭建 KVM 指令行安裝虛拟機

添加netmask gateway c 儲存

Centos7搭建 KVM 指令行安裝虛拟機

添加密碼

Centos7搭建 KVM 指令行安裝虛拟機

b開始執行安裝

Centos7搭建 KVM 指令行安裝虛拟機

安裝完成

Centos7搭建 KVM 指令行安裝虛拟機

主控端直接連接配接到虛拟機

Centos7搭建 KVM 指令行安裝虛拟機
Centos7搭建 KVM 指令行安裝虛拟機

等待重新開機虛拟機,虛拟機起開之後直接遠端就ok了 。

(虛拟機需要先關閉)

Centos7搭建 KVM 指令行安裝虛拟機

克隆完檢視 所有的虛拟機以及狀态

Centos7搭建 KVM 指令行安裝虛拟機

删除虛拟機 <code>njvm01</code>

{{&lt; alert theme="warning" dir="ltr" &gt;}}

⚠️ 注意

取消定義 删除以後要找到虛拟機檔案路徑吧虛拟機檔案也删除掉

{{&lt; /alert &gt;}}

Centos7搭建 KVM 指令行安裝虛拟機
Centos7搭建 KVM 指令行安裝虛拟機

克隆完以後因為<code>ip</code>位址還是<code>njvm01</code>的ip位址是以我們要修改ip位址

開啟我們克隆的虛拟機

遠端登陸上去

Centos7搭建 KVM 指令行安裝虛拟機
Centos7搭建 KVM 指令行安裝虛拟機

<code>ipaddr=192.168.1.121</code> 改為我們想要的ip位址

儲存退出

<code>service network restart</code>

重新開機網絡

重新連結

參考文檔:

http://www.linuxidc.com/linux/2017-01/140007.htm

http://blog.csdn.net/u011414200/article/details/47310827

https://www.cnblogs.com/5201351/p/4445199.html

http://blog.51cto.com/7834466/2064277

https://www.cnblogs.com/yemilice/p/8080688.html

繼續閱讀