磁盘管理综合测试题

系统管理09-磁盘管理综合测试题

磁盘管理综合测试题

一、实验需求

1、用户需把/dev/myvg/mylv逻辑卷以支持磁盘配额的方式挂载到网页目录下

2、在网页目录下创建测试文件index.html,内容为用户名称,通过浏览器访问测试

3、创建用户账户,对LVM配置磁盘配额限制用户磁盘容量为软限制80M;硬限制100M、文件数量软限制为80个;硬限制为100个。

yum仓库构建以及源代码安装请参考:https://www.cnblogs.com/elin989898/p/11255514.html

二、实验拓扑

 

三、实验步骤

  1. 实验环境

Centos7  创建3个硬盘,每个硬盘20G  制作成RAID

       2.   实验准备

添加3块20G大小的SCSI硬盘

 

 

   3.  实验步骤

3.1 创建磁盘,为磁盘分区,制作RAID5硬盘

[root@localhost ~]# fdisk -l |grep "/dev/"     //检查所添加的磁盘

磁盘 /dev/sda42.9 GB, 42949672960 字节,83886080 个扇区

/dev/sda1   *        2048     2099199     1048576   83  Linux

/dev/sda2         2099200    83886079    40893440   8e  Linux LVM

磁盘 /dev/sdb21.5 GB, 21474836480 字节,41943040 个扇区

磁盘 /dev/sdc21.5 GB, 21474836480 字节,41943040 个扇区

磁盘 /dev/sdd21.5 GB, 21474836480 字节,41943040 个扇区

磁盘 /dev/mapper/centos-root39.7 GB, 39720058880 字节,77578240 个扇区

磁盘 /dev/mapper/centos-swap2147 MB, 2147483648 字节,4194304 个扇区

[root@localhost ~]# fdisk /dev/sdb        //对sdb磁盘进行分区

欢迎使用 fdisk (util-linux 2.23.2)

更改将停留在内存中,直到您决定将更改写入磁盘。

使用写入命令前请三思。

Device does not contain a recognized partition table

使用磁盘标识符 0x8bc47fb9 创建新的 DOS 磁盘标签。

命令(输入 m 获取帮助)n

Partition type:

   p   primary (0 primary, 0 extended, 4 free)

   e   extended

Select (default p): p

分区号 (1-4,默认 1)

起始 扇区 (2048-41943039,默认为 2048)

将使用默认值 2048

Last 扇区, +扇区 or +size{K,M,G} (2048-41943039,默认为 41943039)

将使用默认值 41943039

分区 1 已设置为 Linux 类型,大小设为 20 GiB

 

命令(输入 m 获取帮助)t

已选择分区 1

Hex 代码(输入 L 列出所有代码)fd

已将分区Linux”的类型更改为“Linux raid autodetect

 

命令(输入 m 获取帮助)p

 

磁盘 /dev/sdb21.5 GB, 21474836480 字节,41943040 个扇区

Units = 扇区 of 1 * 512 = 512 bytes

扇区大小(逻辑/物理)512 字节 / 512 字节

I/O 大小(最小/最佳)512 字节 / 512 字节

磁盘标签类型:dos

磁盘标识符:0x8bc47fb9

 

   设备 Boot      Start         End      Blocks   Id  System

/dev/sdb1            2048    41943039    20970496   fd  Linux raid autodetect

 

命令(输入 m 获取帮助)w

The partition table has been altered!

 

Calling ioctl() to re-read partition table.

正在同步磁盘。

[root@localhost ~]# fdisk /dev/sdc

欢迎使用 fdisk (util-linux 2.23.2)

 

更改将停留在内存中,直到您决定将更改写入磁盘。

使用写入命令前请三思。

 

Device does not contain a recognized partition table

使用磁盘标识符 0x4f78eab9 创建新的 DOS 磁盘标签。 

命令(输入 m 获取帮助)n

Partition type:

   p   primary (0 primary, 0 extended, 4 free)

   e   extended

Select (default p): p

分区号 (1-4,默认 1)

起始 扇区 (2048-41943039,默认为 2048)

将使用默认值 2048

Last 扇区, +扇区 or +size{K,M,G} (2048-41943039,默认为 41943039)

将使用默认值 41943039

分区 1 已设置为 Linux 类型,大小设为 20 GiB

 

命令(输入 m 获取帮助)t

已选择分区 1

Hex 代码(输入 L 列出所有代码)fd

已将分区Linux”的类型更改为“Linux raid autodetect

 

命令(输入 m 获取帮助)p

 

磁盘 /dev/sdc21.5 GB, 21474836480 字节,41943040 个扇区

Units = 扇区 of 1 * 512 = 512 bytes

