第七周

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

(1) 要求其block大小为2048, 预留空间百分比为2, 卷标为MYDATA, 默认挂载属性包含acl;
(2) 挂载至/data/mydata目录,要求挂载时禁止程序自动运行,且不更新文件的访问时间戳;
fdisk /dev/sdb欢迎使用 fdisk (util-linux 2.23.2)。更改将停留在内存中,直到您决定将更改写入磁盘。使用写入命令前请三思。命令(输入 m 获取帮助):nPartition type:   p   primary (1 primary, 0 extended, 3 free)   e   extendedSelect (default p): p分区号 (2-4,默认 2):起始 扇区 (20973568-41943039,默认为 20973568):将使用默认值 20973568Last 扇区, +扇区 or +size{K,M,G} (20973568-41943039,默认为 41943039):+10G分区 2 已设置为 Linux 类型,大小设为 10 GiB命令(输入 m 获取帮助):wThe partition table has been altered!# mke2fs -t ext4 -b 2048 -L MYDATA -m 2 /dev/sdb2# mkdir -pv /data/mydata# mount -t ext4 -o defaults,noexec,nodiratime,acl /dev/sdb2 /data/mydata/

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

# fdisk /dev/sdb命令(输入 m 获取帮助):nPartition type:   p   primary (1 primary, 0 extended, 3 free)   e   extendedSelect (default p): p分区号 (2-4,默认 2):起始 扇区 (20973568-41943039,默认为 20973568):将使用默认值 20973568Last 扇区, +扇区 or +size{K,M,G} (20973568-41943039,默认为 41943039):+1G分区 2 已设置为 Linux 类型,大小设为 1 GiB命令(输入 m 获取帮助):t分区号 (1,2,默认 2):Hex 代码(输入 L 列出所有代码):82已将分区“Linux”的类型更改为“Linux swap / Solaris”命令(输入 m 获取帮助):wThe partition table has been altered!# partx -a /dev/sdb# cat /proc/partitions major minor  #blocks  name   8        0   41943040 sda   8        1       2048 sda1   8        2    1048576 sda2   8        3   31461376 sda3   8       16   20971520 sdb   8       17   10485760 sdb1   8       18    1048576 sdb2  11        0    1048575 sr0 253        0   10485760 dm-0 253        1    1048576 dm-1 253        2    5242880 dm-2# mkswap /dev/sdb2正在设置交换空间版本 1,大小 = 1048572 KiB无标签,UUID=13400b7b-46b9-4acf-8314-b52055a3a71f[root@localhost ~]# swapon -a /deb/sdb2# swapon -s文件名             类型      大小  已用  权限/dev/dm-1                               partition   1048572 0   -1/dev/sdb2                               partition   1048572 0   -2

3、写一个脚本

(1)、获取并列出当前系统上的所有磁盘设备;
(2)、显示每个磁盘设备上每个分区相关的空间使用信息;
#!/bin/bashecho -e "All of disk:\n `fdisk -l | grep '磁盘' | awk -F , '{print $1}'`"echo -e "The Disk partation information:\n `df -h`"

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

RAID-0:     读、写性能最好;    可用空间:N*min(S1,S2,...)    无容错能力    最少磁盘数:2, 2+RAID-1:    读性能提升、写性能略有下降;    可用空间:1*min(S1,S2,...)    有冗余能力    最少磁盘数:2, 2+,必须为偶数块磁盘RAID-5:    读性能一样,写惩罚为4    可用空间:(N-1)*min(S1,S2,...)    有容错能力:1块磁盘    最少磁盘数:3, 3+,奇数块磁盘RAID-10:    读性能一样,写惩罚为2    可用空间:N*min(S1,S2,...)/2    有容错能力:每组镜像最多只能坏一块;    最少磁盘数:4, 4+,必须为偶数块磁盘

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

