KVM虚拟化笔记(十一)------kvm之Linux虚拟机在线扩展磁盘

简介:

  kvm虚拟机也支持在线扩展磁盘功能,在线扩展有特定的使用环境,主要用于不能随便停用的生产环境中,本文以hadoop为例具体步骤如下:

1,查看现有磁盘

1
2
3
4
5
6
7
8
9
10
11
12
13
[root@KVM  test ] # virsh list --all
  Id    Name                           State
----------------------------------------------------
  1     win7                           running
  17    hadoop1                        running
  18    hadoop4                        running
  20    hadoop2                        running
  -     hadoop3                        shut off
[root@KVM  test ] # virsh domblklist hadoop1
Target     Source
------------------------------------------------
vda         /images/test/hadoop1 .qcow2
hdc        -

 

2,创建一块qcow2虚拟磁盘

1
2
3
[root@KVM  test ] # qemu-img create -f qcow2 hadoop1_add01.qcow2 5G
Formatting  'hadoop1_add01.qcow2' fmt =qcow2 size=5368709120 encryption=off cluster_size=65536 
[root@KVM  test ] #

wKioL1a0YSaS9zkQAADshmPf3WA450.png3,在线添加这台qcow2虚拟磁盘

1
2
3
4
5
6
7
8
[root@KVM  test ] # virsh attach-disk hadoop1 /images/test/hadoop1_add01.qcow2 vdb --cache=none --subdriver=qcow2            
Disk attached successfully
[root@KVM  test ] # virsh domblklist hadoop1                       
Target     Source
------------------------------------------------
vda         /images/test/hadoop1 .qcow2
vdb         /images/test/hadoop1_add01 .qcow2
hdc        -

wKioL1a0YizibtGZAABeCpmwwdk206.png4,进入虚拟机查看,如下图:

wKioL1a0Yn2hSA2zAABSB9swk_Q757.png

5,然后进入系统里边划分区

fdisk /dev/vdb

wKiom1a0Y4biAtfzAAAaEIuPcKI184.png

wKiom1a0Y06AqiANAABACXkO1jM598.png

wKioL1a0Y6HzlILkAAAo0LWA1Yw548.png

6,划分逻辑卷LVM省略,前边的可以参考。


7,修改虚拟机配置文件,把新增的磁盘配置写到虚拟机磁盘配置

 (1)查看当前虚拟机hadoop1的磁盘配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
