日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

Libvirt安装

發(fā)布時(shí)間:2023/12/20 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Libvirt安装 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

目錄

建立在上一章的基礎(chǔ)上

一、Libvirt安裝與配置

1.修改/etc/selinux/config 文件

2.配置yum源為阿里源

3.清理yum源

4.重新生成新緩存?

5.檢查系統(tǒng)是否安裝?libvirt,qemu

6.檢查kvm模塊是否被系統(tǒng)加載

7.安裝qemu及l(fā)ibvirt?

8.配置/etc/libvirt/libvirt.conf

9.重啟服務(wù)并連接

10.配置/etc/libvirt/libvirtd.conf

10.映射

11.測(cè)試

二、使用virsh創(chuàng)建虛擬機(jī)

1.創(chuàng)建虛擬機(jī)硬盤(pán)

2.傳輸centos7-1-init.xml并編輯

3.修改/etc/libvirt/qemu.conf ,在末尾插入

4.重啟服務(wù)

5.創(chuàng)建虛擬機(jī)

6.進(jìn)入centos,連接虛擬機(jī)

7.安裝虛擬機(jī)至重啟頁(yè)面

8.不要重啟虛擬機(jī),直接關(guān)閉虛擬機(jī)(ctrl+c),并將centos7-1-init.xml文件啟動(dòng)方式更改

9.重新創(chuàng)建虛擬機(jī)?

10.重新進(jìn)入虛擬機(jī)、

三、virsh管理

1.查看域(虛擬機(jī))列表

2.查看域的基本信息

3.設(shè)置域的內(nèi)存大小

4.查看域的 vCPU基本信息

5.將域的vCPU綁定到物理CPU上運(yùn)行(把2號(hào)機(jī)器的0號(hào)vcpu綁定到宿主機(jī)0號(hào)CPU上)

6.暫停域

7.喚醒域

8.讓域關(guān)機(jī)

9.保存域的狀態(tài)到文件中,而后被關(guān)閉

10.從文件中恢復(fù)域的運(yùn)行

11.以xml格式轉(zhuǎn)存域的信息到標(biāo)準(zhǔn)輸出

12.向域添加硬盤(pán),使用qemu-img制作虛擬機(jī)硬盤(pán),并附著到虛擬機(jī)上


建立在上一章的基礎(chǔ)上

一、Libvirt安裝與配置

1.修改/etc/selinux/config 文件

2.配置yum源為阿里源

