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,確??s減完成后原有數據完全可用; [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.www58058.com/49519
第八題其實是缺少判斷用戶是否存在的,如果存在你添加是會報錯的,所以要先判斷在往后處理哦。
@luoweiro:好的,我去修改一下。謝謝老師指導!