Discuz! Board

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 8387|回复: 0
打印 上一主题 下一主题

udisk挂载到uhost并扩容lvm

[复制链接]

85

主题

89

帖子

600

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
600
跳转到指定楼层
楼主
发表于 2016-9-19 19:51:40 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
一、lvm创建.
1、查看磁盘:
[root@10-19-64-242 ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/vda1        20G  1.7G   18G   9% /
tmpfs           1.9G     0  1.9G   0% /dev/shm
/dev/vdb         60G  180M   56G   1% /data



2、卸载磁盘:
[root@Platform-Ops-datacenter03 ~]# umount /data/
umount: /data: device is busy.
        (In some cases useful info about processes that use
         the device is found by lsof(8) or fuser(1))

红色部分报错,是因为/data分区中有正在使用的文件或程序。
查看什么程序在使用/data下文件:使用lsof命令
[root@Platform-Ops-datacenter03 ~]# lsof /data/
COMMAND   PID USER   FD   TYPE DEVICE SIZE/OFF     NODE NAME
agent   10450 root    5u   REG  253,0      254 18079747 /data/logs/agent/agent.log

可以看见/data/logs/agent/agent.log正在被使用,杀死使用改文件进程:
[root@Platform-Ops-datacenter03 ~]# kill -9 10450
[root@Platform-Ops-datacenter03 ~]# lsof  /data/
[root@Platform-Ops-datacenter03 ~]#

现在可以正常卸载/data了:
[root@10-19-64-242 ~]# umount /data/
[root@10-19-64-242 ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/vda1        20G  1.7G   18G   9% /
tmpfs           1.9G     0  1.9G   0% /dev/shm
[root@10-19-64-242 ~]#



3、重新创建分区并修改分区格式:
[root@10-19-64-242 ~]# fdisk /dev/vdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x40e1b7b1.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.


Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)


WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').


Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-124830, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-124830, default 124830):
Using default value 124830


Command (m for help): t
Selected partition 1
Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM)


Command (m for help): p


Disk /dev/vdb: 64.4 GB, 64424509440 bytes
16 heads, 63 sectors/track, 124830 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x40e1b7b1


   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1               1      124830    62914288+  8e  Linux LVM


Command (m for help): w
The partition table has been altered!


Calling ioctl() to re-read partition table.
Syncing disks.
[root@10-19-64-242 ~]#

重新读区分区表
[root@10-19-64-242 ~]# partprobe /dev/vdb1


4、开始创建lvm:
首先创建pv:
[root@10-19-64-242 ~]# pvcreate /dev/vdb1
  Physical volume "/dev/vdb1" successfully created

[root@10-19-64-242 ~]# pvdisplay
  "/dev/vdb1" is a new physical volume of "60.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/vdb1
  VG Name               
  PV Size               60.00 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               CtAqc6-MXW6-cUuS-q0n2-yObL-CrP8-gAXtFv
创建vg:
[root@10-19-64-242 ~]# vgcreate DataCenter0 /dev/vdb1
  Volume group "DataCenter0" successfully created
[root@10-19-64-242 ~]# vgdisplay
  --- Volume group ---
  VG Name               DataCenter0
  System ID            
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  1
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                0
  Open LV               0
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               60.00 GiB
  PE Size               4.00 MiB
  Total PE              15359
  Alloc PE / Size       0 / 0   
  Free  PE / Size       15359 / 60.00 GiB
  VG UUID               LMBzfK-0BVm-xCoy-tfPG-pxQC-gLSH-HURQzO

[root@10-19-64-242 ~]#

创建lv:
[root@10-19-64-242 ~]# lvcreate -l 15359 -n lvDatacenter DataCenter0
  Logical volume "lvDatacenter" created.
