Centos系統中軟陣列(raid)的實現

來源:互聯網
上載者:User

1.建立測試的使用者和修改掛載的參數


[root@localhost ~]# useradd user1 --建立兩個使用者[root@localhost ~]# useradd user2[root@localhost ~]# mount -o remount,usrquota,grpquota /mnt/sdb --重新掛載,加參數[root@localhost ~]# mount -l --查看掛載選項/dev/mapper/VolGroup-lv_rooton / typeext4 (rw)proc on /proctypeproc (rw)sysfs on /systypesysfs (rw)devpts on /dev/ptstypedevpts (rw,gid=5,mode=620)tmpfs on /dev/shmtypetmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")/dev/sda1on /boottypeext4 (rw)none on /proc/sys/fs/binfmt_misctypebinfmt_misc (rw)/dev/sdb1on /mnt/sdbtypeext4 (rw,usrquota,grpquota)[root@localhost ~]# quotacheck -avug -mf --產生兩個quota檔案quotacheck: Your kernel probably supports journaled quotabut you are not using it. Consider switching to journaled quotato avoid running quotacheckafter an unclean shutdown.quotacheck: Scanning /dev/sdb1[/mnt/sdb] donequotacheck: Cannot stat old user quotafile: No such fileor directoryquotacheck: Cannot stat old group quotafile: No such fileor directoryquotacheck: Cannot stat old user quotafile: No such fileor directoryquotacheck: Cannot stat old group quotafile: No such fileor directoryquotacheck: Checked 2 directories and 0 filesquotacheck: Old filenot found.quotacheck: Old filenot found.[root@localhost ~]# ll /mnt/sdb --查看產生的兩個檔案total 26-rw-------. 1 root root 6144 Jan 9 17:59 aquota.group-rw-------. 1 root root 6144 Jan 9 17:59 aquota.userdrwx------. 2 root root 12288 Jan 9 17:55 lost+found[root@localhost ~]# quotaon -avug --開啟quota功能/dev/sdb1[/mnt/sdb]: group quotas turned on/dev/sdb1[/mnt/sdb]: user quotas turned on[root@localhost ~]# edquota -u user1Disk quotas foruser user1 (uid 500):Filesystem blocks soft hard inodes soft hard/dev/sdb10 10 20 0 0 0[root@localhost ~]# edquota -u user2Disk quotas foruser user2 (uid 501):Filesystem blocks soft hard inodes soft hard/dev/sdb10 5 10 0 0 0
[root@localhost ~]# useradd user1 --建立兩個使用者[root@localhost ~]# useradd user2[root@localhost ~]# mount -o remount,usrquota,grpquota /mnt/sdb --重新掛載,加參數[root@localhost ~]# mount -l --查看掛載選項/dev/mapper/VolGroup-lv_rooton / typeext4 (rw)proc on /proctypeproc (rw)sysfs on /systypesysfs (rw)devpts on /dev/ptstypedevpts (rw,gid=5,mode=620)tmpfs on /dev/shmtypetmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")/dev/sda1on /boottypeext4 (rw)none on /proc/sys/fs/binfmt_misctypebinfmt_misc (rw)/dev/sdb1on /mnt/sdbtypeext4 (rw,usrquota,grpquota)[root@localhost ~]# quotacheck -avug -mf --產生兩個quota檔案quotacheck: Your kernel probably supports journaled quotabut you are not using it. Consider switching to journaled quotato avoid running quotacheckafter an unclean shutdown.quotacheck: Scanning /dev/sdb1[/mnt/sdb] donequotacheck: Cannot stat old user quotafile: No such fileor directoryquotacheck: Cannot stat old group quotafile: No such fileor directoryquotacheck: Cannot stat old user quotafile: No such fileor directoryquotacheck: Cannot stat old group quotafile: No such fileor directoryquotacheck: Checked 2 directories and 0 filesquotacheck: Old filenot found.quotacheck: Old filenot found.[root@localhost ~]# ll /mnt/sdb --查看產生的兩個檔案total 26-rw-------. 1 root root 6144 Jan 9 17:59 aquota.group-rw-------. 1 root root 6144 Jan 9 17:59 aquota.userdrwx------. 2 root root 12288 Jan 9 17:55 lost+found[root@localhost ~]# quotaon -avug --開啟quota功能/dev/sdb1[/mnt/sdb]: group quotas turned on/dev/sdb1[/mnt/sdb]: user quotas turned on[root@localhost ~]# edquota -u user1 --使用者user1使用/mnt/sdb目錄不要起過20MDisk quotas foruser user1 (uid 500):Filesystem blocks soft hard inodes soft hard/dev/sdb10 10000 20000 0 0 0[root@localhost ~]# edquota -u user2 --使用者user2對sdb目錄不要超過10M,大於5M超出指定時間刪除Disk quotas foruser user2 (uid 501):Filesystem blocks soft hard inodes soft hard/dev/sdb10 5000 10000 0 0 0

