马哥教育网络班21期+第7周课程练习

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

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

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

WARNING: 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): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-6527, default 1): 
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-6527, default 6527): +10g^HG
Unsupported suffix: 'G'.
Supported: 10^N: KB (KiloByte), MB (MegaByte), GB (GigaByte)
            2^N: K  (KibiByte), M  (MebiByte), G  (GibiByte)
Last cylinder, +cylinders or +size{K,M,G} (1-6527, default 6527): +10g
Unsupported suffix: 'g'.
Supported: 10^N: KB (KiloByte), MB (MegaByte), GB (GigaByte)
            2^N: K  (KibiByte), M  (MebiByte), G  (GibiByte)
Last cylinder, +cylinders or +size{K,M,G} (1-6527, default 6527): +10G

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@localhost ~]# mke2fs -t ext4 -b 2048 -m 2 -L "MYDATA" /dev/sda1
[root@localhost ~]# tune2fs -o acl /dev/sda1

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

[root@localhost ~]# mount -o noexec,nodiratime /dev/sda1 /data/mydata/

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

[root@localhost ~]# fdisk /dev/sda
WARNING: 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): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (1307-6527, default 1307): 
Using default value 1307
Last cylinder, +cylinders or +size{K,M,G} (1307-6527, default 6527): +10g^H
Unsupported suffix: ''.
Supported: 10^N: KB (KiloByte), MB (MegaByte), GB (GigaByte)
            2^N: K  (KibiByte), M  (MebiByte), G  (GibiByte)
Last cylinder, +cylinders or +size{K,M,G} (1307-6527, default 6527): +10G
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): 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@localhost bin]# mkswap /dev/sda2
[root@localhost bin]# swapon /dev/sda2

3、写一个脚本

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

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

#!/bin/bash
#
echo "disk info:$(fdisk -l | grep -o "^Disk[[:space:]]/dev/sd[a-z]")"
for i in $(fdisk -l | grep -o "^Disk[[:space:]]/dev/sd[a-z]"| cut -d" " -f2);do
    echo "$(fdisk -l $i)"
done

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

RAID-0: 
读、写性能提升;
可用空间:N*min(S1,S2,...)
无容错能力
最少磁盘数:2, 2+
RAID-1:
读性能提升、写性能略有下降;
可用空间:1*min(S1,S2,...)
有冗余能力
最少磁盘数:2, 2+
RAID-4:
1101, 0110, 1011
最少磁盘数:3,3+
RAID-5:
读、写性能提升
可用空间:(N-1)*min(S1,S2,...)
有容错能力:1块磁盘
最少磁盘数:3, 3+
RAID-6:
读、写性能提升
可用空间:(N-2)*min(S1,S2,...)
有容错能力:2块磁盘
最少磁盘数:4, 4+
混合类型
RAID-10:
读、写性能提升
可用空间:N*min(S1,S2,...)/2
有容错能力:每组镜像最多只能坏一块;
最少磁盘数:4, 4+

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

[root@localhost ~]# mdadm -C /dev/md0 -a yes -n 3 -x 1 -l 1 -c 128 /dev/sda{1,2,3}

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

[root@localhost ~]# mdadm -C /dev/md0 -n 3 -l 5 -a yes -c 256 -x 1 /dev/sda{1,2,3,4}

7、写一个脚本

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

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

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

