学习笔记

Day77-云计算基础KVM虚拟化[下]

2019-11-28  本文已影响0人  三德书生

kvm虚拟机的桥接网络

默认的虚拟机网络是NAT模式,网段192.168.122.0/24

1:创建桥接网卡

创建桥接网卡命令 virsh iface-bridge eth0 br0 取消桥接网卡命令 virsh
iface-unbridge br0

2 新虚拟机使用桥接模式

默认NAT模式

virt-install --virt-type kvm --os-type=linux --os-variant rhel7 --name web04 --memory 1024 --vcpus 1 --disk /opt/web04.qcow2 --boot hd --network network=default --graphics vnc,listen=0.0.0.0 --noautoconsole

桥接模式

virt-install --virt-type kvm --os-type=linux --os-variant rhel7 --name web04 --memory 1024 --vcpus 1 --disk /opt/web04.qcow2 --boot hd --network bridge=br0 --graphics vnc,listen=0.0.0.0 --noautoconsole

问题1:
如果虚拟机获取不到ip地址:


2-1.png
3 将已有虚拟机网络修改为桥接模式

a:关机状态下修改虚拟机配置文件:
例如:virsh edit centos7

<interface type='bridge'>
<source bridge='br0'/>

b:启动虚拟机,测试虚拟机网络
如果上层没有开启dhcp,
需要手动配置ip地 址,IPADDR,NATMASK.GATEWAY,DNS1=180.76.76.76

echo 'TYPE="Ethernet"
BOOTPROTO="none"
NAME="eth0"
DEVICE="eth0"
ONBOOT="yes"
IPADDR="10.0.0.101"
NETMASK="255.255.255.0"
GATEWAY="10.0.0.254"
DNS1="223.5.5.5"'  >/etc/sysconfig/network-scripts/ifcfg-eth0

热添加技术

热添加硬盘、网卡、内存、cpu

kvm热添加硬盘

临时生效

virsh attach-disk web01 /data/web01-add.qcow2 vdb --subdriver qcow2

永久生效

virsh attach-disk web01 /data/web01-add.qcow2 vdb --subdriver qcow2 --config

临时剥离硬盘

virsh detach-disk web01 vdb

永久剥离硬盘

virsh detach-disk web01 vdb --config
扩容: 在虚拟机里把扩容盘的挂载目录卸载掉

在宿主机上剥离硬盘

virsh detach-disk web01 vdb 

在宿主机上调整容量

qemu-img resize 

在宿主机上再次附加硬盘

virsh attach-disk web01 /data/web01-add.qcow2 vdb --subdriver qcow2 

在虚拟机里再次挂载扩容盘

在虚拟机里用xfs_growfs更新扩容盘超级块信息

作业1:扩容kvm虚拟机的根分区

kvm虚拟机在线热添加网卡

添加
virsh attach-interface web04 --type bridge --source br0 --model virtio
拔掉
virsh detach-interface web04 --type bridge --mac 52:54:00:35:d3:71

kvm虚拟机在线热添加内存

virt-install --virt-type kvm --os-type=linux --os-variant rhel7 --name web04 --memory 512,maxmemory=2048 --vcpus 1 --disk /data/web04.qcow2 --boot hd --network bridge=br0 --graphics vnc,listen=0.0.0.0 --noautoconsole

临时热添加内存

virsh setmem web04 1024M 

永久增大内存

virsh setmem web04 1024M --config

调整虚拟机内存最大值

virsh setmaxmem web04 4G

kvm虚拟机在线热添加cpu

virt-install --virt-type kvm --os-type=linux --os-variant rhel7 --nameweb04 --memory 512,maxmemory=2048 --vcpus 1,maxvcpus=10 --disk /data/web04.qcow2 --boot hd --network bridge=br0 --graphics vnc,listen=0.0.0.0 --noautoconsole 

热添加cpu核数

virsh setvcpus web04

永久添加cpu核数

virsh setvcpus web04 4 --config

virt-manager和kvm虚拟机热迁移(共享的网络文件系统)

冷迁移kvm虚拟机:配置文件,磁盘文件
热迁移kvm虚拟机:配置文件,nfs共享

yum groupinstall "GNOME Desktop" -y yum install openssh-askpass -y
yum install tigervnc-server -y
vncpasswd vncserver :1 vncserver -kill :1
2):kvm虚拟机热迁移 
1:两边的环境(桥接网卡)
2-2.png
2:实现共享存储(nfs)
yum install nfs-utils rpcbind  -y
vim /etc/exports
/data  10.0.0.0/24(rw,async,no_root_squash,no_all_squash
systemctl start rpcbind nfs

#kvm01和kvm02
mount -t nfs 10.0.0.31:/data /data
3:虚拟机桥接网络
2-1.png
4:在线热迁移
wget http://192.168.37.202/linux59/web04.qcow2
virt-install --virt-type kvm --os-type=linux --os-variant rhel7 --name web04 --memory 1024,maxmemory=2048 --vcpus 1,maxvcpus=10 --disk /data/web04.qcow2 --boot hd --network bridge=br0 --graphics vnc,listen=0.0.0.0 --noautoconsole

#临时迁移
virsh migrate --live --verbose web04 qemu+ssh://10.0.0.100/system --unsafe 
#永久迁移
virsh migrate --live --verbose web04 qemu+ssh://10.0.0.100/system --unsafe --persistent --undefinesource
#配置网卡
echo 'TYPE="Ethernet"
BOOTPROTO="none"
NAME="eth1"
DEVICE="eth1"
ONBOOT="yes"
IPADDR="10.0.0.101"
NETMASK="255.255.255.0"
GATEWAY="10.0.0.254"
DNS1="223.5.5.5"'  >/etc/sysconfig/network-scripts/ifcfg-eth1
上一篇 下一篇

猜你喜欢

热点阅读