# fdisk /dev/sdaWARNING: DOS-compatible mode is deprecated. It's strongly recommended to         switch off the mode (command 'c') and change display units to         sectors (command 'u').Command (m for help): nFirst cylinder (4307-15665, default 4307): Using default value 4307Last cylinder, +cylinders or +size{K,M,G} (4307-15665, default 15665): +10GCommand (m for help): nFirst cylinder (5613-15665, default 5613): Using default value 5613Last cylinder, +cylinders or +size{K,M,G} (5613-15665, default 15665): +10GCommand (m for help): nFirst cylinder (6919-15665, default 6919): Using default value 6919Last cylinder, +cylinders or +size{K,M,G} (6919-15665, default 15665): +10GCommand (m for help): tPartition number (1-8): 7Hex code (type L to list codes): fdChanged system type of partition 7 to fd (Linux raid autodetect)Command (m for help): tPartition number (1-8): 8Hex code (type L to list codes): fdChanged system type of partition 8 to fd (Linux raid autodetect)Command (m for help): tPartition number (1-9): 9Hex code (type L to list codes): fdChanged system type of partition 9 to fd (Linux raid autodetect)Command (m for help): wThe partition table has been altered!]# partx -a /dev/sda]# mdadm -C /dev/md0 -a yes -n 2 -l 1 -x 1 -c 128 /dev/sda{7,8,9}

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

]# fdisk /dev/sdaWARNING: DOS-compatible mode is deprecated. It's strongly recommended to         switch off the mode (command 'c') and change display units to         sectors (command 'u').Command (m for help): nFirst cylinder (8225-15665, default 8225): Using default value 8225Last cylinder, +cylinders or +size{K,M,G} (8225-15665, default 15665): +2GCommand (m for help): nFirst cylinder (8487-15665, default 8487): Using default value 8487Last cylinder, +cylinders or +size{K,M,G} (8487-15665, default 15665): +2GCommand (m for help): nFirst cylinder (8749-15665, default 8749): Using default value 8749Last cylinder, +cylinders or +size{K,M,G} (8749-15665, default 15665): +2GCommand (m for help): tPartition number (1-12): 10Hex code (type L to list codes): fd   Changed system type of partition 10 to fd (Linux raid autodetect)Command (m for help): tPartition number (1-12): 11Hex code (type L to list codes): fdChanged system type of partition 11 to fd (Linux raid autodetect)Command (m for help): tPartition number (1-12): 12Hex code (type L to list codes): fdChanged system type of partition 12 to fd (Linux raid autodetect)Command (m for help): wThe partition table has been altered!]# partx -a /dev/sda]# mdadm -C /dev/md1 -a yes -n 3 -c 256K -l 5 /dev/sda{10,11,12}]# mkfs.ext4 /dev/md1

7、写一个脚本

(1) 接受一个以上文件路径作为参数;
(2) 显示每个文件拥有的行数;
(3) 总结说明本次共为几个文件统计了其行数;
#!/bin/bashif [ $# -le 1 ];then    echo "more than 2 arg!"    exitelse    for i in $*;do        echo "$i total lines: `wc -l $i | cut -d" " -f1`"    donefiecho "Total args: $#"

8、写一个脚本

(1) 传递两个以上字符串当作用户名;
(2) 创建这些用户;且密码同用户名;
(3) 总结说明共创建了几个用户;
#!/bin/bashif [ $# -le 2 ];then    echo "more than 3 arg!"    exitelse    for i in $*;do        id $i &> /dev/null        if [ $? -eq 0 ];then            echo "$i exists"        else            useradd $i && echo "$i" | passwd --stdin $i            let x++        fi    donefiecho "Total create users: $x"

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

#!/bin/bashfor i in {1..20};do    useradd visitor$i    let x+= `id -u visitor$i`doneecho "sum of visitor user id: $x"

10、写一脚本,分别统计/etc/rc.d/rc.sysinit、/etc/rc.d/init.d/functions和/etc/fstab文件中以#号开头的行数之和,以及总的空白行数;

#!/bin/bashfor i in {/etc/rc.d/rc.sysinit,/etc/rc.d/init.d/functions,/etc/fstab};do    let sum1+= $(`grep "^#" $i | wc -l`)    let sum1+= $(`grep "^$" $i | wc -l`)doneecho "total #begin lines:$sum1"echo "total spacelines:$sum2"

11、写一个脚本,显示当前系统上所有默认shell为bash的用户的用户名、UID以及此类所有用户的UID之和;

#!/bin/bashfor i in `grep "/bin/bash$" /etc/passwd | cut -d: -f1`;do    echo "user:$i,uid:`id -u $i`"    let x+=`id -u $i`doneecho "sum of UID:$x`"

12、写一个脚本,显示当前系统上所有,拥有附加组的用户的用户名;并说明共有多少个此类用户;

#!/bin/bashfor i in `cut -d: -f1 /etc/passwd`;do    id $i | grep "," &> /dev/null    if [ $? -eq 0 ];then        echo "user: $i" && let x++    fidoneecho "sum: $x"