[root@KVM  test ] # virsh dumpxml hadoop1
<domain  type = 'qemu'  id = '17' >
   <name>hadoop1< /name >
   <uuid>919f0921-0736-ad5b-780b-a440de2f35cb< /uuid >
   <memory unit= 'KiB' >524288< /memory >
   <currentMemory unit= 'KiB' >524288< /currentMemory >
   <vcpu placement= 'static' >1< /vcpu >
   <os>
     < type  arch= 'x86_64'  machine= 'rhel6.6.0' >hvm< /type >
     <boot dev= 'hd' />
   < /os >
   <features>
     <acpi/>
     <apic/>
     <pae/>
   < /features >
   <clock offset= 'utc' />
   <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'  cache= 'none' />
       < source  file = '/images/test/hadoop1.qcow2' />
       <target dev= 'vda'  bus= 'virtio' />
       < alias  name= 'virtio-disk0' />
       <address  type = 'pci'  domain= '0x0000'  bus= '0x00'  slot= '0x05'  function = '0x0' />
     < /disk >
     <disk  type = 'file'  device= 'disk' >
       <driver name= 'qemu'  type = 'qcow2'  cache= 'none' />
       < source  file = '/images/test/hadoop1_add01.qcow2' />
       <target dev= 'vdb'  bus= 'virtio' />
       < alias  name= 'virtio-disk1' />
       <address  type = 'pci'  domain= '0x0000'  bus= '0x00'  slot= '0x07'  function = '0x0' />
     < /disk >
     <disk  type = 'block'  device= 'cdrom' >
       <driver name= 'qemu'  type = 'raw' />
       <target dev= 'hdc'  bus= 'ide' />
       < readonly />
       < alias  name= 'ide0-1-0' />
       <address  type = 'drive'  controller= '0'  bus= '1'  target= '0'  unit= '0' />
     < /disk >
     <controller  type = 'usb'  index= '0'  model= 'ich9-ehci1' >
       < alias  name= 'usb0' />
       <address  type = 'pci'  domain= '0x0000'  bus= '0x00'  slot= '0x04'  function = '0x7' />
     < /controller >
     <controller  type = 'usb'  index= '0'  model= 'ich9-uhci1' >
       < alias  name= 'usb0' />
       <master startport= '0' />
       <address  type = 'pci'  domain= '0x0000'  bus= '0x00'  slot= '0x04'  function = '0x0'  multifunction= 'on' />
     < /controller >
     <controller  type = 'usb'  index= '0'  model= 'ich9-uhci2' >
       < alias  name= 'usb0' />
       <master startport= '2' />
       <address  type = 'pci'  domain= '0x0000'  bus= '0x00'  slot= '0x04'  function = '0x1' />
     < /controller >
     <controller  type = 'usb'  index= '0'  model= 'ich9-uhci3' >
       < alias  name= 'usb0' />
       <master startport= '4' />
       <address  type = 'pci'  domain= '0x0000'  bus= '0x00'  slot= '0x04'  function = '0x2' />
     < /controller >
     <controller  type = 'ide'  index= '0' >
       < alias  name= 'ide0' />
       <address  type = 'pci'  domain= '0x0000'  bus= '0x00'  slot= '0x01'  function = '0x1' />
     < /controller >
     <interface  type = 'bridge' >
       <mac address= '52:54:00:b6:bf:1f' />
       < source  bridge= 'br0' />
       <target dev= 'vnet1' />
       <model  type = 'virtio' />
       < alias  name= 'net0' />
       <address  type = 'pci'  domain= '0x0000'  bus= '0x00'  slot= '0x03'  function = '0x0' />
     < /interface >
     <serial  type = 'pty' >
       < source  path= '/dev/pts/2' />
       <target port= '0' />
       < alias  name= 'serial0' />
     < /serial >
     <console  type = 'pty'  tty = '/dev/pts/2' >
       < source  path= '/dev/pts/2' />
       <target  type = 'serial'  port= '0' />
       < alias  name= 'serial0' />
     < /console >
     <input  type = 'mouse'  bus= 'ps2' />
     <graphics  type = 'vnc'  port= '5911'  autoport= 'no'  listen= '0.0.0.0' >
       <listen  type = 'address'  address= '0.0.0.0' />
     < /graphics >
     <video>
       <model  type = 'cirrus'  vram= '9216'  heads= '1' />
       < alias  name= 'video0' />
       <address  type = 'pci'  domain= '0x0000'  bus= '0x00'  slot= '0x02'  function = '0x0' />
     < /video >
     <memballoon model= 'virtio' >
       < alias  name= 'balloon0' />
       <address  type = 'pci'  domain= '0x0000'  bus= '0x00'  slot= '0x06'  function = '0x0' />
     < /memballoon >
   < /devices >
< /domain >


 (2)把以下配置添加到/etc/libvirt/qemu/hadoop1.xml配置文件中

1
2
3
4
5
6
7
  <disk  type = 'file'  device= 'disk' >
       <driver name= 'qemu'  type = 'qcow2'  cache= 'none' />
       < source  file = '/images/test/hadoop1_add01.qcow2' />
       <target dev= 'vdb'  bus= 'virtio' />
       < alias  name= 'virtio-disk1' />
       <address  type = 'pci'  domain= '0x0000'  bus= '0x00'  slot= '0x07'  function = '0x0' />
     < /disk >


wKiom1a0Z2aD00LdAAGB6Cp_t9A795.pngwKioL1a0aBjT1aLqAAFy6S32LMg936.png




本文转自 lqbyz 51CTO博客,原文链接:http://blog.51cto.com/liqingbiao/1741252

