N26-第七周博客作业

一、创建一个10G分区,并格式为ext4文件系统;

1 要求其block大小为2048, 预留空间百分比为2, 卷标为MYDATA, 默认挂载属性包含acl

         A、创建一个10G的磁盘空间

[root@VM_221_40_centos ~]#
fdisk /dev/vdb

Welcome to fdisk (util-linux 2.23.2).

 

Changes will remain in memory only, until you decide to write them.

Be careful before using the write command.

 

 

Command (m for help): p                                                               #查看当前分区情况

 

Disk /dev/vdb: 32.2 GB, 32212254720 bytes, 62914560 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk label type: dos

Disk identifier: 0xaec1a5ab

 

   Device Boot      Start         End      Blocks   Id  System

 

Command (m for help): n                                                                 #新建一个分区

Partition type:

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

   e   extended

Select (default p): p                                                                            #选择分区类型为主分区

Partition number (1-4, default 1): 1                                               #分区编号为1

First sector (2048-62914559, default 2048):                           #输入磁盘空间开始的块的序号。不输入任何数字为默认值2048

Using default value 2048                                                                  #提示信息:使用默认值2048

Last sector, +sectors or +size{K,M,G} (2048-62914559, default
62914559): +10G                  #
输入磁盘空间大小:10G

Partition 1 of type Linux and of size 10 GiB is set                      #反馈信息:类型为linux、空间为10G的分区1已经设定

 

Command (m for help): p                                                                 #查看当前分区信息

 

Disk /dev/vdb: 32.2 GB, 32212254720 bytes, 62914560 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk label type: dos

Disk identifier: 0xaec1a5ab

 

   Device Boot      Start         End      Blocks   Id  System

/dev/vdb1            2048    20973567    10485760   83  Linux

#创建的分区的信息。设备路径:/dev/vdb1、开始柱面:2048、结束柱面:20973567、总共有10485760个块、分区ID83、分区类型:linux

Command (m for help): w                                                                #输入w 保存操作并退出

The partition table has been altered!                                           #提示分区表已经改变

 

Calling ioctl() to re-read partition table.

Syncing disks.

[root@VM_221_40_centos ~]#

B、创建文件系统

[root@VM_221_40_centos ~]# mke2fs -t ext4 -b 2048 -L MYDATA -m 2 -O
has_journal /dev/vdb1

mke2fs 1.42.9 (28-Dec-2013)

Filesystem label=MYDATA                                                                         #标签

OS type: Linux                                                                                               #文件系统类型

Block size=2048 (log=1)                                                                             #块大小2048

Fragment size=2048 (log=1)

Stride=0 blocks, Stripe width=0 blocks

655360 inodes, 5242880 blocks                                                               #文件系统的inodeblock数量

104857 blocks (2.00%) reserved for the super user                           #预留空间百分比

First data block=0

Maximum filesystem blocks=273678336

320 block groups                                                                                          #块组数量

16384 blocks per group, 16384 fragments per group                        #每组16384个块

2048 inodes per group                                                                               #每个块组中有2048inode

Superblock backups stored on blocks:                                                  #超级块备份在哪些块中

         16384, 49152, 81920,
114688, 147456, 409600, 442368, 802816, 1327104,

         2048000, 3981312

 

Allocating group tables: done                           

Writing inode tables: done                           

Creating journal (32768 blocks): done

Writing superblocks and filesystem accounting information: done  

 

[root@VM_221_40_centos ~]#

 

2、挂载至/data/mydata目录,要求挂载时禁止程序自动运行,且不更新文件的访问时间戳;

[root@VM_221_40_centos
~]# mkdir /data/mydata

[root@VM_221_40_centos
~]# mount -o noexec,noatime /dev/vdb1 /data/mydata

也可在/etc/fstab文件中新增一行

/dev/vdb1                /data/mydata                            ext4          defaults,noexec,noatime       0 0

         写入保存退出后,运行mount
–a
,再运行mount命令查看己挂载的项

 

、创建一个大小为1Gswap分区,并创建好文件系统,并启用之;

[root@VM_221_40_centos ~]# fdisk /dev/vdb

Welcome to fdisk (util-linux 2.23.2).

 

Changes will remain in memory only, until you decide to write them.

Be careful before using the write command.

 

 

Command (m for help): p

 

Disk /dev/vdb: 32.2 GB, 32212254720 bytes, 62914560 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk label type: dos

