1、创建一个10G分区,并格式为ext4文件系统;
(1) 要求其block大小为2048, 预留空间百分比为2, 卷标为MYDATA, 默认挂载属性包含acl;
(2) 挂载至/data/mydata目录,要求挂载时禁止程序自动运行,且不更新文件的访问时间戳;
[root@localhost ~]# mkfs.ext4 -b 2048 -L MYDATA -m 2 /dev/sdb1 [root@localhost ~]# mount -o noexec,noatime,acl /dev/sdb1 /data/mydata/
2、创建一个大小为1G的swap分区,并创建好文件系统,并启用之;
[root@localhost ~]# fdisk /dev/sdb 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): d Selected partition 1 Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 1 First cylinder (1-1305, default 1): Using default value 1 Last cylinder, +cylinders or +size{K,M,G} (1-1305, default 1305): +1G Command (m for help): t Selected partition 1 Hex code (type L to list codes): 82 Changed system type of partition 1 to 82 (Linux swap / Solaris) Command (m for help): p Disk /dev/sdb: 10.7 GB, 10737418240 bytes 255 heads, 63 sectors/track, 1305 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0xeafee498 Device Boot Start End Blocks Id System /dev/sdb1 1 132 1060258+ 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 ~]# mkswap /dev/sdb1 [root@localhost ~]# swapon /dev/sdb1
3、写一个脚本
(1)、获取并列出当前系统上的所有磁盘设备;
(2)、显示每个磁盘设备上每个分区相关的空间使用信息;
#!/bin/bash # fdisk -l | grep "^Disk /dev" | awk '{print $2}'| cut -d: -f1 #获取磁盘设备 for list in `fdisk -l | grep "^/" | awk '{print $1}'`;do #显示空间使用 df -h $list done
4、总结RAID的各个级别及其组合方式和性能的不同;
级别 | 组合方式 | 性能 |
raid0 | 条带式,至少2块盘 | 提升读写性能,无冗余 |
raid1 | 镜像式,至少2块盘 | 略提升读性能,写性能下降,有冗余 |
raid5 | 轮流校验,至少3块盘 | 读写性能提升,可容错1块盘 |
raid10 | 先镜像,后分条带,至少4块盘 | 读写性能提升,有冗余,每组镜像可容错一块盘 |
5、创建一个大小为10G的RAID1,要求有一个空闲盘,而且CHUNK大小为128k;
[root@localhost ~]# mdadm -C /dev/md-test -n 2 -l 1 -c 128 /dev/sd{b,c}
6、创建一个大小为4G的RAID5设备,chunk大小为256k,格式化ext4文件系统,要求可开机自动挂载至/backup目录,而且不更新访问时间戳,且支持acl功能;
[root@localhost ~]# mdadm -C /dev/md1 -c 256 -l 5 -n 3 /dev/sd{b,c,d} [root@localhost ~]# mount -a -o noatime,acl /dev/md1 /backup
7、写一个脚本
(1) 接受一个以上文件路径作为参数;
(2) 显示每个文件拥有的行数;
(3) 总结说明本次共为几个文件统计了其行数;
#!/bin/bash # if [ $# -gt 0 ];then for file_path in $*;do if [ -f $file_path ];then awk 'END{print NR}' $file_path else echo "$file_path is not a file!" fi done else echo "you must input one file_path at least!" fi echo "count $# files"
8、写一个脚本
(1) 传递两个以上字符串当作用户名;
(2) 创建这些用户;且密码同用户名;
(3) 总结说明共创建了几个用户;
#!/bin/bash # declare -i sum=0 newuser () { for user in $*;do if id $user &> /dev/null;then echo $user is exist else useradd $user echo "$user" | passwd --stdin $user let sum++ fi done } if [ $# -lt 2 ];then echo "usage: newuser arg1 arg2 ...(at least 2 args)" exit fi newuser $* echo "you add $sum users in this operation"
9、写一个脚本,新建20个用户,visitor1-visitor20;计算他们的ID之和;
#!/bin/bash # declare -i num=1 declare -i sum=0 while [ $num -le 20 ];do useradd visitor$num let num++ done for list in $(seq 1 20);do id_number=$(id visitor$list | awk -F [=\(] '{print $2}') let sum+=$id_number done echo "sum of total ID is $sum"
10、写一脚本,分别统计/etc/rc.d/rc.sysinit、/etc/rc.d/init.d/functions和/etc/fstab文件中以#号开头的行数之和,以及总的空白行数;
#!/bin/bash # a="/etc/rc.d/rc.sysinit" b="/etc/rc.d/init.d/functions" c="/etc/fstab" declare -i sum=0 for list in $a $b $c;do echo "$list have $(grep -c "^#" $list) lines" space_line=$(grep -c "^$" $list) let sum+=$space_line done echo "sum of total space lines is $sum"
11、写一个脚本,显示当前系统上所有默认shell为bash的用户的用户名、UID以及此类所有用户的UID之和;
#!/bin/bash # declare -i sum=0 awk -F: ' BEGIN{printf "%-15s %s\n","Username","ID"}$7 ~ /\/bin\/bash/{printf "%-15s %d\n",$1,$3 }' /etc/passwd for num in $(awk -F: '{print $3}' /etc/passwd);do let sum+=$num done echo "sum of total user_id is $sum"
12、写一个脚本,显示当前系统上所有,拥有附加组的用户的用户名;并说明共有多少个此类用户;
#!/bin/bash # declare -i sum=0 for user in $(awk -F: '{print $1}' /etc/passwd);do result=$(id $user | awk -F, '{print $2}') if [ ! -z "$result" ];then echo $user let sum++ fi done echo "total is $sum"
13、创建一个由至少两个物理卷组成的大小为20G的卷组;要求,PE大小为8M;而在卷组中创建一个大小为5G的逻辑卷mylv1,格式化为ext4文件系统,开机自动挂载至/users目录,支持acl;
[root@www1 ~]# pvcreate /dev/sd{b1,c1} [root@www1 ~]# vgcreate -s 8M test-vg /dev/sd{b1,c1} [root@www1 ~]# lvcreate -L 5G -n mylv1 test-vg [root@www1 ~]# mkfs.ext4 /dev/test-vg/mylv1 [root@www1 ~]# echo "/dev/test-vg/mylv1 /users ext4 defaults,acl 0 0" >> /etc/fstab
14、新建用户magedu;其家目录为/users/magedu,而后su切换至此用户,复制多个文件至家目录;
[root@www1 ~]# useradd -d /users/magedu magedu [root@www1 ~]# su - magedu [magedu@www1 ~]$ cp /tmp/* .
15、扩展mylv1至9G,确保扩展完成后原有数据完全可用;
[root@www1 ~]# lvextend -L +4G -r /dev/test-vg/mylv1
16、缩减mylv1至7G,确保缩减完成后原有数据完全可用;
[root@www1 ~]# lvreduce -L -2G -r /dev/test-vg/mylv1
17、对mylv1创建快照,并通过备份数据;要求保留原有的属主属组等信息;
[root@www1 ~]# lvcreate -s -L 100M -n mylv1.snapshot /dev/test-vg/mylv1
原创文章,作者:Net21_木头,如若转载,请注明出处:http://www.178linux.com/36555
评论列表(1条)
第一个问题可以尝试一下用脚本搞定,应该不难