[root@localhost ~]# rm -rf /etc/yum.repos.d/*
[root@localhost ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo ?
? % Total ? ?% Received % Xferd ?Average Speed ? Time ? ?Time ? ? Time ?Current
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Dload ?Upload ? Total ? Spent ? ?Left ?Speed
100 ?2523 ?100 ?2523 ? ?0 ? ? 0 ?26225 ? ? ?0 --:--:-- --:--:-- --:--:-- 26557

3.清理yum源

yum clean all?

4.重新生成新緩存?

yum makecache

5.檢查系統(tǒng)是否安裝?libvirt,qemu

[root@localhost ~]# rpm -q libvirt
未安裝軟件包 libvirt?
[root@localhost ~]# rpm -q qemu
未安裝軟件包 qemu?

6.檢查kvm模塊是否被系統(tǒng)加載

[root@localhost ~]# lsmod |grep kvm
kvm_intel ? ? ? ? ? ? 188740 ?0?
kvm ? ? ? ? ? ? ? ? ? 637289 ?1 kvm_intel
irqbypass ? ? ? ? ? ? ?13503 ?1 kvm

7.安裝qemu及l(fā)ibvirt?

yum install -y qemu-kvm libvirt

8.配置/etc/libvirt/libvirt.conf

uri_aliases = [
? "hail=qemu+ssh://root@hail.cloud.example.com/system",
? "sleet=qemu+ssh://root@sleet.cloud.example.com/system",
? "remote=qemu+ssh://root@192.168.100.130/system",
]

9.重啟服務(wù)并連接

[root@localhost ~]# systemctl restart libvirtd
[root@localhost ~]# virsh -c remote
The authenticity of host '192.168.100.130 (192.168.100.130)' can't be established.
ECDSA key fingerprint is SHA256:Zc5Cgp78zu5A/YgncnLyIoNlA8NAaq/B9y+uwRhzBQw.
ECDSA key fingerprint is MD5:d4:e6:c5:c5:84:7c:c4:c6:23:56:66:7b:46:5b:45:8a.
Are you sure you want to continue connecting (yes/no)? yes
root@192.168.100.130's password:?
歡迎使用 virsh,虛擬化的交互式終端。

輸入:'help' 來(lái)獲得命令的幫助信息
? ? ? ?'quit' 退出

virsh #?

10.配置/etc/libvirt/libvirtd.conf

將如下內(nèi)容找出并在配置文件中把注釋取消并修改

listen_tls = 0
listen_tcp = 1
tcp_port = "16509"
unix_sock_dir = "/var/run/libvirt"
auth_tcp = "none"?

?

?

[root@localhost ~]# cat /etc/libvirt/libvirtd.conf |egrep -v "^#|^$"
listen_tls = 0
listen_tcp = 1
tcp_port = "16509"
unix_sock_dir = "/var/run/libvirt"
auth_tcp = "none"??

10.映射

[root@localhost ~]# hostnamectl set-hostname master
[root@localhost ~]# bash

進(jìn)入/etc/hosts配置

11.測(cè)試

[root@master ~]# libvirtd --listen -d
libvirtd:錯(cuò)誤:Unable to obtain pidfile。查看 /var/log/messages 或者運(yùn)行不帶 --daemon 的命令查看更多信息。
[root@master ~]# rm -rf /run/libvirtd.pid?
[root@master ~]# libvirtd --listen -d
[root@master ~]# virsh -c qemu+tcp://localhost:16509/system
歡迎使用 virsh,虛擬化的交互式終端。

輸入:'help' 來(lái)獲得命令的幫助信息
? ? ? ?'quit' 退出

virsh # quit

二、使用virsh創(chuàng)建虛擬機(jī)

1.創(chuàng)建虛擬機(jī)硬盤(pán)

[root@master ~]# qemu-img create -f qcow2 /opt/cent7.qcow2 20g
Formatting '/opt/cent7.qcow2', fmt=qcow2 size=21474836480 encryption=off cluster_size=65536 lazy_refcounts=off?
[root@master ~]# ll CentOS-7-x86_64-Everything-2009.iso?
-rw-r--r--. 1 root root 10200547328 9月 ? 8 09:28 CentOS-7-x86_64-Everything-2009.iso

2.傳輸centos7-1-init.xml并編輯

?

<domain type='kvm'><name>centos7-1</name><memory>1048576</memory><currentMemory>1048576</currentMemory><vcpu>1</vcpu><os><type arch='x86_64' machine='pc-i440fx-rhel7.0.0'>hvm</type><boot dev='cdrom'/></os><features><acpi/><apic/><pae/></features><clock offset='localtime'/><on_poweroff>destroy</on_poweroff><on_reboot>restart</on_reboot><on_crash>destroy</on_crash><devices><emulator>/usr/libexec/qemu-kvm</emulator><disk type='file' device='disk'><driver name='qemu' type='qcow2'/><source file='/opt/cent7.qcow2'/> <target dev='hda' bus='ide'/></disk><disk type='file' device='cdrom'><source file='/root/CentOS-7-x86_64-Everything-2009.iso'/><target dev='hdb' bus='ide'/></disk><interface type='network'><source network='default' bridge='virbr0'/><mac address="00:16:3e:5d:aa:a8"/></interface><input type='mouse' bus='ps2'/><input type='tablet' bus='usb'/><input type='keyboard' bus='ps2'/><graphics type='vnc' port='5905' autoport='no' listen = '0.0.0.0' keymap='en-us'/></devices> </domain>

3.修改/etc/libvirt/qemu.conf ,在末尾插入

user?=?"root"
grout?=?"root"
dynamic_ownership?=?0

4.重啟服務(wù)

systemctl restart libvirtd

5.創(chuàng)建虛擬機(jī)

[root@master ~]# virsh define /opt/centos7-1-init.xml?
定義域 centos7-1(從 /opt/centos7-1-init.xml)

[root@master ~]# virsh list --all
?Id ? ?名稱(chēng) ? ? ? ? ? ? ? ? ? ? ? ? 狀態(tài)
----------------------------------------------------
?- ? ? centos7-1 ? ? ? ? ? ? ? ? ? ? ?關(guān)閉
[root@master ~]# virsh start centos7-1?
域 centos7-1 已開(kāi)始

[root@master ~]# virsh start centos7-1?
域 centos7-1 已開(kāi)始

[root@master ~]# virsh list --all
?Id ? ?名稱(chēng) ? ? ? ? ? ? ? ? ? ? ? ? 狀態(tài)
----------------------------------------------------
?1 ? ? centos7-1 ? ? ? ? ? ? ? ? ? ? ?running

6.進(jìn)入centos,連接虛擬機(jī)

7.安裝虛擬機(jī)至重啟頁(yè)面

?

8.不要重啟虛擬機(jī),直接關(guān)閉虛擬機(jī)(ctrl+c),并將centos7-1-init.xml文件啟動(dòng)方式更改

?

??<boot dev='hd'/>

9.重新創(chuàng)建虛擬機(jī)?

[root@master ~]# vim /opt/centos7-1-init.xml?
[root@master ~]#?
[root@master ~]# virsh define /opt/centos7-1-init.xml?
定義域 centos7-1(從 /opt/centos7-1-init.xml)

[root@master ~]# virsh list --all
?Id ? ?名稱(chēng) ? ? ? ? ? ? ? ? ? ? ? ? 狀態(tài)
----------------------------------------------------
?- ? ? centos7-1 ? ? ? ? ? ? ? ? ? ? ?關(guān)閉

[root@master ~]# virsh start centos7-1?
域 centos7-1 已開(kāi)始

10.重新進(jìn)入虛擬機(jī)、

三、virsh管理

1.查看域(虛擬機(jī))列表

[root@master ~]# virsh list --all
?Id ? ?名稱(chēng) ? ? ? ? ? ? ? ? ? ? ? ? 狀態(tài)
----------------------------------------------------
?2 ? ? centos7-1 ? ? ? ? ? ? ? ? ? ? ?running

2.查看域的基本信息

[root@master ~]# virsh dominfo 2
Id: ? ? ? ? ? ? 2
名稱(chēng): ? ? ? centos7-1
UUID: ? ? ? ? ? d5fb2624-d259-42e1-98d8-40955bddb76c
OS 類(lèi)型: ? ?hvm
狀態(tài): ? ? ? running
CPU: ? ? ? ? ?1
CPU 時(shí)間: ? 492.4s
最大內(nèi)存: 1048576 KiB
使用的內(nèi)存: 1048576 KiB
持久: ? ? ? 是
自動(dòng)啟動(dòng): 禁用
管理的保存: 否
安全性模式: selinux
安全性 DOI: 0
安全性標(biāo)簽: system_u:system_r:svirt_t:s0:c718,c977 (enforcing)

3.設(shè)置域的內(nèi)存大小

virsh setmem 2? 51200

4.查看域的 vCPU基本信息

[root@master ~]# virsh vcpuinfo 2?
VCPU: ? ? ? ? ? 0
CPU: ? ? ? ? ? ?0
狀態(tài): ? ? ? running
CPU 時(shí)間: ? 683.5s
CPU關(guān)系: ? ? ?y

5.將域的vCPU綁定到物理CPU上運(yùn)行(把2號(hào)機(jī)器的0號(hào)vcpu綁定到宿主機(jī)0號(hào)CPU上)

[root@master ~]# virsh list --all
?Id ? ?名稱(chēng) ? ? ? ? ? ? ? ? ? ? ? ? 狀態(tài)
----------------------------------------------------
?2 ? ? centos7-1 ? ? ? ? ? ? ? ? ? ? ?running
[root@master ~]# virsh vcpupin 2 0 0

6.暫停域

[root@master ~]# virsh start centos7-1
域 centos7-1 已開(kāi)始

[root@master ~]# virsh list --all
?Id ? ?名稱(chēng) ? ? ? ? ? ? ? ? ? ? ? ? 狀態(tài)
----------------------------------------------------
?2? ? ?centos7-1 ? ? ? ? ? ? ? ? ? ? ?running
[root@master ~]# virsh suspend 2
域 2?被掛起
[root@master ~]# virsh list --all
?Id ? ?名稱(chēng) ? ? ? ? ? ? ? ? ? ? ? ? 狀態(tài)
----------------------------------------------------
?2? ? centos7-1 ? ? ? ? ? ? ? ? ? ? ?暫停

7.喚醒域

[root@master ~]# virsh resume 2
域 2?被重新恢復(fù)

[root@master ~]# virsh list --all
?Id ? ?名稱(chēng) ? ? ? ? ? ? ? ? ? ? ? ? 狀態(tài)
----------------------------------------------------
?2? ? ?centos7-1 ? ? ? ? ? ? ? ? ? ? ?running

8.讓域關(guān)機(jī)

[root@master ~]# virsh shutdown 2
域 2?被關(guān)閉

9.保存域的狀態(tài)到文件中,而后被關(guān)閉

[root@master ~]# virsh list --all
?Id ? ?名稱(chēng) ? ? ? ? ? ? ? ? ? ? ? ? 狀態(tài)
----------------------------------------------------
?2?? ? centos7-1 ? ? ? ? ? ? ? ? ? ? ?running

[root@master ~]# virsh shutdown 2
域 2?被關(guān)閉

[root@master ~]# virsh list --all
?Id ? ?名稱(chēng) ? ? ? ? ? ? ? ? ? ? ? ? 狀態(tài)
----------------------------------------------------
?2? ? ?centos7-1 ? ? ? ? ? ? ? ? ? ? ?running

[root@master ~]# virsh save 2?cent.img

保存到 2?的域 cent.img?

[root@master ~]# virsh list --all
?Id ? ?名稱(chēng) ? ? ? ? ? ? ? ? ? ? ? ? 狀態(tài)
----------------------------------------------------
?- ? ? centos7-1 ? ? ? ? ? ? ? ? ? ? ?關(guān)閉

10.從文件中恢復(fù)域的運(yùn)行

[root@master ~]# virsh restore cent.img?
從 cent.img 恢復(fù)域

[root@master ~]# virsh list --all
?Id ? ?名稱(chēng) ? ? ? ? ? ? ? ? ? ? ? ? 狀態(tài)
----------------------------------------------------
?3? ? ?centos7-1 ? ? ? ? ? ? ? ? ? ? ?running

11.以xml格式轉(zhuǎn)存域的信息到標(biāo)準(zhǔn)輸出


[root@master ~]# virsh dumpxml 3
<domain type='kvm' id='3'>
? <name>centos7-1</name>
? <uuid>d5fb2624-d259-42e1-98d8-40955bddb76c</uuid>
? <memory unit='KiB'>1048576</memory>
? <currentMemory unit='KiB'>1048576</currentMemory>
? <vcpu placement='static'>1</vcpu>
????........

12.向域添加硬盤(pán),使用qemu-img制作虛擬機(jī)硬盤(pán),并附著到虛擬機(jī)上

[root@master ~]# qemu-img create -f raw vda.img 10g
Formatting 'vda.img', fmt=raw size=10737418240?
[root@master ~]# virsh attach-disk 3?/root/vda.img vda
成功附加磁盤(pán)

登錄到虛擬機(jī)上查看

在登錄的虛擬機(jī)上為添加的硬盤(pán)創(chuàng)建文件系統(tǒng)并查看

mkfs.ext3 /dev/vda

mount /dev/vda? /mnt?

ls /mnt

df? -h

總結(jié)

以上是生活随笔為你收集整理的Libvirt安装的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。