Disk identifier: 0xaec1a5ab

 

   Device Boot      Start         End      Blocks   Id  System

/dev/vdb1            2048    20973567    10485760   83  Linux

 

Command (m for help): n

Partition type:

   p   primary (1 primary, 0 extended, 3 free)

   e   extended

Select (default p): p

Partition number (2-4, default 2): 2

First sector (20973568-62914559, default 20973568):

Using default value 20973568

Last sector, +sectors or +size{K,M,G} (20973568-62914559, default
62914559): +1G           #
设置分区大小为1G

Partition 2 of type Linux and of size 1 GiB is set

 

Command (m for help): t                                                                  #修改分区类型

 

Partition number (1,2, default 2): 2

Hex code (type L to list all codes): 82                                                     #输入分区类型

Changed type of partition ‘Old Minix’ to ‘Linux swap / Solaris’

 

Command (m for help): p                                                                           #查看当前分区状态

 

Disk /dev/vdb: 32.2 GB, 32212254720 bytes, 62914560 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk label type: dos

Disk identifier: 0xaec1a5ab

 

   Device Boot      Start         End      Blocks   Id  System

/dev/vdb1            2048    20973567    10485760   83  Linux

/dev/vdb2        20973568    23070719     1048576   82  Linux swap / Solaris

 

Command (m for help): w                                                                          #保存退出

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 or after you run partprobe(8) or kpartx(8)

Syncing disks.

[root@VM_221_40_centos ~]#

 

[root@VM_221_40_centos ~]# partx -a /dev/vdb                             #读取分区

partx: /dev/vdb: error adding partitions 1-2

[root@VM_221_40_centos ~]# fdisk -l /dev/vdb                                #查看/dev/vdb分区信息

 

Disk /dev/vdb: 32.2 GB, 32212254720 bytes, 62914560 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk label type: dos

Disk identifier: 0xaec1a5ab

 

   Device Boot      Start         End      Blocks   Id  System

/dev/vdb1            2048    20973567    10485760   83  Linux

/dev/vdb2        20973568    23070719     1048576   82  Linux swap / Solaris            #swap分区己创建完成

[root@VM_221_40_centos ~]#

 

[root@VM_221_40_centos ~]# mkswap /dev/vdb2                          #创建交换分区文件系统

Setting up swapspace version 1, size = 1048572 KiB

no label, UUID=f731fb7d-f408-4088-9fca-ca2b4c39abc4

[root@VM_221_40_centos ~]#

 

[root@VM_221_40_centos ~]# free                                                      #free命令查看当前可用内存

              total        used        free      shared  buff/cache   available

Mem:        1016904      106860      135484       12544      774560      719572

Swap:             0           0           0

[root@VM_221_40_centos ~]# swapon
/dev/vdb2                           #
挂载swap分区

[root@VM_221_40_centos ~]# free                                                      #再次用free命令查看,可以看到已经挂载成功

              total        used        free      shared  buff/cache   available

Mem:        1016904      107348      135004       12544      774552      719096

Swap:       1048572           0     1048572

[root@VM_221_40_centos ~]#

三、写一个脚本

   (1)、获取并列出当前系统上的所有磁盘设备;

   (2)、显示每个磁盘设备上每个分区相关的空间使用信息;

脚本如下:

 

#!/bin/bash

#

#

a=`ls /dev/ | grep “[hsv]d[a-z]”`

echo -e “All of you disk devices is \n$a”

 

filesystem=`df -lh | grep “Filesystem”`

b=`df -lh | grep “^\/dev”`

echo -e “The Disk partition information\n$filesystem\n$b”

 

输出结果:

 

[root@VM_221_40_centos tmp]# ./diskdisplay.sh

All of you disk devices is

vda

vda1

vdb

vdb1

vdb2

The Disk partition information

Filesystem      Size  Used Avail Use% Mounted on

/dev/vda1        20G  1.8G   17G  10% /

/dev/vdb1       9.8G   13M  9.6G   1% /data/mydata

 

四、总结RAID的各个级别及其组合方式和性能的不同;

         RAID的实现方式:

1.         硬件方式:

a)         外接式磁盘阵列:通过PCIPCI-E扩展卡提供适配能力

b)         内接式磁盘阵列:通过主板上集成的RAID控制器

2.         软件方式:

a)         通过软件创建(生产环境中不推荐使用)

RAID的级别

1)         RAID 0

