@IT·互联网

云端技术驾驭DAY01——云计算底层技术奥秘、磁盘技术揭秘、虚拟

2024-01-28  本文已影响0人  川川野马

云计算时代的运维艺术

云计算底层技术奥秘

虚拟化技术介绍

常见虚拟化技术
系列 PC/服务器版代表
VMware VMware Workstation、vSphere
Microsoft VirtualPC、Hyper-V
RedHat KVM、RHEV
Citrix Xen
Oracle Oracle、VM VirtualBox
虚拟化与云计算的关系

虚拟化平台安装、虚拟化网络

创建Linux虚拟机
[root@ecs ~]# grep -Po "vmx|svm" /proc/cpuinfo   // 检查 CPU 是否支持 Intel 的虚拟化技术
vmx
……
[root@ecs ~]# lsmod | grep kvm   // 查看内核模块
kvm_intel             389120  0
kvm                   958464  1 kvm_intel
irqbypass              16384  1 kvm
[root@ecs ~]# dnf -y install \
> qemu-kvm \   // 虚拟化仿真程序
> libvirt-daemon \   // 核心守护进程
> libvirt-client \   // 客户端程序
> libvirt-daemon-driver-qemu \   // QEMU管理模块
> libvirt-daemon-driver-network \   // 网络管理模块
> dnsmasq   // 基础服务DHCP、DNS
[root@ecs ~]# systemctl enable libvirtd --now   // 开机自启
[root@ecs ~]# virsh version   // 查看版本
[root@ecs ~]# vim /etc/libvirt/qemu/networks/vbr.xml   // 网桥文件(模板来自官网 libvirt.org)

<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.128' end='192.168.100.200'/>
    </dhcp>
  </ip>
</network>
[root@ecs ~]# virsh net-define /etc/libvirt/qemu/networks/vbr.xml   // 创建网桥
Network vbr defined from /etc/libvirt/qemu/networks/vbr.xml
[root@ecs ~]# virsh net-autostart vbr   // 设置开机自启动
Network vbr marked as autostarted
[root@ecs ~]# virsh net-start vbr   // 启动网桥
Network vbr started
[root@ecs ~]# virsh net-list --all   // 验证状态
 Name   State    Autostart   Persistent
-----------------------------------------
 vbr    active   yes         yes
[root@ecs ~]# ifconfig vbr   // 验证
命令 解释
virsh net-list [--all] 列出虚拟网络
virsh net-start 启动虚拟交换机
virsh net-destroy 强制停止虚拟交换机
virsh net-define 根据xml文件创建虚拟网络
virsh net-undefine 删除一个虚拟网络设备
virsh net-edit 修改虚拟交换机的配置
virsh net-autostart 设置开机自启动

虚拟机管理

虚拟机原理

虚拟机的构成

虚拟机配置管理

虚拟机磁盘概念
虚拟机磁盘管理
qemu-img 子命令 子命令参数 块文件名称 大小
子命令 解释
create 创建一个磁盘
info 查看磁盘信息
[root@ecs ~]# qemu-img create -f raw disk1.img 20G   // 创建普通格式磁盘
Formatting 'disk1.img', fmt=raw size=21474836480
[root@ecs ~]# qemu-img create -f qcow2 disk2.img 20G   // 创建CoW格式磁盘
Formatting 'disk2.img', fmt=qcow2 cluster_size=65536 extended_l2=off compression_type=zlib size=21474836480 lazy_refcounts=off refcount_bits=16
[root@ecs ~]# cp cirros.qcow2 /var/lib/libvirt/images/   // 将cirrors.qcow2文件放进/var/lib/libvirt/images/
[root@ecs ~]# cd /var/lib/libvirt/images/   // 进入images目录
[root@ecs images]# qemu-img create -b cirros.qcow2 -F qcow2 -f qcow2 vmhost.img 20G   // -b指定基础映像文件 -F指定输出映像格式 -f指定输入基础映像格式
Formatting 'vmhost.img', fmt=qcow2 cluster_size=65536 extended_l2=off compression_type=zlib size=21474836480 backing_file=cirros.qcow2 backing_fmt=qcow2 lazy_refcounts=off refcount_bits=16
[root@ecs images]# qemu-img info vmhost.img   // 查看信息
image: vmhost.img
file format: qcow2
virtual size: 20 GiB (21474836480 bytes)
disk size: 196 KiB
cluster_size: 65536
backing file: cirros.qcow2
backing file format: qcow2
Format specific information:
    compat: 1.1
    compression type: zlib
    lazy refcounts: false
    refcount bits: 16
    corrupt: false
    extended l2: false
