DOC

LinuxAdvancedFilesystemManagement

By Anne Ward,2014-05-20 14:26
15 views 0
LinuxAdvancedFilesystemManagement

    Advanced File System Management

    Software RAID Configuration Software RAID Recovery

    Converting LVM1 to LVM2

    Creating Logical Volumes Resizing Logical Volumes The Linux Quota System

    一、Software RAID Configuration

    1. 数据分布情况

     2. features:

     2.1. raid0

     需要2块硬盘?文件的文件块依次放在2块硬盘上

     A. 写文件的时候可以实现并行写同时写?可以实现并行读同时读

    可以提高读写速度

     B. 文件分布在2块上?只要有1块硬盘块坏了?文件就坏了

    没有冗余更容易损坏?文件就全部损坏

     C. 只适合对读写速度要求非常高

    对可选性安全性几乎没有要求的环境

     2.2. raid1

     需要2块硬盘?也叫镜像?同1个文件块同时写到2个硬盘上

    实现了冗余

     A.写性能上没有提高?同1数据要写2

     B.读性能有所提高?可以从2块硬盘上同时读

     C.浪费了一半的空间

     2.3. raid5

     A.需要4块硬盘?往里面写文件时,文件块a1块写在第1块上

    a2写在第2块上,a3写在第3,4块写前3块文件的校验和

     3块基中任何1块坏了?通过另外2块和校验和都能计算出来.

     b1写在第1块上?b2写在第2块上,b3写在第4块上,3块写文件

    的校验和?依次类推,这样检验和也被平均的分配到4

     硬盘上?没有分配在某一块上面?这样不会因为这一块所存放的检

    验和坏了?导致所有检验和损坏的情况

     B.最多只能坏1块硬盘

     C.浪费1/4的空间

     D.读性能是很高的?可以同时从3块硬盘上读

     E.写性能比较差?需要写校验和

     F.坏了其中一块硬盘,这时候raid性能会极剧下降?非常慢

     2.4. raid6

     A.raid5相似?但有2块硬盘做校验和,2份校验和?这样可以同时

    2块硬盘都能恢复数据

     B.写性能比raid5还差

     C.读性能还可以

     2.5. raid10

     A.需要4块硬盘,2块做raid1,2块做raid1,再把两组raid1组成raid0

     B.读写性能都很好

     C.浪费2块硬盘空间

     2.6. raid01

     A.需要4块硬盘,2块做raid0,2块做raid0,再把两组raid0组成raid1

     B.用了raid0读写性能很高

     C.用了raid1实现了冗余性

     D.浪费2块硬盘的空间

    3. 可以通过partition来模拟多块磁盘通过Software实现RAID

    4. 实例A:实现RAID0 partition

     A. 新增加两个partition

    [root@A ~]# df -h

    Filesystem Size Used Avail Use% Mounted on /dev/hda2 15G 3.0G 11G 22% /

    /dev/hda5 2.9G 69M 2.7G 3% /tmp

    /dev/hda1 9.5G 156M 8.9G 2% /boot

    tmpfs 242M 0 242M 0% /dev/shm [root@A ~]# fdisk -l

Disk /dev/hda: 42.9 GB, 42949672960 bytes

    255 heads, 63 sectors/track, 5221 cylinders

    Units = cylinders of 16065 * 512 = 8225280 bytes

     Device Boot Start End Blocks Id System /dev/hda1 * 1 1275 10241406 83 Linux /dev/hda2 1276 3187 15358140 83 Linux /dev/hda3 3188 4832 13213462+ 82 Linux swap / Solaris /dev/hda4 4833 5221 3124642+ 5 Extended /dev/hda5 4833 5214 3068383+ 83 Linux [root@A ~]# fdisk /dev/hda

    The number of cylinders for this disk is set to 5221. There is nothing wrong with that, but this is larger than 1024, and could in certain setups cause problems with:

    1) software that runs at boot time (e.g., old versions of LILO) 2) booting and partitioning software from other OSs

     (e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): p

Disk /dev/hda: 42.9 GB, 42949672960 bytes

    255 heads, 63 sectors/track, 5221 cylinders

    Units = cylinders of 16065 * 512 = 8225280 bytes

     Device Boot Start End Blocks Id System /dev/hda1 * 1 1275 10241406 83 Linux /dev/hda2 1276 3187 15358140 83 Linux /dev/hda3 3188 4832 13213462+ 82 Linux swap / Solaris /dev/hda4 4833 5221 3124642+ 5 Extended /dev/hda5 4833 5214 3068383+ 83 Linux

Command (m for help): n

    First cylinder (5215-5221, default 5215): Using default value 5215

Last cylinder or +size or +sizeM or +sizeK (5215-5221, default 5221): +10M

Command (m for help): n

    First cylinder (5217-5221, default 5217):

    Using default value 5217

    Last cylinder or +size or +sizeM or +sizeK (5217-5221, default 5221): +10M

Command (m for help): P

Disk /dev/hda: 42.9 GB, 42949672960 bytes

    255 heads, 63 sectors/track, 5221 cylinders

    Units = cylinders of 16065 * 512 = 8225280 bytes

     Device Boot Start End Blocks Id System /dev/hda1 * 1 1275 10241406 83 Linux /dev/hda2 1276 3187 15358140 83 Linux /dev/hda3 3188 4832 13213462+ 82 Linux swap / Solaris /dev/hda4 4833 5221 3124642+ 5 Extended /dev/hda5 4833 5214 3068383+ 83 Linux /dev/hda6 5215 5216 16033+ 83 Linux

     Linux /dev/hda7 5217 5218 16033+ 83