相关文章
|
21天前
|
存储 运维 数据挖掘
虚拟化数据恢复—误还原快照导致虚拟机上数据库丢失的数据恢复案例
虚拟化数据恢复环境&故障: vmfs文件系统,存储的数据是SqlServer数据库及其他办公文件。 工作人员误将快照还原,导致了SqlServer数据库数据的丢失,需要恢复原来的SqlServer数据库文件。
55 22
|
1月前
|
Ubuntu Linux 网络安全
Linux磁盘挂接教程
Linux磁盘挂接教程
68 14
|
3月前
|
存储 SQL 数据库
虚拟化数据恢复—Vmware虚拟机误还原快照的数据恢复案例
虚拟化数据恢复环境: 一台虚拟机从物理机迁移到ESXI虚拟化平台,迁移完成后做了一个快照。虚拟机上运行了一个SQL Server数据库,记录了数年的数据。 ESXI虚拟化平台上有数十台虚拟机,EXSI虚拟化平台连接了一台EVA存储,所有的虚拟机都存放在EVA存储上。 虚拟化故障: 工组人员误操作将数年前迁移完成后做的快照还原了,也就意味着虚拟机状态还原到数年前,近几年数据都被删除了。 还原快照相当于删除数据,意味着部分存储空间会被释放。为了不让这部分释放的空间被重用,需要将连接到这台存储的所有虚拟机都关掉,需要将不能长时间宕机的虚拟机迁移到别的EXSI虚拟化平台上。
149 50
|
2月前
|
存储 数据挖掘 数据库
虚拟化数据恢复—VMFS简介&误删除虚拟机的数据恢复案例
物理区:物理上连续的磁盘空间,即通常意义上的分区。 本地区:VMFS管理的物理区分为保留区和本地区,前面一部分是保留区,后面部分是本地区。本地区又分为元文件区和数据区。 元文件:与NTFS的元文件类似,属于FS的管理用数据。VMFS有6个元文件:.VH.SF/.FBB.SF/.FDC.SF/.SBC.SF/.PBC.SF/.PB2.SF。 元文件区:6个元文件占用的所有空间,在本地区的前面部分。 数据区:用于存放文件数据。 datastore:在ESX服务器上看到的VMFS存储空间。 LV:logical volume,所指的范围其实和本地区一样,即虚拟化卷。 LVM逻辑卷组:用来管理跨dis
|
3月前
|
存储 持续交付 虚拟化
|
18天前
|
Linux
Linux系统之whereis命令的基本使用
Linux系统之whereis命令的基本使用
54 23
Linux系统之whereis命令的基本使用
|
3月前
|
Linux 网络安全 数据安全/隐私保护
Linux 超级强大的十六进制 dump 工具:XXD 命令,我教你应该如何使用!
在 Linux 系统中,xxd 命令是一个强大的十六进制 dump 工具,可以将文件或数据以十六进制和 ASCII 字符形式显示,帮助用户深入了解和分析数据。本文详细介绍了 xxd 命令的基本用法、高级功能及实际应用案例,包括查看文件内容、指定输出格式、写入文件、数据比较、数据提取、数据转换和数据加密解密等。通过掌握这些技巧,用户可以更高效地处理各种数据问题。
384 8
|
5天前
|
缓存 Ubuntu Linux
Linux中yum、rpm、apt-get、wget的区别,yum、rpm、apt-get常用命令,CentOS、Ubuntu中安装wget
通过本文,我们详细了解了 `yum`、`rpm`、`apt-get`和 `wget`的区别、常用命令以及在CentOS和Ubuntu中安装 `wget`的方法。`yum`和 `apt-get`是高层次的包管理器,分别用于RPM系和Debian系发行版,能够自动解决依赖问题;而 `rpm`是低层次的包管理工具,适合处理单个包;`wget`则是一个功能强大的下载工具,适用于各种下载任务。在实际使用中,根据系统类型和任务需求选择合适的工具,可以大大提高工作效率和系统管理的便利性。
54 25
|
3天前
|
缓存 Linux
Linux查看内存命令
1. free free命令是最常用的查看内存使用情况的命令。它显示系统的总内存、已使用内存、空闲内存和交换内存的总量。 free -h • -h 选项:以易读的格式(如GB、MB)显示内存大小。 输出示例: total used free shared buff/cache available Mem: 15Gi 4.7Gi 4.1Gi 288Mi 6.6Gi 9.9Gi Swap: 2.0Gi 0B 2.0Gi • to
14 2

热门文章

最新文章