07-13-周一_11-01-36
This commit is contained in:
@@ -132,7 +132,7 @@ kvm有良好的图形化支持,所以我们可以先装一下桌面组件
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
[root@localhost ~]# yum grouplist
|
[root@localhost ~]# yum grouplist
|
||||||
[root@localhost ~]# yum groupinstall -y "GNOME 桌面"
|
[root@localhost ~]# yum groupinstall -y "Server with GUI"
|
||||||
```
|
```
|
||||||
|
|
||||||
3. 启动图形化
|
3. 启动图形化
|
||||||
@@ -502,11 +502,11 @@ Formatting 'vm1-1.qcow2', fmt=qcow2 size=10737418240 encryption=off cluster_size
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
[root@localhost ~]# vim /etc/libvirt/qemu/vm1.xml
|
[root@localhost ~]# vim /etc/libvirt/qemu/vm1.xml
|
||||||
<disk type='file' device='disk'>
|
<disk type='volume' device='disk'>
|
||||||
<driver name='qemu' type='qcow2'/>
|
<driver name='qemu' type='qcow2' discard='unmap'/>
|
||||||
<source file='/var/lib/libvirt/images/vm1-1.qcow2'/>
|
<source pool='default' volume='ubuntu-22.04-1-1.qcow2'/>
|
||||||
<target dev='vdb' bus='virtio'/>
|
<target dev='vdb' bus='virtio'/>
|
||||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x17' function='0x0'/>
|
<address type='pci' domain='0x0000' bus='0x07' slot='0x00' function='0x0'/>
|
||||||
</disk>
|
</disk>
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -529,6 +529,12 @@ Formatting 'vm1-1.qcow2', fmt=qcow2 size=10737418240 encryption=off cluster_size
|
|||||||
连接到域 vm1
|
连接到域 vm1
|
||||||
换码符为 ^]
|
换码符为 ^]
|
||||||
|
|
||||||
|
# 如果没有输出的话,检查是否控制台输出到串口
|
||||||
|
# vim /etc/default/grub
|
||||||
|
# GRUB_CMDLINE_LINUX="console=tty0 console=ttyS0,115200n8"
|
||||||
|
# update-grub
|
||||||
|
# systemctl enable serial-getty@ttyS0.service
|
||||||
|
# reboot
|
||||||
|
|
||||||
CentOS Linux 7 (Core)
|
CentOS Linux 7 (Core)
|
||||||
Kernel 3.10.0-957.el7.x86_64 on an x86_64
|
Kernel 3.10.0-957.el7.x86_64 on an x86_64
|
||||||
@@ -547,6 +553,12 @@ vda 252:0 0 10G 0 disk
|
|||||||
vdb 252:16 0 10G 0 disk
|
vdb 252:16 0 10G 0 disk
|
||||||
```
|
```
|
||||||
|
|
||||||
|
- **在线热插盘**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
virsh attach-disk ubuntu-22.04-1 /var/lib/libvirt/images/ubuntu-22.04-1-1.qcow2 vdb --subdriver qcow2 --persistent
|
||||||
|
```
|
||||||
|
|
||||||
## CPU添加
|
## CPU添加
|
||||||
|
|
||||||
- 热添加的意思就是可以在虚拟机不重启的情况下,完成CPU的升级
|
- 热添加的意思就是可以在虚拟机不重启的情况下,完成CPU的升级
|
||||||
@@ -561,6 +573,10 @@ vdb 252:16 0 10G 0 disk
|
|||||||
<memory unit='KiB'>1048576</memory>
|
<memory unit='KiB'>1048576</memory>
|
||||||
<currentMemory unit='KiB'>1048576</currentMemory>
|
<currentMemory unit='KiB'>1048576</currentMemory>
|
||||||
<vcpu placement='auto' current='1'>4</vcpu> # 最大cpu使用4个,默认是1个
|
<vcpu placement='auto' current='1'>4</vcpu> # 最大cpu使用4个,默认是1个
|
||||||
|
# 改完这个配置后,必须要shutdown一下才可以生效
|
||||||
|
# 查看是否生效
|
||||||
|
[root@localhost ~]# virsh dumpxml ubuntu-22.04-1 | grep vcpu
|
||||||
|
<vcpu placement='auto' current='1'>4</vcpu>
|
||||||
[root@localhost ~]# virsh vcpucount vm1
|
[root@localhost ~]# virsh vcpucount vm1
|
||||||
最大值 配置 4
|
最大值 配置 4
|
||||||
当前 配置 1
|
当前 配置 1
|
||||||
@@ -826,43 +842,39 @@ virbr1 8000.525400a15e56 yes virbr1-nic
|
|||||||
|
|
||||||
<img src="KVM%E8%99%9A%E6%8B%9F%E5%8C%96%E6%8A%80%E6%9C%AF/%E6%A1%A5%E6%8E%A5%E7%BD%91%E7%BB%9C%E6%8B%93%E6%89%91.png" style="zoom:80%;" />
|
<img src="KVM%E8%99%9A%E6%8B%9F%E5%8C%96%E6%8A%80%E6%9C%AF/%E6%A1%A5%E6%8E%A5%E7%BD%91%E7%BB%9C%E6%8B%93%E6%89%91.png" style="zoom:80%;" />
|
||||||
|
|
||||||
可以为网卡添加网络接口
|
|
||||||
|
|
||||||
```bash
|
|
||||||
[root@localhost ~]# brctl delif virbr0 vnet0
|
|
||||||
[root@localhost ~]# brctl addif virbr0 vnet0
|
|
||||||
```
|
|
||||||
|
|
||||||
## 配置桥接网络
|
## 配置桥接网络
|
||||||
|
|
||||||
在宿主机上
|
在宿主机上,桥接自动获取IP地址
|
||||||
|
|
||||||
- 新建桥接网卡配置文件
|
- 注意,物理网卡在这样操作后,ens160就会被挂到br0桥下,原本ens160的IP地址会丢失,br0桥的虚拟接口会获得原本的IP。
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-br0
|
nmcli connection add type bridge ifname br0 con-name br0
|
||||||
TYPE=Bridge
|
nmcli connection modify br0 ipv4.method auto ipv6.method ignore
|
||||||
NAME=br0
|
|
||||||
DEVICE=br0
|
nmcli connection add type ethernet ifname ens160 con-name br0-slave-ens160 master br0
|
||||||
ONBOOT="yes"
|
|
||||||
BOOTPROTO=dhcp
|
nmcli connection modify ens160 connection.autoconnect no
|
||||||
|
nmcli connection modify br0-slave-ens160 no
|
||||||
|
|
||||||
|
nmcli connection down ens160
|
||||||
|
nmcli connection up br0
|
||||||
|
nmcli connection up br0-slave-ens160
|
||||||
```
|
```
|
||||||
|
|
||||||
- 修改宿主机网卡配置文件
|
- 检查配置,如果虚拟机网卡没有挂到br0下,可以手动操作
|
||||||
|
- 删除原本virbr0桥上的vnet0网卡`brctl delif virbr0 vnet0` , 加到br0的网桥上`brctl addif virbr0 vnet0`
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
[root@localhost ~]# cp /etc/sysconfig/network-scripts/ifcfg-ens33{,.old}
|
[root@localhost ~]# brctl show
|
||||||
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33
|
bridge name bridge id STP enabled interfaces
|
||||||
DEVICE="ens33"
|
br0 8000.000c292e48c6 yes ens160
|
||||||
ONBOOT="yes"
|
vnet3
|
||||||
BRIDGE=br0
|
docker0 8000.22698a118ebc no
|
||||||
|
virbr0 8000.525400b17117 yes vnet2
|
||||||
```
|
```
|
||||||
|
|
||||||
- 重启`libvirtd`和`network`服务
|
|
||||||
|
|
||||||
```bash
|
|
||||||
[root@localhost ~]# systemctl restart network libvirtd
|
|
||||||
```
|
|
||||||
|
|
||||||
- 修改虚拟机配置,然后启动虚拟机检查网络是否生效
|
- 修改虚拟机配置,然后启动虚拟机检查网络是否生效
|
||||||
|
|
||||||
@@ -882,13 +894,14 @@ BRIDGE=br0
|
|||||||
- 修改正常网卡的配置文件
|
- 修改正常网卡的配置文件
|
||||||
|
|
||||||
```
|
```
|
||||||
cd /etc/sysconfig/network-scripts/
|
nmcli connection down br0-slave-ens160
|
||||||
rm -rf ifcfg-br0
|
nmcli connection down br0
|
||||||
rm -rf ifcfg-ens33
|
nmcli connection delete br0-slave-ens160
|
||||||
mv ifcfg-ens33.old ifcfg-ens33
|
nmcli connection delete br0
|
||||||
```
|
|
||||||
|
|
||||||
- 重启系统
|
nmcli connection modify ens160 connection.autoconnect yes
|
||||||
|
nmcli connection up ens160
|
||||||
|
```
|
||||||
|
|
||||||
## 配置NAT网络
|
## 配置NAT网络
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user