N25-第七周作业

第七周

1、创建一个10G分区,并格式为ext4文件系统; (1) 要求其block大小为2048, 预留空间百分比为2, 卷标为MYDATA, 默认挂载属性包含acl;

[root@zf ~]# fdisk  /dev/sdb  

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

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

[root@zf ~]# mkfs -t ext4 -b 2048 -L MYDATA -m2 /dev/sdb1
    mke2fs 1.41.12 (17-May-2010)
    文件系统标签=MYDATA
    操作系统:Linux
    块大小=2048 (log=1)
    分块大小=2048 (log=1)
    Stride=0 blocks, Stripe width=0 blocks
    655360 inodes, 5241190 blocks
    104823 blocks (2.00%) reserved for the super user
    ...

[root@zf ~]# tune2fs -o acl /dev/sdb1   
[root@zf ~]# tune2fs -l /dev/sdb1    
    tune2fs 1.41.12 (17-May-2010)
    Filesystem volume name:   MYDATA
    Last mounted on:          <not available>
    Filesystem UUID:          87fcd186-1115-4f84-8dad-b171e380771f
    Filesystem magic number:  0xEF53
    Filesystem revision #:    1 (dynamic)
    Filesystem features:      has_journal ext_attr resize_inode dir_index filetype needs_recovery extent flex_bg sparse_super huge_file uninit_bg dir_nlink extra_isize
    Filesystem flags:         signed_directory_hash 
    Default mount options:    acl   
    ...

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

    [root@zf ~]# mount -o noexec,noatime /dev/sdb1 /data/mydata/
    [root@zf ~]# mount
    /dev/sda2 on / type ext4 (rw)
    ...
    /dev/sdb1 on /data/mydata type ext4 (rw,noexec,noatime)

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

[root@zf ~]# fdisk  /dev/sdb  

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

Command (m for help): p
...

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        1306    10490413+  83  Linux
/dev/sdb2            1307        1438     1060290   83  Linux

Command (m for help): t
Partition number (1-4): 2
Hex code (type L to list codes): 82
Changed system type of partition 2 to 82 (Linux swap / Solaris)

Command (m for help): p
...

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        1306    10490413+  83  Linux
/dev/sdb2            1307        1438     1060290   82  Linux swap / Solaris

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

[root@zf ~]# partx -a /dev/sdb
[root@zf ~]# mkswap /dev/sdb2
Setting up swapspace version 1, size = 1060284 KiB
no label, UUID=3ca73dc3-92f9-4fcf-8098-76d21f5e81c3

[root@zf ~]# free -m
             total       used       free     shared    buffers     cached
Mem:           980        412        568          0         18        100
-/+ buffers/cache:        293        687
Swap:         2047          0       2047

[root@zf ~]# swapon /dev/sdb2
[root@zf ~]# free -m         
             total       used       free     shared    buffers     cached
Mem:           980        413        567          0         18        100
-/+ buffers/cache:        294        686
Swap:         3083          0       3083

3、写一个脚本 (1)、获取并列出当前系统上的所有磁盘设备; (2)、显示每个磁盘设备上每个分区相关的空间使用信息;

#!/bin/bash
    #
    fdisk -l /dev/[sh]d[a-z]

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

RAID-0:至少两块硬盘,每个文件分成N块,分别放在每块硬盘上,没有冗错功能;总容量和读写速度都为所有硬盘之和;
   RIAD-1:至少两块硬盘,每块硬盘内容相同,总容量为单块硬盘容量最小的容量,读写为单块硬盘的性能;
   RAID-5:至少3块硬盘,总容量为最小硬盘容量N倍减1,有一块硬盘的容量用来做校验;读性能较好,写性能(要写入校验)稍差;
   RAID-10:至少需要4块硬盘,总容量为最小硬盘的N/2倍,先两个硬盘之间做RAID1,在这个基础上再做RAID0;读写性能较好为N/2;

5、创建一个大小为10G的RAID1,要求有一个空闲盘,而且CHUNK大小为128k;

[root@zf ~]# fdisk /dev/sdb
[root@zf ~]# fdisk /dev/sdc
[root@zf ~]# fdisk /dev/sdd
依次创建大小为10G的sdb1、sdc1、sdd1分区(更改分区类型为Linux raid autodetect)

[root@zf ~]# mdadm -C /dev/md0 -n 2 -l 1 -a yes -c 128K -x 1 /dev/sd{b,c,d}1
-C是创建,-a 自动回答yes -n 用2块磁盘创建,-x 用一块磁盘做空闲, -l 是级别RAID-1 , -c 指定chunk 为128k

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

[root@zf ~]# fdisk /dev/sdb
[root@zf ~]# fdisk /dev/sdc
[root@zf ~]# fdisk /dev/sdd
依次创建大小为1G的sdb2,3、sdc2,3、sdd2分区(更改分区类型为Linux raid autodetect)