#!/bin/bash
#
if [ $# -le 1 ]; then
    echo "At least 2 parameter.Try again!"
    exit 3
else
    for i in $*; do
        echo "$i total lines: `wc -l $i | cut -d' ' -f1`"
    done
fi
echo "Total parameters: $#"

8、写一个脚本

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

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

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

#!/bin/bash
#
if [ $# -le 2 ]; then
    echo "Enter at least 3 para. Try again!"
    exit 3
fi
for i in $*; do
    id $i &> /dev/null
    if [ $? -eq 0 ]; then
        echo "$i exists."
    else
        useradd $i && echo "$i" | passwd --stdin "$i"
        echo "add $i finished"
        let j++
    fi
done
echo "add $j users"

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

#!/bin/bash
#
declare -i idsum=0
for i in {1..20}; do
   useradd visitor$i &> /dev/null
   let idsum+=$(id -u visitor$i)
done
echo "The idsum is $idsum"

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

#!/bin/bash
#
declare -i sum1=0
declare -i sum2=0
for i in {/etc/rc.d/rc.sysinit,/etc/rc.d/init.d/functions,/etc/fstab};do
     let sum1+=$(grep "^#" $i | wc -l )
     let sum2+=$(grep "^$" $i | wc -l )
done
echo "The #lines:$sum1"
echo "The spacelins:$sum2"

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

#!/bin/bash
#
declare -i UIDsum=0
for i in $(grep "bash$" /etc/passwd | cut -d":" -f3); do
         let UIDsum+=$i
done
echo "Username&UID:"
echo "$(grep "bash$" /etc/passwd | cut -d":" -f1,3)"
echo "UIDsum=$UIDsum"

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

#!/bin/bash
#
declare -i j=0
for i in $(cut -d: -f1 /etc/passwd); do
    id $i | grep ',' &> /dev/null
    if [ $? -eq 0 ]; then
        echo "USER: $i" 
        let j++
    fi
done
echo "Sum: $j."

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

[root@CentOS6 ~]# pvcreate /dev/sdb /dev/sdc
[root@CentOS6 ~]# vgcreate -s 8M myvg /dev/sd{b,c}
[root@CentOS6 ~]# lvcreate -L 5G -n mylv1 /dev/myvg
[root@CentOS6 ~]# mkfs.ext4 /dev/myvg/mylv1
[root@CentOS6 ~]# echo "/dev/myvg/mylv1    /users   ext4  defaults,acl,nodiratime  0 0"  >> /etc/fstab

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

[root@CentOS6 test]# useradd -d /users/magedu magedu
[root@CentOS6 test]# su - magedu
[magedu@CentOS6 ~]$ pwd
/users/magedu
[magedu@CentOS6 ~]$ cp /etc/fstab /etc/issue ./

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

[root@CentOS6 users]# cp /etc/fstab ./
[root@CentOS6 users]# lvextend -L +4G -n /dev/myvg/mylv1
[root@CentOS6 users]# resize2fs /dev/myvg/mylv1 
[root@CentOS6 users]# ls
fstab  lost+found

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

[root@CentOS6 ~]# umount /users
[root@CentOS6 ~]# e2fsck -f /dev/myvg/mylv1
[root@CentOS6 ~]# resize2fs /dev/myvg/mylv1 7G
[root@CentOS6 ~]# lvreduce -L 7G -n /dev/myvg/mylv1

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

[root@CentOS6 ~]# lvcreate -L 3G -p r -s -n mylv1_snapshot /dev/myvg/mylv1

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

(0)
BazingaBazinga
上一篇 2016-08-24 10:26
下一篇 2016-08-24 10:27

相关推荐

  • 马哥教育网络20期+第8周练习博客

    1、请描述网桥、集线器、二层交换机、三层交换机、路由器的功能、使用场景与区别。 网桥:链接层设备,基于MAC地址过滤。 集线器:物理层设备,基本都属于半双工模式。集线器与网桥在现在的局域网中基本都不用了。 二层交换机:基本MAC转发数据,功能齐全的可支持VLAN等功能。常见的有100/1000M、16口/24口/48口。 三层交换机:功能齐全的交换机,具备都…

    Linux干货 2016-08-01
  • TCP连接的状态转移

    TCP是一个面向连接的传输层协议,因此不论哪一方需要传输数据,都需要在双方之间建立一条传输连接。 用TCP的三次握手与四次挥手来解释TCP的各个状态之间的会比较清晰。 一、TCP的三次握手: a)         单方主动发起连接: 1、  服务器端应用层的应用程序创建…

    2017-03-19
  • IO,用户与组管理,文件,目录权限管理

           文件统配匹配模式:元字符文件名通配符*匹配任意长度的任意字符[root@localhost ~]# ls /root/D*/root/Desktop  /root/Documents  /root/Downloads ?匹配单个任意字符[root@localhost ~]# …

    Linux干货 2016-08-05
  • 使用NFS服务和samba部署wordpress

             centos 7.3主机一台   centos 6.8主机一台  使用yum安装的mysql(7以后使用yum装mysql叫mariadb)         我事先查看了一…

    2017-05-02
  • 如何实现在命令行输入pwd时显示出ifconfig的效果

    1、使用type ifconfig 查看   2、使用type pwd 查看 如果还没有使用过pwd则显示如下,表示pwd属于内部命令,然后输入enable -n pwd 禁用这个内部命令   如果已经使用过,就会显示hash,已经缓存过   此时就不仅需要禁用内部命令,还需要使用hash -d pwd 清除pwd的缓存,使其在…

    2017-07-13
  • 马哥教育网络19期+第十七周课程练习

    1、结合图形描述LVS的工作原理;     LVS (Linux Virtual Server)是一种集群(Cluster)技术,采用IP负载均衡技术和基于内容请求分发技术。调度器具有很好的吞吐率,将请求均衡地转移到不同的服务器上执行,且调度器自动屏蔽掉服务器的故障,从而将一组服务器构成一个高性能的、高可用的虚拟服务器。整个服务器集群的结…

    Linux干货 2016-09-05

评论列表(1条)

  • 马哥教育
    马哥教育 2016-08-30 13:19

    如果raid的描述能够做到图文并茂就更好了