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.www58058.com/36555
第一個問題可以嘗試一下用腳本搞定,應該不難