13、创建一个由至少两个物理卷组成的大小为20G的卷组;要求,PE大小为8M;而在卷组中创建一个大小为5G的逻辑卷mylv1,格式化为ext4文件系统,开机自动挂载至/users目录,支持acl;

[root@localhost ~]# pvcreate /dev/sda{3,5}[root@localhost ~]# vgcreate -s 8M myvg /dev/sda{3,5}[root@localhost ~]# lvcreate -L 5G -n mylv1 myvg[root@localhost ~]# mkfs.ext4 /dev/myvg/mylv1[root@localhost ~]# mkdir /users[root@localhost ~]# echo "/dev/myvg/mylv1  /users   ext4    defaults,acl     0 0" >> /etc/fstab

14、新建用户magedu;其家目录为/users/magedu,而后su切换至此用户,复制多个文件至家目录;

[root@localhost ~]# useradd -d /users/magedu magedu[root@localhost ~]# su - magedu[magedu@localhost ~]$ cp /etc/rc.sysinit .[magedu@localhost ~]$ cp /tmp/* .

15、扩展mylv1至9G,确保扩展完成后原有数据完全可用;

[root@localhost ~]# lvresize +9G /dev/myvg/mylv1[root@localhost ~]# resize2fs /dev/myvg/mylv1

16、缩减mylv1至7G,确保缩减完成后原有数据完全可用;

[root@localhost ~]# umount /dev/myvg/mylv1[root@localhost ~]# e2fsck -f /dev/myvg/mylv1[root@localhost ~]# resize2fs /dev/myvg/mylv1 7G[root@localhost ~]# lvreduce -L 7G /dev/myvg/mylv1[root@localhost ~]# mount -a

17、对mylv1创建快照,并通过备份数据;要求保留原有的属主属组等信息;

[root@localhost ~]# lvcreate -L 2G -s -p r -n mysnap1 /dev/myvg/mylv1

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

(0)
N21_smileN21_smile
上一篇 2016-09-19 13:48
下一篇 2016-09-19 13:48

相关推荐

  • N22-第六周博客作业

    请详细总结vim编辑器的使用并完成以下练习题 1、复制/etc/rc.d/rc.sysinit文件至/tmp目录,将/tmp/rc.sysinit文件中的以至少一个空白字符开头的行的行首加#; # cp /etc/rc.d/rc.sysinit /tmp # vim /tmp/rc.sysinit …

    Linux干货 2016-09-26
  • NFS,samba,vsftpd的基本使用

    一.NFS介绍 NFS(Network File System),全名叫做网络文件系统,是由SUN公司研发的。顾名思义,简单理解就是通过网络互联,将本地的文件系统共享出去,从而实现资源的共享,NFS监听在TCP的2049端口上。当涉及到主机之间的通信时,就会存在安全问题,于是为了安全考虑,主动提出请求的一方(客户端)需要提供一些基本信息来认证,这些信息是需要…

    Linux干货 2017-01-04
  • 基于haproxy实现wordpress动静分离

    环境:centos 6.8 注:此处省略对于各服务器的IP配置。 一:图示讲解      用户访问vip,通过haproxy代理得到服务器的资源。此架构下基于keepalived对haproxy做负载均衡(此种两种软件装在同一台服务器),基于haproxy对Nginx和apache做负载均衡,Nginx和Apache使用共享存储…

    2017-05-18
  • 文件管理命令及通配符练习

    1.Linux上的文件管理类命令都有哪些,其常用的使用方法及其相关示例 按增删改查的思路来 增: touch filename:这个命令本身不是用来新建文件的,它是用来修改文件的时间属性,不过默认情况时当filename不存在时,它会默认建立一个空文件 mkdir: 常用参数 -p:相当于递归创建目录 -v:显示出创建过程中的信息 cp : 常用参数 -r:…

    Linux干货 2016-11-06
  • RHCE基础实验

    实验:配额实现 1. 启用配额功能 vim /etc/fstab defaults usrquota,grpquota mount -o remount /home 2. 创建配额数据库 quotacheck -cug /home 3. 启用数据库 quotaon /home quotaon -p /home 查看 4. edquota wang setqu…

    Linux干货 2017-05-02
  • 磁盘、文件系统管理

    linux磁盘、文件系统管理 硬盘:机械硬盘、固态硬盘     计算硬盘速度:IoPs:(Io  per  second ) 每秒20次 机械硬盘:     track:磁道     平均寻道时间  &nbsp…

    Linux干货 2016-08-25

评论列表(1条)

  • 马哥教育
    马哥教育 2016-09-19 18:02

    条理清晰一些,