2.驗證配額


[root@localhost ~]# su - user1[user1@localhost ~]$ cd/mnt/sdb[user1@localhost sdb]$ ddif=/dev/zeroof=12 bs=1M count=5 --建立5M的檔案沒有警告資訊,正常5+0 records in5+0 records out5242880 bytes (5.2 MB) copied, 0.0525754 s, 99.7 MB/s[user1@localhost sdb]$ ll -h 12-rw-rw-r--. 1 user1 user1 5.0M Jan 9 18:16 12[user1@localhost sdb]$ ddif=/dev/zeroof=123 bs=1M count=21 --建立12M的檔案有警告資訊,表示失敗sdb1: warning, user block quotaexceeded.sdb1: write failed, user block limit reached.dd: writing `123': Disk quotaexceeded20+0 records in19+0 records out20475904 bytes (20 MB) copied, 0.20094 s, 102 MB/s[user1@localhost sdb]$ ll -h 123-rw-rw-r--. 1 user1 user1 0 Jan 9 18:17 123[user1@localhost sdb]$ exitlogout[root@localhost ~]# su - user2 --使用者user2測試[user2@localhost ~]$ cd/mnt/sdb[user2@localhost sdb]$ ddif=/dev/zeroof=23 bs=1M count=8 --寫入8M檔案成功sdb1: warning, user block quotaexceeded.8+0 records in8+0 records out8388608 bytes (8.4 MB) copied, 0.0923618 s, 90.8 MB/s[user2@localhost sdb]$ ll -h 23 --查看檔案大小-rw-rw-r--. 1 user2 user2 8.0M Jan 9 18:23 23[user2@localhost sdb]$[user2@localhost sdb]$ ddif=/dev/zeroof=23 bs=1M count=11 --寫入11M檔案失敗sdb1: warning, user block quotaexceeded.sdb1: write failed, user block limit reached.dd: writing `23': Disk quotaexceeded10+0 records in9+0 records out10235904 bytes (10 MB) copied, 0.106298 s, 96.3 MB/s[user2@localhost sdb]$

3.查看quota配置,修改警告時間,取消quota


[root@localhost ~]# quota -vu user1 user2 --尋找指定的使用者quota資訊Disk quotas foruser user1 (uid 500):Filesystem blocks quotalimit grace files quotalimit grace/dev/sdb10 10000 20000 0 0 0Disk quotas foruser user2 (uid 501):Filesystem blocks quotalimit grace files quotalimit grace/dev/sdb18193* 5000 10000 6days 1 0 0[root@localhost ~]# repquota -av --所有使用者和quota資訊*** Report foruser quotas on device /dev/sdb1Block grace time: 7days; Inode grace time: 7daysBlock limits File limitsUser used soft hard grace used soft hard grace----------------------------------------------------------------------root -- 13 0 0 2 0 0user1 -- 0 10000 20000 0 0 0user2 +- 8193 5000 10000 6days 1 0 0Statistics:Total blocks: 7Data blocks: 1Entries: 3Used average: 3.000000[root@localhost ~]# edquota -t --修改檔案警告天數(Block 天數 Inode 天數)Grace period before enforcing soft limits forusers:Time unitsmay be: days, hours, minutes, or secondsFilesystem Block grace period Inode grace period/dev/sdb17days 7days[root@localhost ~]# vim /etc/warnquota.conf --查看警告資訊[root@localhost ~]# quotaoff /mnt/sdb --關閉quota功能