这种模式如通过相同型号、相同容量的磁盘来实现效果极佳。

工作方式:

先把硬盘分切出等量的区块,当文件要写入磁盘中时,把数据依据磁盘区块大小切割好,再依序交错存入磁盘。如一个数据文件有100MB,每个磁盘会各存入50MB

工作方式如下图:

N26-第七周博客作业

RAID 0的特点:

l  读写能力提升

l  可用空间为最小硬盘容量乘以硬盘块数。

l  无容错能力,若其中一块硬盘有故障,会导致数据缺失。

l  最少硬盘块数:2

2)         RAID 1

工作方式:

先把硬盘分切出等量的区块,当文件要写入磁盘中时,把数据依据磁盘区块大小切割好,再存入各磁盘各一份。

如保存一份文件时,两个磁盘都会保存一份完整的文件。

N26-第七周博客作业

RAID 1 镜像卷(mirror)特点:

l  读性能提升,写性能略有下降

l  可用空间:最小磁盘空间*1

l  有容错能力

l  最少磁盘个数:2

3)         RAID 4

RAID 4工作方式:

两块硬盘做数据盘,另外一块硬盘专门来做校验盘。

数据保存时,按异或运算保存数据。

即当硬盘1保存的数据为1011,硬盘2保存的数据为1100,硬盘3中的数据以10111100作异或运算即为0111

N26-第七周博客作业

RAID 4特点:

l  至少需要三块硬盘

l  2块硬盘做数据盘,1块硬盘做校验盘(文件读写时都需访问该硬盘,工作压力大)。

l  有容错能力,允许坏一块硬盘。当坏一块硬盘的时候,为降级工作模式。可读写,但不推荐。

l  可用空间:(N-1*最小硬盘空间

 

4)         RAID 5

RAID5工作方式:

RAID4,不过为三块硬盘轮流做校验盘。

特点:

l  至少需要三块硬盘

l  三块硬盘轮流做校验盘。

l  有容错能力,允许坏一块硬盘。当坏一块硬盘的时候,为降级工作模式。可读写,但不推荐。

l  可用空间:(N-1*最小硬盘空间

工作方式见下图:

N26-第七周博客作业 

5)         RAID 6

实现方式:至少由四块硬盘构成。两块硬盘数据,另外两块硬盘轮流做校验盘。

特点:

l  最少需4块硬盘

l  读写能力提升

l  有容错能力,可坏2块硬盘而不影响数据。

l  可用空间(N-2*最小磁盘空间大小

工作方式见下图:

N26-第七周博客作业

6)         RAID10

构成方式:

假设有四块硬盘,分别为1234。硬盘12构成一组RAID 1,硬盘34构成一组RAID 1。这两组RAID 1再组成一组RAID 0

N26-第七周博客作业

RAID 10特点:

l  读写能力提升

l  有容错能力。每组RAID
1
允许坏一块硬盘而不影响数据完整性。

l  可用空间为N*较小硬盘空间大小*50%

l  至少需要用4块硬盘

7)         RAID 01

假设有四块硬盘,分别为1234。硬盘12构成一组RAID 0,硬盘34构成一组RAID 0。这两组RAID 0再组成一组RAID 1

结构图如下:

N26-第七周博客作业

RAID 01特点:

l  读写能力提升

l  有容错能力。可以一组RAID0同时坏而不影响数据完整性。

l  可用空间为N*较小硬盘空间大小*50%

l  至少需要用4块硬盘

 

 

五、创建一个大小为10GRAID1,要求有一个空闲盘,而且CHUNK大小为128k;

         1、创建三个磁盘,状态如下

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

Units = 扇区 of 1 * 512 = 512 bytes

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

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

磁盘标签类型:dos

磁盘标识符:0x6100c71b

 

   设备 Boot      Start         End      Blocks   Id  System

/dev/sdb1            2048    41943039    20970496   fd  Linux raid autodetect

 

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

Units = 扇区 of 1 * 512 = 512 bytes

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

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

磁盘标签类型:dos

磁盘标识符:0xa5e6f16a

 

   设备 Boot      Start         End      Blocks   Id  System

/dev/sdc1            2048    41943039    20970496   fd  Linux raid autodetect

 

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

Units = 扇区 of 1 * 512 = 512 bytes

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

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

磁盘标签类型:dos

磁盘标识符:0xdbe93c5b

 

   设备 Boot      Start         End      Blocks   Id  System

