常用虛擬化技術(shù)
vmware(收費,企業(yè)版 esxi )
https://www.proxmox.com/en/proxmox-ve
redhat kvm rhev
虛擬化平臺
1、查看是否支持虛擬化
[root@localhost ~]# grep -P "vmx|svm" /proc/cpuinfo
flags : ... ... vmx
[root@localhost ~]# lsmod |grep kvm
kvm_intel 174841 6
kvm 578518 1 kvm_intel
irqbypass 13503 1 kvm
2恢共、創(chuàng)建虛擬機 2cpu魏保,4G內(nèi)存(默認用戶名: root 密碼: a)
這里是linux系統(tǒng)主機,提前寫好的腳本文件,直接創(chuàng)建好一臺虛擬機即可
[root@localhost ~]# base-vm create ecs
vm ecs create [ OK ]
[root@localhost ~]#
3撑柔、驗證 yum 倉庫的配置
[root@localhost ~]# yum makecache
[root@localhost ~]# yum repolist
4、安裝 libvirtd
[root@localhost ~]# yum install -y qemu-kvm \
libvirt-daemon \
libvirt-daemon-driver-qemu \
libvirt-client
[root@localhost ~]# systemctl enable --now libvirtd
[root@localhost ~]# virsh version
虛擬機組成
硬盤文件 /var/lib/libvirt/images/
配置文件 /etc/libvirt/qemu/
虛擬化實驗圖例
Linux虛擬機
虛擬機硬盤磁盤文件
COW圖例
上傳 cirros.qcow2 到虛擬機
通過 qemu-img 創(chuàng)建虛擬機磁盤
命令格式: qemu-img 子命令 子命令參數(shù) 虛擬機磁盤文件 大小
[root@localhost ~]# cp cirros.qcow2 /var/lib/libvirt/images/
[root@localhost ~]# cd /var/lib/libvirt/images/
[root@localhost ~]# qemu-img create -f qcow2 -b cirros.qcow2 vmhost.img 30G
[root@localhost ~]# qemu-img info vmhost.img #查看信息
虛擬網(wǎng)絡(luò)配置
虛擬網(wǎng)絡(luò)管理命令
命令 | 說明 |
---|---|
virsh net-list [--all] | 列出虛擬網(wǎng)絡(luò) |
virsh net-start | 啟動虛擬交換機 |
virsh net-destroy | 強制停止虛擬交換機 |
virsh net-define | 根據(jù)xml文件創(chuàng)建虛擬網(wǎng)絡(luò) |
virsh net-undefine | 刪除一個虛擬網(wǎng)絡(luò)設(shè)備 |
virsh net-edit | 修改虛擬交換機的配置 |
virsh net-autostart | 設(shè)置開機自啟動 |
創(chuàng)建配置文件 /etc/libvirt/qemu/networks/vbr.xml
[root@localhost ~]# vim /etc/libvirt/qemu/networks/vbr.xml
<network>
<name>vbr</name>
<forward mode='nat'/>
<bridge name='vbr' stp='on' delay='0'/>
<ip address='192.168.100.254' netmask='255.255.255.0'>
<dhcp>
<range start='192.168.100.100' end='192.168.100.200'/>
</dhcp>
</ip>
</network>
創(chuàng)建虛擬交換機
[root@localhost ~]# cd /etc/libvirt/qemu/networks/
[root@localhost ~]# virsh net-define vbr.xml
[root@localhost ~]# virsh net-start vbr
[root@localhost ~]# virsh net-autostart vbr
[root@localhost ~]# ifconfig # 查看驗證
虛擬機管理命令
命令 | 說明 |
---|---|
virsh list [--all] | 列出虛擬機 |
virsh start/shutdown | 啟動/關(guān)閉虛擬機 |
virsh destroy | 強制停止虛擬機 |
virsh define/undefine | 創(chuàng)建/刪除虛擬機 |
virsh ttyconsole | 顯示終端設(shè)備 |
virsh console | 連接虛擬機的 console |
virsh edit | 修改虛擬機的配置 |
virsh autostart | 設(shè)置虛擬機自啟動 |
virsh dominfo | 查看虛擬機摘要信息 |
virsh domiflist | 查看虛擬機網(wǎng)卡信息 |
virsh domblklist | 查看虛擬機硬盤信息 |
虛擬機配置文件
官方文檔地址 https://libvirt.org/format.html
1您访、拷貝 node_base.xml 到虛擬機中
2铅忿、拷貝 node_base.xml 到 /etc/libvirt/qemu/虛擬機名字.xml
3、修改配置文件灵汪,啟動運行虛擬機
[root@localhost ~]# cp node_base.xml /etc/libvirt/qemu/vmhost.xml
[root@localhost ~]# vim /etc/libvirt/qemu/vmhost.xml
2: <name>vmhost</name>
3: <memory unit='KB'>1024000</memory>
4: <currentMemory unit='KB'>1024000</currentMemory>
5: <vcpu placement='static'>2</vcpu>
26: <source file='/var/lib/libvirt/images/vmhost.img'/>
創(chuàng)建虛擬機:
[root@localhost ~]# virsh list
[root@localhost ~]# virsh define /etc/libvirt/qemu/vmhost.xml
[root@localhost ~]# virsh start vmhost
[root@localhost ~]# virsh console vmhost # 兩次回車
退出使用 ctrl + ]