4.磁碟分割,轉換磁碟的格式做軟陣列


[root@localhost ~]# sfdisk -l --查看系統有多少塊硬碟Disk /dev/sda: 1044 cylinders, 255 heads, 63 sectors/trackUnits = cylinders of 8225280 bytes, blocks of 1024 bytes, counting from 0Device Boot Start End #cyls #blocks Id System/dev/sda1* 0+ 63- 64- 512000 83 Linux/dev/sda263+ 1044- 981- 7875584 8e Linux LVM/dev/sda30 - 0 0 0 Empty/dev/sda40 - 0 0 0 EmptyDisk /dev/sdb: 74 cylinders, 255 heads, 63 sectors/track--第二塊硬碟Disk /dev/sdc: 79 cylinders, 255 heads, 63 sectors/track--第三塊硬碟Disk /dev/sdd: 74 cylinders, 255 heads, 63 sectors/track--第四塊硬碟Disk /dev/mapper/VolGroup-lv_root: 849 cylinders, 255 heads, 63 sectors/trackDisk /dev/mapper/VolGroup-lv_swap: 130 cylinders, 255 heads, 63 sectors/track[root@localhost ~]# fdisk -cu /dev/sdb --分區交轉換分區格式(以下分區全部這麼做,這裡我就不顯示了)Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabelBuilding a new DOS disklabel with disk identifier 0x2255ec93.Changes will remain inmemory only, untilyou 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)Command (m forhelp): nCommand actione extendedp primary partition (1-4)pPartition number (1-4): 1First sector (2048-1196031, default 2048):Using default value 2048Last sector, +sectors or +size{K,M,G} (2048-1196031, default 1196031): +100MCommand (m forhelp): nCommand actione extendedp primary partition (1-4)pPartition number (1-4): 2First sector (206848-1196031, default 206848):Using default value 206848Last sector, +sectors or +size{K,M,G} (206848-1196031, default 1196031): +100MCommand (m forhelp): nCommand actione extendedp primary partition (1-4)pPartition number (1-4): 3First sector (411648-1196031, default 411648):Using default value 411648Last sector, +sectors or +size{K,M,G} (411648-1196031, default 1196031): +100MCommand (m forhelp): tPartition number (1-4): 1Hex code (typeL to list codes): fdChanged system typeof partition 1 to fd (Linux raid autodetect)Command (m forhelp): tPartition number (1-4): 2Hex code (typeL to list codes): fdChanged system typeof partition 2 to fd (Linux raid autodetect)Command (m forhelp): tPartition number (1-4): 1Hex code (typeL to list codes): fdChanged system typeof partition 1 to fd (Linux raid autodetect)Command (m forhelp): pDisk /dev/sdb: 612 MB, 612368384 bytes255 heads, 63 sectors/track, 74 cylinders, total 1196032 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/Osize (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x2255ec93Device Boot Start End Blocks Id System/dev/sdb12048 206847 102400 fd Linux raid autodetect/dev/sdb2206848 411647 102400 fd Linux raid autodetect/dev/sdd3411648 616447 102400 fd Linux raid autodetectCommand (m forhelp): wThe partition table has been altered!Calling ioctl() to re-readpartition table.Syncing disks.[root@localhost ~]# partx -a /dev/sdb --強制讀取分區表BLKPG: Device or resource busyerror adding partition 1BLKPG: Device or resource busyerror adding partition 2BLKPG: Device or resource busyerror adding partition 3[root@localhost ~]# partx -a /dev/sdc --強制讀取分區表BLKPG: Device or resource busyerror adding partition 1BLKPG: Device or resource busyerror adding partition 2BLKPG: Device or resource busyerror adding partition 3[root@localhost ~]# partx -a /dev/sdd --強制讀取分區表BLKPG: Device or resource busyerror adding partition 1BLKPG: Device or resource busyerror adding partition 2BLKPG: Device or resource busyerror adding partition 3

5.將第二,三塊硬碟的第一個分區做成raid0