/dev/sdd1            2048    41943039    20970496   fd  Linux raid autodetect

         2[root@promote ~]# mdadm -C /dev/md0 -a yes -n 2 -l 1 -x 1 -c 128
/dev/sd{b,c,d} 

                   #创建块大小为128k,有两块磁盘,冗余一块磁盘的raid1

mdadm: /dev/sdb appears to be part of a raid array:

       level=raid5 devices=4
ctime=Sun Jul  9 04:47:10 2017

mdadm: partition table exists on /dev/sdb but will be lost or

       meaningless after
creating array

mdadm: Note: this array has metadata at the start and

    may not be suitable as a
boot device.  If you plan to

    store ‘/boot’ on this
device please ensure that

    your boot-loader
understands md/v1.x metadata, or use

    –metadata=0.90

mdadm: /dev/sdc appears to be part of a raid array:

       level=raid5 devices=4
ctime=Sun Jul  9 04:47:10 2017

mdadm: partition table exists on /dev/sdc but will be lost or

       meaningless after
creating array

mdadm: /dev/sdd appears to be part of a raid array:

       level=raid5 devices=4
ctime=Sun Jul  9 04:47:10 2017

mdadm: partition table exists on /dev/sdd but will be lost or

       meaningless after
creating array

Continue creating array? y

mdadm: Defaulting to version 1.2 metadata

mdadm: array /dev/md0 started.

[root@promote ~]# cat /proc/mdstat                                          #查看状态

Personalities : [raid6] [raid5] [raid4] [raid1]

md0 : active raid1 sdd[2](S) sdc[1] sdb[0]

      20955136 blocks super
1.2 [2/2] [UU]

      [===========>………]  resync
= 58.2% (12203264/20955136) finish=0.7min speed=200040K/sec

 

unused devices: <none>

[root@promote ~]#

六、创建一个大小为4GRAID5设备,chunk大小为256k,格式化ext4文件系统,要求可开机自动挂载至/backup目录,而且不更新访问时间戳,且支持acl功能;

 

         1、先创建三个空白磁盘空间,大小都为2G,分区类型改为raid可用的Linux raid autodetect

2[root@promote ~]# mdadm -C /dev/md0 -a yes -n 3 -l 5 -c 256
/dev/sdb{1,2,3}                #
创建RAID5设备

mdadm: /dev/sdb1 appears to be part of a raid array:

       level=raid0 devices=0
ctime=Thu Jan  1 08:00:00 1970

mdadm: partition table exists on /dev/sdb1 but will be lost or

       meaningless after
creating array

Continue creating array? y

mdadm: Defaulting to version 1.2 metadata

mdadm: array /dev/md0 started.

[root@promote ~]# mdadm -D
/dev/md0                              #
查看设备信息

/dev/md0:

        Version : 1.2

  Creation Time : Mon Jul 10
00:13:18 2017

     Raid Level : raid5

     Array Size : 4190208
(4.00 GiB 4.29 GB)

  Used Dev Size : 2095104
(2046.34 MiB 2145.39 MB)

   Raid Devices : 3

  Total Devices : 3

    Persistence : Superblock
is persistent

 

    Update Time : Mon Jul 10
00:13:28 2017

          State : clean

 Active Devices : 3

Working Devices : 3

 Failed Devices : 0

  Spare Devices : 0

 

         Layout :
left-symmetric

     Chunk Size : 256K

 

           Name :
promote.cache-dns.local:0  (local to host
promote.cache-dns.local)

           UUID :
a862f385:88ce921d:85b08e3e:3116ff37

         Events : 18

 

    Number   Major   Minor   RaidDevice State

       0       8       17        0      active sync   /dev/sdb1

       1       8       18        1      active sync   /dev/sdb2

       3       8       19        2      active sync   /dev/sdb3

3[root@promote ~]# mkfs.ext4 /dev/md0                                  #创建文件系统

mke2fs 1.42.9 (28-Dec-2013)

文件系统标签=

OS type: Linux

块大小=4096
(log=2)

分块大小=4096
(log=2)

Stride=64 blocks, Stripe width=128 blocks

262144 inodes, 1047552 blocks

52377 blocks (5.00%) reserved for the super user

第一个数据块=0

Maximum filesystem blocks=1073741824

32 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

 

Allocating group tables: 完成

正在写入inode: 完成

Creating journal (16384 blocks): 完成

Writing superblocks and filesystem accounting information: 完成

4、创建文件夹