[root@zf ~]# mdadm -C /dev/md1 -n 5 -l 5 -a yes -c 256K /dev/sd{b,c,d}2 /dev/sd{b,c}3
-C是创建,-a 自动回答yes -n 用5块磁盘创建,-x 用一块磁盘做空闲, -l 是级别RAID-5 , -c 指定chunk 为256k

[root@zf ~]# mke2fs -t ext4 /dev/md1 -L MYDATA2 
[root@zf ~]# vi /etc/fstab 
...
LABEL=MYDATA2           /backup                 ext4    noatime,acl     0 0

7、写一个脚本 (1) 接受一个以上文件路径作为参数; (2) 显示每个文件拥有的行数; (3) 总结说明本次共为几个文件统计了其行数;

#!/bin/bash
#

sum=0

if [ $# -lt 1 ]; then
        echo "please iput /PATH/TO/SOMEFILE."
        exit 2
fi

for file in $*; do
        if [ -d $file ]; then
                echo "$file is directory."
                exit 3
        else
                lines=$(wc -l $file | cut -d' ' -f1)
                echo "$file has $lines."
                let sum++
        fi
done
        echo "count $sum files."

8、写一个脚本 (1) 传递两个以上字符串当作用户名; (2) 创建这些用户;且密码同用户名; (3) 总结说明共创建了几个用户;

#!/bin/bash
#

sum=0

if [ $# -lt 1 ]; then
        echo "please input username1 username2."
        exit 2
fi

for i in $*; do
        if id $i &> /dev/null; then
                echo "user existed."
        else
                useradd $i
                echo "$i" | passwd --stdin $i &> /dev/null
                echo "useradd $i finished."
                let sum++
        fi
done
        echo "create $sum users."

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

#!/bin/bash
#

for n in {1..20}; do  
        if grep "^visitor$n\>" /etc/passwd &> /dev/null; then
                echo "user existed."
                exit 2
        else
                useradd visitor$n
        fi
done

sum=0
uid=$(grep "^visitor" /etc/passwd | cut -d: -f3)

for i in $uid; do
    let sum+=$i
    let i++ 
done
    echo $sum

原创文章,作者:N25-深圳-寻觅,如若转载,请注明出处:http://www.178linux.com/69942

赞 (0)
N25-深圳-寻觅N25-深圳-寻觅
上一篇 2017-02-24 15:13
下一篇 2017-02-24 19:27

相关推荐

  • Linux软件包管理器—rpm

    rpm 最开始是Red Hat Package Manager 之意,原用在Red Hat Linux一款软件包管理器,先在已被许多其他Linux 发行商使用,成为主流包管理器,rpm包的文件格式也写进Linux标准库中,所以rpm 现在递归意为RPM Package Manager。rpm的诞生使得在Linux上管理软件包变得方便许多,rpm功能强大,可完成构建、安装、查询、校验、升级和卸载软件包。

    Linux干货 2016-08-26
  • Linux 环境 SSD(固态硬盘)使用指南

    原文链接:http://www.jinbuguo.com/storage/ssd_usage.html 前言 因为SSD有着诸多与传统机械式硬盘不同的特点,而且这些特点导致了SSD在实际使用中的性能和寿命与其使用方法紧密相关。所以并不是说买来一块非常牛X的SSD就万事大吉了。另一方面,SSD的性能并不像机械式硬盘那样比较稳定(浮动范围小),而是呈现出一种离散…

    Linux干货 2015-04-08
  • N26-第四周博客

    1、复制/etc/skel目录为/home/tuser1,要求/home/tuser1及其内部文件的属组和其它用户均没有任何访问权限。 [root@localhost skel]# cp -r /etc/skel /home/tuser1[root@localhost skel]# chmod -R go=— /home/tuser1 2、编辑/etc/…

    系统运维 2017-02-08
  • httpd-2.2和httpd-2.4区别 、请求方法和响应状态码、虚拟主机、访问控制、持久链接

    第十周
    The Apache HTTP Server is a powerful, efficient, and extensible web server.
    2018/2/4 16:33

    2018-02-04
  • RAID详解

    测试机centos6.7 x86_64 一、RAID是什么     简单描述:RAID(Redundant Array of indenpensive Disk)独立磁盘冗余阵列:磁盘阵列是把多个磁盘组成一个阵列,当作单一磁盘使用,它将数据以分段或条带(striping)的方式储存在不同的磁盘中,存取数据时,阵列中的相关磁盘一起…

    2016-02-14
  • Linux程序包管理方式

    Linux程序包安装和管理方式共计三种:          一、[yum|dnf],通过官网或者其他开源网站提供的文件服务器,本机镜像源等途径进行安装。         二、rpm,通过官网或者其他开源网站通过…

    Linux干货 2016-07-29

评论列表(1条)

  • 马哥教育
    马哥教育 2017-03-15 01:19

    赞~~写的比较认真,继续加油~