1、创建一个10G分区,并格式为ext4文件系统;
(1) 要求其block大小为2048, 预留空间百分比为2, 卷标为MYDATA, 默认挂载属性包含acl;
[root@localhost ~]# fdisk /dev/sdf
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
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost ~]# kpartx -af /dev/sdf
[root@localhost ~]# dmsetup status
[root@localhost ~]# dmsetup remove_all
[root@localhost ~]# mke2fs -t ext4 -b 2048 -L 'MYDATA' -m 2 /dev/sdf1
(2) 挂载至/data/mydata目录,要求挂载时禁止程序自动运行,且不更新文件的访问时间戳;
[root@localhost ~]# mkdir -pv /data/mydata
[root@localhost ~]# mount -o noexec,noatime /dev/sdf1 /data/mydata/
2、创建一个大小为1G的swap分区,并创建好文件系统,并启用之;
[root@localhost ~]# fdisk /dev/sdf
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): +1G
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
[root@localhost ~]# mkswap /dev/sdf2
Setting up swapspace version 1, size = 1060284 KiB
no label, UUID=b7d1a974-a04c-434c-8304-c5d6bdeb2779
[root@localhost ~]# swapon /dev/sdf2
3、写一个脚本
(1)、获取并列出当前系统上的所有磁盘设备;
(2)、显示每个磁盘设备上每个分区相关的空间使用信息;
[root@localhost tmp]# vim disk_no.sh
#!/bin/bash
disk=$(fdisk -l |grep "Disk /dev/[sh]d"|cut -d: -f1)
diskspace=$(fdisk -l | grep "/dev/[sh]d[a-z][1-9]"| awk '{print $1}'| df -h)
echo -e "$disk\n"
echo -e "$diskspace\n"
[root@localhost tmp]# bash disk_no.sh
4、总结RAID的各个级别及其组合方式和性能的不同;
RAID-0:
读、写性能提升
可用空间:N*min(S1,S2,...)
无容错能力
最少磁盘数:2,2+
RAID-1:
读性能提升、写性能略有下降
可用空间:1*min(S1,S2,...)
有冗余能力
最少磁盘数: 2,2+
RAID-4:
读、写性能提升
可用空间:(N-1)*min(S1,S2,...)
有容错能力:最多坏1块磁盘
最少磁盘数: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/md1 -n2 -l1 -c 128 -x1 /dev/sd{c,d,e}
[root@localhost ~]# mdadm -D /dev/md1
/dev/md1:
Version : 1.2
Creation Time : Sun Sep 25 16:45:06 2016
Raid Level : raid1
Array Size : 10477568 (9.99 GiB 10.73 GB)
Used Dev Size : 10477568 (9.99 GiB 10.73 GB)
Raid Devices : 2
Total Devices : 3
Persistence : Superblock is persistent
Update Time : Sun Sep 25 16:45:59 2016
State : clean
Active Devices : 2
Working Devices : 3
Failed Devices : 0
Spare Devices : 1
Name : localhost.localdomain:1 (local to host localhost.localdomain)
UUID : 128eeac8:2e46723d:c0c503d8:3ca4c831
Events : 17
Number Major Minor RaidDevice State
0 8 32 0 active sync /dev/sdc
1 8 48 1 active sync /dev/sdd
2 8 64 - spare /dev/sde
6、创建一个大小为4G的RAID5设备,chunk大小为256k,格式化ext4文件系统,要求可开机自动挂载至/backup目录,而且不更新访问时间戳,且支持acl功能;
添加3块4G的硬盘
[root@localhost ~]# mdadm -C /dev/md2 -n3 -l5 -c 256 /dev/sd{c,d,e}
[root@localhost ~]# mke2fs -t ext4 /dev/md2
[root@localhost ~]# vim /etc/fstab
/dev/md2 /backup ext4 noatime,acl 0 0
[root@localhost ~]# mount -a
[root@localhost ~]# mount
/dev/md2 on /backup type ext4 (rw,noatime,acl)
7、写一个脚本
(1) 接受一个以上文件路径作为参数;
(2) 显示每个文件拥有的行数;
(3) 总结说明本次共为几个文件统计了其行数;
[root@test tmp]# vim args.sh
#!/bin/bash
if [ $# -eq 0 ];then
echo "please input file path"
exit 1
fi
for i in $*;do
echo "$i lines :$(grep ".*" $i |wc -l)"
done
echo "file total:$#"
[root@test tmp]# bash args.sh /etc/passwd /etc/inittab
8、写一个脚本
(1) 传递两个以上字符串当作用户名;
(2) 创建这些用户;且密码同用户名;
(3) 总结说明共创建了几个用户;
[root@test tmp]# vim CretUser2.sh
#!/bin/bash
if [ $# -lt 2 ];then
echo "please input at least two users"
exit 1
fi
for i in $*; do
useradd $i
password=$i
echo $password |passwd --stdin $i
done
echo "Created users total:$#"
[root@test tmp]# bash CretUser2.sh test102 test103
9、写一个脚本,新建20个用户,visitor1-visitor20;计算他们的ID之和;
[root@test tmp]# vim CretUser20.sh
#!/bin/bash
declare -i sumuid=0
for ((i=1;i<=20;i++));do
username=visitor$i
useradd $username
uid=`id -u $username`
let sumuid+=$uid
done
echo "the users id sum:$sumuid"
[root@test tmp]# bash CretUser20.sh
10、写一脚本,分别统计/etc/rc.d/rc.sysinit、/etc/rc.d/init.d/functions和/etc/fstab文件中以#号开头的行数之和,以及总的空白行数;
[root@test ~]# vim filelines.sh
#!/bin/bash
for i in /etc/rc.d/rc.sysinit /etc/rc.d/init.d/functions /etc/fstab;do
line=$(grep "^#" $i |wc -l|cut -d' ' -f1)
echo "$i The first char is # lines:$line"
let lines1+=$line
let lines2+=$(grep "^[[:space:]]*$" $i |wc -l|cut -d' ' -f1)
done
echo "The first char is # lines total:$lines1"
echo "The space lines total:$lines2"
[root@test ~]# bash filelines.sh
11、写一个脚本,显示当前系统上所有默认shell为bash的用户的用户名、UID以及此类所有用户的UID之和;
[root@test ~]# vim sumuid.sh
#!/bin/bash
grep "/bin/bash$" /etc/passwd|awk -F: '{print $1,$3}'
uid=$(grep "/bin/bash$" /etc/passwd|cut -d: -f 3)
for i in $uid;do
let sumuid+=$i
done
echo "All users id sum:"$sumuid
[root@test ~]# bash sumuid.sh
12、写一个脚本,显示当前系统上所有,拥有附加组的用户的用户名;并说明共有多少个此类用户;
[root@test ~]# vim UserGrp.sh
#!/bin/bash
Sum_user=0
echo "attach group users list:"
while read line; do
User_name=$(echo ${line} | cut -d: -f1)
Num=$(id -G ${User_name} | wc -w)
if [[ ${Num} -ge 2 ]]; then
echo "${User_name}"
let Sum_user+=1
fi
done < /etc/passwd
echo "The number of user: ${Sum_user}"
[root@test ~]# bash UserGrp.sh
13、创建一个由至少两个物理卷组成的大小为20G的卷组;要求,PE大小为8M;而在卷组中创建一个大小为5G的逻辑卷mylv1,格式化为ext4文件系统,开机自动挂载至/users目录,支持acl;
[root@test ~]# fdisk /dev/sdb
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-1958, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-1958, default 1958): +10G
Command (m for help): t
Selected partition 1
Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM)
Command (m for help): w
The partition table has been altered!
[root@test ~]# fdisk /dev/sdc
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-1958, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-1958, default 1958): +10G
Command (m for help): t
Selected partition 1
Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM)
Command (m for help): w
The partition table has been altered!
[root@test ~]# kpartx -af /dev/sdb
[root@test ~]# kpartx -af /dev/sdc
[root@test ~]# dmsetup remove sdb1
[root@test ~]# dmsetup remove sdc1
[root@test ~]# pvcreate /dev/sdb1
[root@test ~]# pvcreate /dev/sdc1
[root@test ~]# vgcreate -s 8m myvg /dev/sd{b,c}1
[root@test ~]# lvcreate -L 5g -n mylv1 myvg
[root@test ~]# mke2fs -t ext4 /dev/myvg/mylv1
[root@test ~]# vim /etc/fstab
/dev/myvg/mylv1 /users ext4 defaults,acl 0 0
[root@test ~]# mount -a
14、新建用户magedu;其家目录为/users/magedu,而后su切换至此用户,复制多个文件至家目录;
[root@test users]# useradd magedu -d /users/magedu
[root@test users]# su - magedu
[magedu@test ~]$ cp /etc/passwd ./
[magedu@test ~]$ cp /etc/inittab ./
[magedu@test ~]$ cp /etc/fstab ./
15、扩展mylv1至9G,确保扩展完成后原有数据完全可用;
[root@test users]# lvextend -L +4G -n /dev/myvg/mylv1
[root@test users]# resize2fs /dev/myvg/mylv1
16、缩减mylv1至7G,确保缩减完成后原有数据完全可用;
[root@test users]# resize2fs /dev/myvg/mylv1 7G
[root@test users]# e2fsck -f /dev/myvg/mylv1
[root@test users]# lvreduce -L 7G /dev/myvg/mylv1
17、对mylv1创建快照,并通过备份数据;要求保留原有的属主属组等信息;
[root@test users]# lvcreate -L 7G -p r -s -n mylv1_snapshot /dev/myvg/mylv1
原创文章,作者:N22_上海_长清,如若转载,请注明出处:http://www.178linux.com/49519


评论列表(2条)
第八题其实是缺少判断用户是否存在的,如果存在你添加是会报错的,所以要先判断在往后处理哦。
@luoweiro:好的,我去修改一下。谢谢老师指导!