虚拟机配置文件
<domain type='kvm'>   // 虚拟机类型
  <name>#####</name>   // 虚拟机名称
  <memory unit='KB'>1048576</memory>   // 最大内存
  <currentMemory unit='KB'>1048576</currentMemory>   // 当前内存
  <vcpu placement='static'>2</vcpu>   // CPU数量
  <os>
    <type arch='x86_64' machine='pc'>hvm</type>   // 系统引导参数
    <boot dev='hd'/>   // (安装)引导设备
    <bootmenu enable='yes'/>
    <bios useserial='yes'/>
  </os>
  <features>   // 电源管理特性
    <acpi/>
    <apic/>
  </features>
  <cpu mode='host-passthrough'></cpu>   // CPU仿真
  <clock offset='localtime'/>   // 系统时钟
  <on_poweroff>destroy</on_poweroff>   // 模拟硬件按钮
  <on_reboot>restart</on_reboot>
  <on_crash>restart</on_crash>
  <devices>
    <emulator>/usr/libexec/qemu-kvm</emulator>   // 仿真程序
    <disk type='file' device='disk'>   // 文件/磁盘仿真
      <driver name='qemu' type='qcow2'/>   // 文件格式
      <source file='/var/lib/libvirt/images/#####.img'/>
      <target dev='vda' bus='virtio'/>
    </disk>
    <interface type='bridge'>   // 网卡仿真
      <source bridge='vbr'/>   // 连接网桥名称
      <model type='virtio'/>
    </interface>
    <channel type='unix'>   // agent客户端
      <target type='virtio' name='org.qemu.guest_agent.0'/>
    </channel>
    <serial type='pty'></serial>   // 终端类型
    <console type='pty'>
      <target type='serial'/>
    </console>
    <memballoon model='virtio'></memballoon>
  </devices>
</domain>
[root@ecs ~]# cp node_base.xml /etc/libvirt/qemu/vmhost.xml
[root@ecs ~]# vim /etc/libvirt/qemu/vmhost.xml

  1 <domain type='kvm'>
  2   <name>vmhost</name>
  3   <memory unit='KB'>1048576</memory>
  4   <currentMemory unit='KB'>1048576</currentMemory>
  5   <vcpu placement='static'>2</vcpu>
... ...
 25       <source file='/var/lib/libvirt/images/vmhost.img'/>
... ...
 29       <source bridge='vbr'/>
创建/删除虚拟机
命令选项 解释
virsh list [--all] 列出虚拟机
virsh start/shutdown 启动/关闭虚拟机
virsh destroy 强制停止虚拟机
virsh define/undefine 创建/删除虚拟机
virsh console 连接虚拟机的 console
virsh edit 修改虚拟机的配置
virsh autostart 设置虚拟机自启动
virsh dominfo 查看虚拟机摘要信息
virsh domiflist 查看虚拟机网卡信息
virsh domblklist 查看虚拟机硬盘信息
[root@ecs ~]# virsh define /etc/libvirt/qemu/vmhost.xml   // 不识别xml文件用这条命令,如果已经识别到xml文件则会报错
error: Failed to define domain from /etc/libvirt/qemu/vmhost.xml
error: operation failed: domain 'vmhost' already exists with uuid e27e71a7-4fd8-41f1-8544-16f188de734f
[root@ecs ~]# virsh list --all
 Id   Name     State
-------------------------
 -    vmhost   shut off
[root@ecs ~]# virsh start vmhost
Domain vmhost started
[root@ecs ~]# virsh console vmhost   // 登陆到虚拟机
[root@ecs ~]# virsh undefine vmhost  // 删除xml配置文件
[root@ecs ~]# rm -f /var/lib/libvirt/images/vmhost.img   // 删除镜像文件

公有云概述

云服务类型

三大服务模式
公有云、私有云、混合云
上一篇 下一篇

猜你喜欢

热点阅读