[root@10-19-64-242 ~]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/DataCenter0/lvDatacenter
  LV Name                lvDatacenter
  VG Name                DataCenter0
  LV UUID                CSh3kj-pVZz-uPAZ-SFgh-3ktd-gJUn-0Fdf3x
  LV Write Access        read/write
  LV Creation host, time 10-19-64-242, 2016-09-19 17:36:17 +0800
  LV Status              available
  # open                 0
  LV Size                60.00 GiB
  Current LE             15359
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

[root@10-19-64-242 ~]#
格式化lv:
[root@10-19-64-242 ~]# mkfs -t ext3 /dev/DataCenter0/lvDatacenter
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
3932160 inodes, 15727616 blocks
786380 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
480 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
        4096000, 7962624, 11239424


Writing inode tables: done                           
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information:
done


This filesystem will be automatically checked every 20 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@10-19-64-242 ~]#



挂载到/data下:
[root@10-19-64-242 ~]# mount /dev/DataCenter0/lvDatacenter /data/
[root@10-19-64-242 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/vda1              20G  1.7G   18G   9% /
tmpfs                 1.9G     0  1.9G   0% /dev/shm
/dev/mapper/DataCenter0-lvDatacenter
                       60G  180M   56G   1% /data
[root@10-19-64-242 ~]#
至此lvm创建成功。



二、扩展lvm.
1、在udisk上创建云硬盘:

2、挂载udisk到目标主机:

3、登录目标主机查看:
[root@Platform-Ops-datacenter03 ~]# fdisk -l


Disk /dev/vda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0005acbe


   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *           1        2611    20970496   83  Linux


Disk /dev/vdb: 2147.5 GB, 2147483648000 bytes
16 heads, 63 sectors/track, 4161015 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xa26c45ae


   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1               1     4161015  2097151528+  8e  Linux LVM


Disk /dev/vdc: 2147.5 GB, 2147483648000 bytes
16 heads, 63 sectors/track, 4161015 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xcd68ee9d


   Device Boot      Start         End      Blocks   Id  System
/dev/vdc1               1     4161015  2097151528+  8e  Linux LVM


Disk /dev/mapper/DataCenter0-lvDataCenter: 4295.0 GB, 4294958907392 bytes
255 heads, 63 sectors/track, 522165 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000




Disk /dev/vdd: 2147.5 GB, 2147483648000 bytes
16 heads, 63 sectors/track, 4161015 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000


[root@Platform-Ops-datacenter03 ~]#

可见新加udisk已经挂载成功。
4、开始扩容lvm(可以参考http://123.59.83.120:8080/forum. ... 3&highlight=lvm
a、新加udisk创建分区:
[root@Platform-Ops-datacenter03 ~]# fdisk /dev/vdd
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x6b4d8acd.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.


Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)


WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').


Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
1
Invalid partition number for type `1'
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-4161015, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-4161015, default 4161015):
Using default value 4161015


Command (m for help): t
Selected partition 1
Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM)


Command (m for help): p


Disk /dev/vdd: 2147.5 GB, 2147483648000 bytes
16 heads, 63 sectors/track, 4161015 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x6b4d8acd


   Device Boot      Start         End      Blocks   Id  System
/dev/vdd1               1     4161015  2097151528+  8e  Linux LVM


Command (m for help): w
The partition table has been altered!


Calling ioctl() to re-read partition table.
Syncing disks.
[root@Platform-Ops-datacenter03 ~]# partprobe /dev/vd
vda   vda1  vdb   vdb1  vdc   vdc1  vdd   vdd1  
[root@Platform-Ops-datacenter03 ~]# partprobe /dev/vdd1
[root@Platform-Ops-datacenter03 ~]#

b、格式化分区:
[root@Platform-Ops-datacenter03 ~]# mkfs -t ext3 /dev/vdd1
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
131072000 inodes, 524287882 blocks
26214394 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
16000 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
        4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
        102400000, 214990848, 512000000

Writing inode tables: done                           
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information:
done

This filesystem will be automatically checked every 38 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@Platform-Ops-datacenter03 ~]#
磁盘较大,格式化时间较长,请耐心等待。

c、创建pv:
[root@Platform-Ops-datacenter03 ~]# pvcreate /dev/vdd1
  Physical volume "/dev/vdd1" successfully created
[root@Platform-Ops-datacenter03 ~]#
d、扩展vg:
[root@Platform-Ops-datacenter03 ~]# vgdisplay
  --- Volume group ---
  VG Name               DataCenter0
  System ID            
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  2
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               1
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               3.91 TiB
  PE Size               4.00 MiB
  Total PE              1023998
  Alloc PE / Size       1023998 / 3.91 TiB
  Free  PE / Size       0 / 0   
  VG UUID               0P1yKj-JUpM-BLUM-SM2e-unGE-UMS6-QOsYTd

[root@Platform-Ops-datacenter03 ~]# vgextend DataCenter0 /dev/vdd1
  Volume group "DataCenter0" successfully extended
[root@Platform-Ops-datacenter03 ~]#

e、扩展pv:
先卸载:
[root@Platform-Ops-datacenter03 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/vda1              20G  2.5G   17G  14% /
tmpfs                 3.9G     0  3.9G   0% /dev/shm
/dev/mapper/DataCenter0-lvDataCenter
                      3.9T  195M  3.7T   1% /data
[root@Platform-Ops-datacenter03 ~]# umount /data/
[root@Platform-Ops-datacenter03 ~]#

扩展pv:
[root@Platform-Ops-datacenter03 ~]# vgdisplay
  --- Volume group ---
  VG Name               DataCenter0
  System ID            
  Format                lvm2
  Metadata Areas        3
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               0
  Max PV                0
  Cur PV                3
  Act PV                3
  VG Size               5.86 TiB
  PE Size               4.00 MiB
  Total PE              1535997
  Alloc PE / Size       1023998 / 3.91 TiB
  Free  PE / Size       511999 / 1.95 TiB
  VG UUID               0P1yKj-JUpM-BLUM-SM2e-unGE-UMS6-QOsYTd

[root@Platform-Ops-datacenter03 ~]#

可以看见还有511999个pe可用;
[root@Platform-Ops-datacenter03 ~]# lvextend -l +511999 /dev/DataCenter0/lvDataCenter
  Size of logical volume DataCenter0/lvDataCenter changed from 3.91 TiB (1023998 extents) to 5.86 TiB (1535997 extents).
  Logical volume lvDataCenter successfully resized
[root@Platform-Ops-datacenter03 ~]#


f、调整文件系统大小:
[root@Platform-Ops-datacenter03 ~]# e2fsck -f /dev/DataCenter0/lvDataCenter
e2fsck 1.41.12 (17-May-2010)
Pass 1: Checking inodes, blocks, and sizes

Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/DataCenter0/lvDataCenter: 14/262144000 files (0.0% non-contiguous), 16503360/1048573952 blocks
[root@Platform-Ops-datacenter03 ~]#
[root@Platform-Ops-datacenter03 ~]# resize2fs /dev/DataCenter0/lvDataCenter
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/DataCenter0/lvDataCenter to 1572860928 (4k) blocks.
The filesystem on /dev/DataCenter0/lvDataCenter is now 1572860928 blocks long.

[root@Platform-Ops-datacenter03 ~]#


这一步要很长时间,真的需要耐心等待。
g、挂载磁盘:
[root@Platform-Ops-datacenter03 ~]# mount /dev/DataCenter0/lvDataCenter /data/
[root@Platform-Ops-datacenter03 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/vda1              20G  2.5G   17G  14% /
tmpfs                 3.9G     0  3.9G   0% /dev/shm
/dev/mapper/DataCenter0-lvDataCenter
                      5.8T  184M  5.5T   1% /data
[root@Platform-Ops-datacenter03 ~]#



扩容完成。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Comsenz Inc.

GMT+8, 2024-12-16 00:53 , Processed in 0.036032 second(s), 21 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表