[root@localhost ~]# mdadm --create /dev/md0 --raid-devices=2 --level=0 /dev/sd{b,c}1 --第二,三塊硬碟第一分區做raid0mdadm: Defaulting to version 1.2 metadatamdadm: array /dev/md0started.[root@localhost ~]# cat /proc/mdstat --查看raid資訊Personalities : [raid0]md0 : active raid0 sdc1[1] sdb1[0]224256 blocks super 1.2 512k chunksunused devices: <none>[root@localhost ~]# mkfs.ext4 /dev/md0 --格式化mke2fs 1.41.12 (17-May-2010)Filesystem label=OS type: LinuxBlock size=1024 (log=0)Fragment size=1024 (log=0)Stride=512 blocks, Stripe width=1024 blocks56224 inodes, 224256 blocks11212 blocks (5.00%) reserved forthe super userFirst data block=1Maximum filesystem blocks=6737100828 block groups8192 blocks per group, 8192 fragments per group2008 inodes per groupSuperblock backups stored on blocks:8193, 24577, 40961, 57345, 73729, 204801, 221185Writing inode tables: doneCreating journal (4096 blocks): doneWriting superblocks and filesystem accounting information: doneThis filesystem will be automatically checked every 38 mounts or180 days, whichever comes first. Use tune2fs -c or -i to override.[root@localhost ~]# mount /dev/md0 /mnt/sdb[root@localhost ~]#

6.將第二,三塊硬碟的第二個分區做raid1


[root@localhost ~]# mdadm --create /dev/md1 --raid-devices=2 --level=1 /dev/sd{b,c}2mdadm: Note: this array has metadata at the start andmay not be suitable as a boot device. If you plan tostore '/boot'on this device please ensure thatyour boot-loader understands md/v1.x metadata, or use--metadata=0.90Continue creating array?Continue creating array? (y/n) ymdadm: Defaulting to version 1.2 metadatamdadm: array /dev/md1started.[root@localhost ~]# mkfs.ext4 /dev/md1mke2fs 1.41.12 (17-May-2010)Filesystem label=OS type: LinuxBlock size=1024 (log=0)Fragment size=1024 (log=0)Stride=0 blocks, Stripe width=0 blocks28112 inodes, 112320 blocks5616 blocks (5.00%) reserved forthe super userFirst data block=1Maximum filesystem blocks=6737100814 block groups8192 blocks per group, 8192 fragments per group2008 inodes per groupSuperblock backups stored on blocks:8193, 24577, 40961, 57345, 73729Writing inode tables: doneCreating journal (4096 blocks): doneWriting superblocks and filesystem accounting information: doneThis filesystem will be automatically checked every 35 mounts or180 days, whichever comes first. Use tune2fs -c or -i to override.[root@localhost ~]# mount /dev/md1 /mnt/sdb1/

7.將第二,三,四塊硬碟的第三個分區做成raid5


[root@localhost ~]# mdadm --create /dev/md2 --raid-devices=3 --level=5 /dev/sd{b,c,d}3mdadm: Defaulting to version 1.2 metadatamdadm: array /dev/md2started.[root@localhost ~]# mkfs.ext4 /dev/md2mke2fs 1.41.12 (17-May-2010)Filesystem label=OS type: LinuxBlock size=1024 (log=0)Fragment size=1024 (log=0)Stride=512 blocks, Stripe width=1024 blocks56224 inodes, 224256 blocks11212 blocks (5.00%) reserved forthe super userFirst data block=1Maximum filesystem blocks=6737100828 block groups8192 blocks per group, 8192 fragments per group2008 inodes per groupSuperblock backups stored on blocks:8193, 24577, 40961, 57345, 73729, 204801, 221185Writing inode tables: doneCreating journal (4096 blocks): doneWriting superblocks and filesystem accounting information: doneThis filesystem will be automatically checked every 35 mounts or180 days, whichever comes first. Use tune2fs -c or -i to override.[root@localhost ~]# mount /dev/md2 /mnt/sdb2/

8.查看raid資訊