扇区大小(逻辑/物理)512 字节 / 512 字节

I/O 大小(最小/最佳)512 字节 / 512 字节

磁盘标签类型:dos

磁盘标识符:0x4f78eab9

 

   设备 Boot      Start         End      Blocks   Id  System

/dev/sdc1            2048    41943039    20970496   fd  Linux raid autodetect

 

命令(输入 m 获取帮助)w

The partition table has been altered!

 

Calling ioctl() to re-read partition table.

正在同步磁盘。

[root@localhost ~]# fdisk /dev/sdd

欢迎使用 fdisk (util-linux 2.23.2)

 

更改将停留在内存中,直到您决定将更改写入磁盘。

使用写入命令前请三思。

 

Device does not contain a recognized partition table

使用磁盘标识符 0xd112d2c3 创建新的 DOS 磁盘标签。

 

命令(输入 m 获取帮助)n

Partition type:

   p   primary (0 primary, 0 extended, 4 free)

   e   extended

Select (default p): p

分区号 (1-4,默认 1)

起始 扇区 (2048-41943039,默认为 2048)

将使用默认值 2048

Last 扇区, +扇区 or +size{K,M,G} (2048-41943039,默认为 41943039)

将使用默认值 41943039

分区 1 已设置为 Linux 类型,大小设为 20 GiB

 

命令(输入 m 获取帮助)t

已选择分区 1

Hex 代码(输入 L 列出所有代码)fd

已将分区Linux”的类型更改为“Linux raid autodetect

 

命令(输入 m 获取帮助)p

 

磁盘 /dev/sdd21.5 GB, 21474836480 字节,41943040 个扇区

Units = 扇区 of 1 * 512 = 512 bytes

扇区大小(逻辑/物理)512 字节 / 512 字节

I/O 大小(最小/最佳)512 字节 / 512 字节

磁盘标签类型:dos

磁盘标识符:0xd112d2c3

 

   设备 Boot      Start         End      Blocks   Id  System

/dev/sdd1            2048    41943039    20970496   fd  Linux raid autodetect

 

命令(输入 m 获取帮助)w

The partition table has been altered!

 

Calling ioctl() to re-read partition table.

正在同步磁盘。

[root@localhost ~]# fdisk -l |grep "raid"  //查看分区后的硬盘

/dev/sdb1            2048    41943039    20970496   fd  Linux raid autodetect

/dev/sdc1            2048    41943039    20970496   fd  Linux raid autodetect

/dev/sdd1            2048    41943039    20970496   fd  Linux raid autodetect

[root@localhost ~]# mdadm -Cv /dev/md5 -l5 -n3 /dev/sd[bcd]1   //制作raid5  -C 创建 -l 指定级别 -n 磁盘活跃个数

mdadm: layout defaults to left-symmetric

mdadm: layout defaults to left-symmetric

mdadm: chunk size defaults to 512K

mdadm: size set to 20954112K

mdadm: Defaulting to version 1.2 metadata

mdadm: array /dev/md5 started.

3.2  raid5 创建物理卷,卷组,逻辑卷

 

[root@localhost ~]# pvcreate /dev/md5     //创建物理卷

  Physical volume "/dev/md5" successfully created.

[root@localhost ~]# vgcreate myvg /dev/md5  //创建卷组 myvg 

  Volume group "myvg" successfully created

 

[root@localhost ~]# lvcreate -L 35G -n mylv myvg   //创建逻辑卷mylv,并指定大小

  Logical volume "mylv" created.

3.3  格式化成ext4文件系统,并挂载到/usr/local/apache/htdocs 目录位置下面

[root@localhost ~]# mkfs.ext4 /dev/myvg/mylv    //将硬盘格式化成ext4 文件系统

mke2fs 1.42.9 (28-Dec-2013)

文件系统标签=

OS type: Linux

块大小=4096 (log=2)

分块大小=4096 (log=2)

Stride=128 blocks, Stripe width=256 blocks

2293760 inodes, 9175040 blocks

458752 blocks (5.00%) reserved for the super user

第一个数据块=0

Maximum filesystem blocks=2157969408

280 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

 

Allocating group tables: 完成                            

正在写入inode: 完成                            

Creating journal (32768 blocks): 完成

Writing superblocks and filesystem accounting information: 完成 

[root@localhost ~]# mount /dev/myvg/mylv /usr/local/apache/htdocs    //挂载硬盘到 /usr/local/apache/htdocs目录下面

[root@localhost ~]# mount -o remount,usrquota,grpquota /usr/local/apache/htdocs   //将remount,usrquota,grpquota 镜像挂载到/usr/local/apache/htdocs 目录下面

