1、创建一个10G分区,并格式为ext4文件系统;
(1) 要求其block大小为2048, 预留空间百分比为2, 卷标为MYDATA, 默认挂载属性包含acl;
[root@CentOS7 ~]# fdisk /dev/sdb Command (m for help): n Select (default p): p Partition number (1-4, default 1): First sector (2048-41943039, default 2048): Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): +10G Partition 1 of type Linux and of size 10 GiB is set Command (m for help): w The partition table has been altered! [root@CentOS7 ~]# mke2fs -t ext4 -b 2048 -m 2 -L "MYDATA" /dev/sdb1 [root@CentOS7 ~]# echo 'LABEL=MYDATA /data/mydata ext4 defaults,acl 0 0' >> /etc/fstab
(2)挂载至/data/mydata目录,要求挂载时禁止程序自动运行,且不更新文件的访问时间戳;
[root@CentOS7 ~]# mount -o noexec,noatime /dev/sdb1 /data/mydata [root@CentOS7 ~]# mount | grep '/dev/sdb1' /dev/sdb1 on /data/mydata type ext4 (rw,noexec,noatime,seclabel,data=ordered)
2、创建一个大小为1G的swap分区,并创建好文件系统,并启用之;
[root@CentOS7 ~]# fdisk /dev/sdb 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-41943039, default 20973568): Using default value 20973568 Last sector, +sectors or +size{K,M,G} (20973568-41943039, default 41943039): +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 'Linux' to 'Linux swap / Solaris' Command (m for help): w The partition table has been altered! [root@CentOS7 ~]# mkswap /dev/sdb2 Setting up swapspace version 1, size = 1048572 KiB no label, UUID=e2c81d3c-1a93-4fe9-a633-b35c6268df37 [root@CentOS7 ~]# swapon /dev/sdb2
3、写一个脚本
(1)、获取并列出当前系统上的所有磁盘设备;
(2)、显示每个磁盘设备上每个分区相关的空间使用信息;
#!/bin/bash disk() { echo -e "Disks on the device:\n" fdisk -l | grep '^Disk /dev/sd.*' | cut -d: -f1 | cut -d' ' -f2 } usage() { echo -e "Usage about :\n" df -h | grep '/dev/sd' | awk -F' ' '{print $1,$2}' } disk echo usage
4、总结RAID的各个级别及其组合方式和性能的不同;
图为原创,非抄袭
5、创建一个大小为10G的RAID1,要求有一个空闲盘,而且CHUNK大小为128k;
[root@CentOS6 ~]# mdadm -C /dev/md0 -n 2 -l 1 -c 128 /dev/sd{b,c} [root@CentOS6 ~]# mdadm -D /dev/md0 /dev/md0: Version : 1.2 Creation Time : Fri Aug 19 15:40:11 2016 Raid Level : raid1 Array Size : 5238720 (5.00 GiB 5.36 GB) Used Dev Size : 5238720 (5.00 GiB 5.36 GB) Raid Devices : 2 Total Devices : 2 Persistence : Superblock is persistent Update Time : Fri Aug 19 15:40:27 2016 State : clean, resyncing Active Devices : 2 Working Devices : 2 Failed Devices : 0 Spare Devices : 0 Resync Status : 64% complete Name : CentOS6:0 (local to host CentOS6) UUID : f92a25b5:a1120042:521176b5:1964c806 Events : 10 Number Major Minor RaidDevice State 0 8 16 0 active sync /dev/sdb 1 8 32 1 active sync /dev/sdc
6、创建一个大小为4G的RAID5设备,chunk大小为256k,格式化ext4文件系统,要求可开机自动挂载至/backup目录,而且不更新访问时间戳,且支持acl功能;
[root@CentOS6 ~]# mdadm -C /dev/md1 -n 2 -l 5 -c 256 /dev/sdb{1,2} [root@CentOS6 ~]# mkfs -t ext4 /dev/md1 [root@CentOS6 ~]# echo "/dev/md1 /backup ext4 defaults,acl,nodiratime 0 0" >> /etc/fstab
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 for i in {1..20}; do useradd visitor$i && echo "add visitor$i finished!" let j+=`id -u visitor$i` done echo "Sum of users' id: $j"
10、写一脚本,分别统计/etc/rc.d/rc.sysinit、/etc/rc.d/init.d/functions和/etc/fstab文件中以#号开头的行数之和,以及总的空白行数;
#!/bin/bash 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 "#lines: $sum1" echo "space lines: $sum2"
11、写一个脚本,显示当前系统上所有默认shell为bash的用户的用户名、UID以及此类所有用户的UID之和;
#!/bin/bash for i in `grep '/bash$' /etc/passwd | cut -d: -f1`; do echo "USER: $i , UID: `id -u $i`" let j+=`id -u $i` done echo "Sum of UID: $j"
12、写一个脚本,显示当前系统上所有,拥有附加组的用户的用户名;并说明共有多少个此类用户;
#!/bin/bash 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
原创文章,作者:Jeason,如若转载,请注明出处:http://www.178linux.com/37841
评论列表(1条)
写的很好,排版还可以在漂亮一点,加油,原创图没显示出来