[root@localhost ~]# cat /proc/mdstatPersonalities : [raid0] [raid1] [raid6] [raid5] [raid4]md2 : active raid5 sdd3[3] sdc3[1] sdb3[0]224256 blocks super 1.2 level 5, 512k chunk, algorithm 2 [3/3] [UUU]md1 : active raid1 sdc2[1] sdb2[0]112320 blocks super 1.2 [2/2] [UU]md0 : active raid0 sdc1[1] sdb1[0]224256 blocks super 1.2 512k chunksunused devices: <none>[root@localhost ~]# df -THFilesystem Type Size Used Avail Use% Mounted on/dev/mapper/VolGroup-lv_rootext4 6.9G 6.4G 166M 98% /tmpfs tmpfs 262M 0 262M 0% /dev/shm/dev/sda1ext4 508M 48M 435M 10% /boot/dev/md0ext4 223M 6.4M 205M 3% /mnt/sdb/dev/md1ext4 112M 5.8M 100M 6% /mnt/sdb1/dev/md2ext4 223M 6.4M 205M 3% /mnt/sdb2[root@localhost ~]#

9.raid故障恢複和用raid使用邏輯卷(lvm)


[root@localhost ~]# mdadm -a /dev/md2 /dev/sdd1 --在raid5中添加一塊分區mdadm: added /dev/sdd1[root@localhost ~]# mdadm -f /dev/md2 /dev/sdd3 --將raid5中的第三個分區變為失效mdadm: set/dev/sdd3faulty in/dev/md2[root@localhost ~]# mdadm -r /dev/md2 /dev/sdd3 --移除raid5中的第三個分區mdadm: hot removed /dev/sdd3from /dev/md2[root@localhost ~]# cat /proc/mdstatPersonalities : [raid0] [raid1] [raid6] [raid5] [raid4]md2 : active raid5 sdd1[4] sdc3[1] sdb3[0] --查看raid5中的所有分區224256 blocks super 1.2 level 5, 512k chunk, algorithm 2 [3/3] [UUU]md1 : active raid1 sdc2[1] sdb2[0]112320 blocks super 1.2 [2/2] [UU]md0 : active raid0 sdc1[1] sdb1[0]224256 blocks super 1.2 512k chunksunused devices: <none>[root@localhost ~]# pvcreate /dev/md2 --將raid5轉換成物理卷Physical volume "/dev/md2"successfully created[root@localhost ~]# vgcreate vg0 /dev/md2 --物理卷組成卷組Volume group "vg0"successfully created[root@localhost ~]# lvcreate -L 150M -n test /dev/vg0 --從卷組中劃分邏輯卷Rounding up size to full physical extent 152.00 MiBLogical volume "test"created[root@localhost ~]# mkfs.ext4 /dev/vg0/test --格式化邏輯卷mke2fs 1.41.12 (17-May-2010)Filesystem label=OS type: LinuxBlock size=1024 (log=0)Fragment size=1024 (log=0)Stride=512 blocks, Stripe width=1024 blocks38912 inodes, 155648 blocks7782 blocks (5.00%) reserved forthe super userFirst data block=1Maximum filesystem blocks=6737100819 block groups8192 blocks per group, 8192 fragments per group2048 inodes per groupSuperblock backups stored on blocks:8193, 24577, 40961, 57345, 73729Writing inode tables: doneCreating journal (4096 blocks): doneWriting superblocks and filesystem accounting information: doneThis filesystem will be automatically checked every 36 mounts or180 days, whichever comes first. Use tune2fs -c or -i to override.[root@localhost ~]# mount /dev/vg0/test /mnt/sdb2/ --掛載[root@localhost ~]# df -THFilesystem Type Size Used Avail Use% Mounted on/dev/mapper/VolGroup-lv_rootext4 6.9G 6.4G 166M 98% /tmpfs tmpfs 262M 0 262M 0% /dev/shm/dev/sda1ext4 508M 48M 435M 10% /boot/dev/md0ext4 223M 6.4M 205M 3% /mnt/sdb/dev/md1ext4 112M 5.8M 100M 6% /mnt/sdb1/dev/mapper/vg0-testext4 155M 5.8M 141M 4% /mnt/sdb2[root@localhost ~]#


linux系統中對邏輯卷(lvm)的實現:http://tongcheng.blog.51cto.com/6214144/1350144

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.