[root@localhost ~]# mount |grep /usr/local/apache/htdocs    //检索 

/dev/mapper/myvg-mylv on /usr/local/apache/htdocs type ext4 (rw,relatime,quota,usrquota,grpquota,stripe=256,data=ordered)

[root@localhost ~]# vi /etc/fstab     // 向文件中添加以下内容

/dev/myvg/mylv       /usr/local/apache/htdocs   ext4    defaults,usrquota,grpquota  0 0

[root@localhost ~]# quotacheck -avug    //扫描文件系统并建立Quota 记录文件

quotacheck: Your kernel probably supports journaled quota but you are not using it. Consider switching to journaled quota to avoid running quotacheck after an unclean shutdown.

quotacheck: Scanning /dev/mapper/myvg-mylv [/usr/local/apache/htdocs] done

quotacheck: Cannot stat old user quota file /usr/local/apache/htdocs/aquota.user: 没有那个文件或目录. Usage will not be subtracted.

quotacheck: Cannot stat old group quota file /usr/local/apache/htdocs/aquota.group: 没有那个文件或目录. Usage will not be subtracted.

quotacheck: Cannot stat old user quota file /usr/local/apache/htdocs/aquota.user: 没有那个文件或目录. Usage will not be subtracted.

quotacheck: Cannot stat old group quota file /usr/local/apache/htdocs/aquota.group: 没有那个文件或目录. Usage will not be subtracted.

quotacheck: Checked 2 directories and 0 files

quotacheck: Old file not found.

quotacheck: Old file not found.

[root@localhost ~]# quotaon -auvg

/dev/mapper/myvg-mylv [/usr/local/apache/htdocs]: group quotas turned on

/dev/mapper/myvg-mylv [/usr/local/apache/htdocs]: user quotas turned on

3.4 创建测试文件,并添加内容

[root@localhost ~]# vi /usr/local/apache/htdocs/index.html   //添加以下内容

 hello,everyone!

my name is jilinlin!

nice to miss you!

[root@localhost ~]# /usr/local/apache/bin/apachectl start

[root@localhost ~]# lynx 127.0.0.1

 

3.5  添加用户并进行测试

[root@localhost ~]# useradd jll

[root@localhost ~]# edquota -u jll          //并进行编辑

Disk quotas for user jll (uid 1001):

Disk quotas for user jll (uid 1001):

  Filesystem                              blocks       soft       hard     inodes     soft     hard

  /dev/mapper/myvg-mylv             0          80M      100M      0        80        100

[root@localhost ~]# ll /usr/local/apache/htdocs/

总用量 36

-rw------- 1 root root  6144 8月   5 14:39 aquota.group

-rw------- 1 root root  7168 8月   5 14:39 aquota.user

-rw-r--r-- 1 root root    55 8月   5 15:15 index.html

drwx------ 2 root root 16384 8月   5 14:23 lost+found

[root@localhost ~]# chmod -R 777 /usr/local/apache/htdocs

chmod: 更改"/usr/local/apache/htdocs/aquota.group" 的权限: 不允许的操作

chmod: 更改"/usr/local/apache/htdocs/aquota.user" 的权限: 不允许的操作

[root@localhost ~]# ll /usr/local/apache/htdocs/

总用量 36

-rw------- 1 root root  6144 8月   5 14:39 aquota.group

-rw------- 1 root root  7168 8月   5 14:39 aquota.user

-rwxrwxrwx 1 root root    55 8月   5 15:15 index.html

drwxrwxrwx 2 root root 16384 8月   5 14:23 lost+found

[root@localhost ~]# su jll

[jll@localhost root]$ cd ~

[jll@localhost ~]$ dd if=/dev/zero of=/usr/local/apache/htdocs/ceshi.txt bs=1M count=400

 

dd: 写入"/usr/local/apache/htdocs/ceshi" 出错: 超出磁盘限额

[jll@localhost ~]$ cd /usr/local/apache/htdocs/

[jll@localhost htdocs]$ touch a{1..70}.txt                 //创建测试文件夹,看是否

[jll@localhost htdocs]$ touch b{1..20}.txt

dm-2: warning, user file quota exceeded.

[jll@localhost htdocs]$ touch c{1..15}.txt

dm-2: write failed, user file limit reached.

touch: 无法创建"c10.txt": 超出磁盘限额

touch: 无法创建"c11.txt": 超出磁盘限额

touch: 无法创建"c12.txt": 超出磁盘限额

touch: 无法创建"c13.txt": 超出磁盘限额

touch: 无法创建"c14.txt": 超出磁盘限额

touch: 无法创建"c15.txt": 超出磁盘限额

 

原文地址:https://www.cnblogs.com/elin989898/p/11303317.html