Command (m for help): wq

    The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource

    busy.

    The kernel still uses the old table.

    The new table will be used at the next reboot.

    Syncing disks.

     B.改变partition type idRAID

    [root@A ~]# fdisk /dev/hda

    The number of cylinders for this disk is set to 5221. There is nothing wrong with that, but this is larger than 1024, and could in certain setups cause problems with:

    1) software that runs at boot time (e.g., old versions of LILO) 2) booting and partitioning software from other OSs

     (e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): t

Partition number (1-7): 6

    Hex code (type L to list codes): fd

    Changed system type of partition 6 to fd (Linux raid autodetect)

Command (m for help): t

    Partition number (1-7): 7

    Hex code (type L to list codes): fd

    Changed system type of partition 7 to fd (Linux raid autodetect)

Command (m for help): p

Disk /dev/hda: 42.9 GB, 42949672960 bytes

    255 heads, 63 sectors/track, 5221 cylinders

    Units = cylinders of 16065 * 512 = 8225280 bytes

     Device Boot Start End Blocks Id System /dev/hda1 * 1 1275 10241406 83 Linux /dev/hda2 1276 3187 15358140 83 Linux /dev/hda3 3188 4832 13213462+ 82 Linux swap / Solaris /dev/hda4 4833 5221 3124642+ 5 Extended /dev/hda5 4833 5214 3068383+ 83 Linux /dev/hda6 5215 5216 16033+ fd Linux raid autodetect

    /dev/hda7 5217 5218 16033+ fd Linux raid autodetect

Command (m for help): wq

    The partition table has been altered!

Calling ioctl() to re-read partition table.

    WARNING: Re-reading the partition table failed with error 16: Device or resource busy.

    The kernel still uses the old table.

    The new table will be used at the next reboot.

    Syncing disks.

C. 使新增partition生效

     [root@A ~]# partprobe

D. 形成RAID0partition

     [root@A ~]# mdadm -C /dev/md0 -l 0 -n 2 /dev/hda6 /dev/hda7

     -C 表示新建raid partition

     /dev/md0 表示新增raid partition对应/dev/md0

     -l(L)表示指定raid level

     0()表示level

     -n:表示partition的数量

     2:表示partition数量值

     /dev/hda6 /dev/hda7 表示要通过这两个partition

    RAID

     [root@A ~]# mdadm -C /dev/md0 -l 0 -n 2 /dev/hda6 /dev/hda7

    mdadm: array /dev/md0 started.

    [root@A ~]# cat /proc/mdstat

    Personalities : [raid0]

    md0 : active raid0 hda7[1] hda6[0]

     31872 blocks 64k chunks

    unused devices:

E. 格式化RAID ext3

     [root@A ~]# mke2fs -j /dev/md0

    F. mount RAID

     [root@A ~]# mkdir /raiddata

    [root@A ~]# ls -l /raiddata/

    total 0

    [root@A ~]# mount /dev/md0 /raiddata/

    [root@A ~]# ls -l /raiddata/

    total 12

    drwx------ 2 root root 12288 Mar 11 15:05 lost+found

    [root@A ~]# df -h

    Filesystem Size Used Avail Use% Mounted on

    /dev/hda2 15G 3.0G 11G 22% /

    /dev/hda5 2.9G 69M 2.7G 3% /tmp

    /dev/hda1 9.5G 156M 8.9G 2% /boot

    tmpfs 242M 0 242M 0% /dev/shm

    /dev/md0 31M 1.4M 28M 5% /raiddata

     G. 开机自动挂载

     [root@A ~]# vi /etc/fstab

     增加如下内容

     H. reboot 测试

     I. 验证

     [root@A ~]# mount

    /dev/hda2 on / type ext3 (rw)

    proc on /proc type proc (rw)

    sysfs on /sys type sysfs (rw)

    devpts on /dev/pts type devpts (rw,gid=5,mode=620)

/dev/hda5 on /tmp type ext3 (rw)

    /dev/hda1 on /boot type ext3 (rw)

    tmpfs on /dev/shm type tmpfs (rw)

    /dev/md0 on /raiddata type ext3 (rw)

    none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)

     sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)[root@A ~]# df -h

    Filesystem Size Used Avail Use% Mounted on /dev/hda2 15G 3.0G 11G 22% / /dev/hda5 2.9G 69M 2.7G 3% /tmp /dev/hda1 9.5G 156M 8.9G 2% /boot tmpfs 242M 0 242M 0% /dev/shm /dev/md0 31M 1.4M 28M 5% /raiddata

    二、Software RAID Recovery

man mdadm

-f 来模拟某个partition损坏的情况.-apartition加入到RAID partition

    三、Converting LVM1 to LVM2

     LVM:Logical Volume Manager

     1.先从一个或多个disk中划分出多个partition,LVM机制下这些

    partition被称为Physical Volume

     然后将这些Physical Volume加入Volume Group逻辑磁区群组

     当数个Physical Volume组成1Volume GroupLVM会在所有

    Physical Volume上做类似format的工作,将每个Physical

    Volume划成一块一块的空间,这些空间就叫Physical Extent

     可以把Volume Goup想像成一个虚拟磁盘Virtual Disk

     Volume Group本不能直接使用, 要先划分成Logical Volume逻辑

    磁区才能存储数据

     2. Logical Volume并不一定对应Physical Volume

     比如LVa就对应着三个Physical Volume,这么做的好处是当LVa

Report this document

For any questions or suggestions please email
cust-service@docsford.com