[root@promote ~]# mkdir /backup

5、编辑/etc/fstab文件,新增一行,内容如下:

         /dev/md0                /backup                 ext4    defaults,acl,noatime    0 0

6、运行mount -a 挂载fstab文件中的所有挂载项,然后查找是否挂载成功。

[root@promote ~]# mount -a

[root@promote ~]# mount | grep md0

/dev/md0 on /backup type ext4
(rw,noatime,seclabel,stripe=128,data=ordered)

 

七、写一个脚本

   (1) 接受一个以上文件路径作为参数;

   (2) 显示每个文件拥有的行数;

   (3) 总结说明本次共为几个文件统计了其行数;

#!/bin/bash

#

echo “the pwd is $@”

for i in $@;do

        lines=`wc -l $i | cut
-d ‘ ‘ -f1 `

        echo “the lines
of $i is $lines”

done

        echo “the total
files is $#”

八、写一个脚本

   (1) 传递两个以上字符串当作用户名;

   (2) 创建这些用户;且密码同用户名;

   (3) 总结说明共创建了几个用户;

                   #!/bin/bash

#

if [ $# -lt 1 ];then

        echo “need more
than 2 strings”

        exit 2

fi

for username in $@;do

        if id $username
&>/dev/null;then

                echo
“$username is exists”

        else

                useradd
$username

                echo
“$username” | passwd –stdin $username

fi

done

九、写一个脚本,新建20个用户,visitor1-visitor20;计算他们的ID之和;

#!/bin/bash

#

sum=0

for user in visitor{1..20};do

        useradd $user

        idnum=`id -u $user`

        let sum=$sum+$idnum

done

echo “uidsum is $sum”

原创文章,作者:lixinkuan,如若转载,请注明出处:http://www.178linux.com/79620

(0)
上一篇 2017-07-09 16:53
下一篇 2017-07-09 17:32

相关推荐

  • 马哥教育网络21期+第三周练习博客

    1、列出当前系统上所有已经登录的用户的用户名,注意:同一个用户登录多次,则只显示一次即可。 [root@localhost ~]# who | cut -d' ' -f 1 | uniq 2、取出最后登录到当前系统的用户的相关信息。 [root…

    Linux干货 2016-07-26
  • Vsftpd+MySQL实现虚拟用户验证登录

    一、安装所需要包和包组: 在数据库服务器上安装包: yum –y install mariadb-server mariadb-devel systemctl start mariadb.service systemctl enable mariadb 在FTP服务器上安装包pam_mysql centos7:无对应rpm包,需…

    Linux干货 2017-08-14
  • GOPS2017全球运维大会 • 深圳站将在深圳召开!

    第六届GOPS2017全球运维大会(本次)将于2017年4月21日-22日在深圳举行,历届金牌讲师精选亮相,各种精彩等您发掘。活动家为GOPS2017全球运维大会提供在线报名!在线报名地址:https://www.huodongjia.com/event-231365274.html 大会亮点 众多国外重量级嘉宾在路上 ► 目前正在和各位大咖商榷行程中,主会…

    2017-04-10
  • grep的用法(CentOS7)及有关正则表达式的使用

    http://www.cnblogs.com/wzhuo/p/6659352.html

    Linux干货 2017-04-08
  • N27_第六周作业

    请详细总结vim编辑器的使用并完成以下练习题 基本模式:编辑模式(命令模式),输入模式,末行模式 模式转换: 编辑模式–输入模式: i:insert,在光标所在处前方输入 a:append,在光标所在处后方输入 o:在光标所在处的下方新建一行 I:在光标所在行行首输入 A:在光标所在处行尾输入 O:在光标所在处的上方打开一个新行 输入模式&#82…

    Linux干货 2017-10-26
  • liunx初探

    计算机的五大单元: 输出单元、输入单元、cpu内部控制单元、算术逻辑单元和内存。 计算机三大组成部分: 输入单元:键盘、鼠标等等 输出单元:屏幕、打印机等 中央处理器(CPU):含有算术逻辑、控制、记忆等 CPU种类有两种分别是:   精简指令集(RISC):这种cpu微指令比较精简,每个指令的执行时间都很短,完成的操作也很简单。常见的简单指令集C…

    Linux干货 2016-09-14

评论列表(1条)

  • 马哥教育
    马哥教育 2017-07-13 17:14

    可以看出有在很认真的整理,这些将来都是自己的理论积累,加油。