1、創建一個10G分區,并格式為ext4文件系統;
(1) 要求其block大小為2048, 預留空間百分比為2, 卷標為MYDATA, 默認掛載屬性包含acl;
[root@localhost ~]# fdisk /dev/sda 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): 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^HG Unsupported suffix: 'G'. Supported: 10^N: KB (KiloByte), MB (MegaByte), GB (GigaByte) 2^N: K (KibiByte), M (MebiByte), G (GibiByte) Last cylinder, +cylinders or +size{K,M,G} (1-6527, default 6527): +10g Unsupported suffix: 'g'. Supported: 10^N: KB (KiloByte), MB (MegaByte), GB (GigaByte) 2^N: K (KibiByte), M (MebiByte), G (GibiByte) 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. 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 ~]# mke2fs -t ext4 -b 2048 -m 2 -L "MYDATA" /dev/sda1 [root@localhost ~]# tune2fs -o acl /dev/sda1
(2) 掛載至/data/mydata目錄,要求掛載時禁止程序自動運行,且不更新文件的訪問時間戳;
[root@localhost ~]# mount -o noexec,nodiratime /dev/sda1 /data/mydata/
2、創建一個大小為1G的swap分區,并創建好文件系統,并啟用之;
[root@localhost ~]# fdisk /dev/sda 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): 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): +10g^H Unsupported suffix: ''. Supported: 10^N: KB (KiloByte), MB (MegaByte), GB (GigaByte) 2^N: K (KibiByte), M (MebiByte), G (GibiByte) Last cylinder, +cylinders or +size{K,M,G} (1307-6527, default 6527): +10G 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 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 bin]# mkswap /dev/sda2 [root@localhost bin]# swapon /dev/sda2
3、寫一個腳本
(1)、獲取并列出當前系統上的所有磁盤設備;
(2)、顯示每個磁盤設備上每個分區相關的空間使用信息;
#!/bin/bash # echo "disk info:$(fdisk -l | grep -o "^Disk[[:space:]]/dev/sd[a-z]")" for i in $(fdisk -l | grep -o "^Disk[[:space:]]/dev/sd[a-z]"| cut -d" " -f2);do echo "$(fdisk -l $i)" done
4、總結RAID的各個級別及其組合方式和性能的不同;
RAID-0: 讀、寫性能提升; 可用空間:N*min(S1,S2,...) 無容錯能力 最少磁盤數:2, 2+ RAID-1: 讀性能提升、寫性能略有下降; 可用空間:1*min(S1,S2,...) 有冗余能力 最少磁盤數:2, 2+ RAID-4: 1101, 0110, 1011 最少磁盤數: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/md0 -a yes -n 3 -x 1 -l 1 -c 128 /dev/sda{1,2,3}
6、創建一個大小為4G的RAID5設備,chunk大小為256k,格式化ext4文件系統,要求可開機自動掛載至/backup目錄,而且不更新訪問時間戳,且支持acl功能;
[root@localhost ~]# mdadm -C /dev/md0 -n 3 -l 5 -a yes -c 256 -x 1 /dev/sda{1,2,3,4}
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 # declare -i idsum=0 for i in {1..20}; do useradd visitor$i &> /dev/null let idsum+=$(id -u visitor$i) done echo "The idsum is $idsum"
10、寫一腳本,分別統計/etc/rc.d/rc.sysinit、/etc/rc.d/init.d/functions和/etc/fstab文件中以#號開頭的行數之和,以及總的空白行數;
#!/bin/bash # declare -i sum1=0 declare -i sum2=0 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 "The #lines:$sum1" echo "The spacelins:$sum2"
11、寫一個腳本,顯示當前系統上所有默認shell為bash的用戶的用戶名、UID以及此類所有用戶的UID之和;
#!/bin/bash # declare -i UIDsum=0 for i in $(grep "bash$" /etc/passwd | cut -d":" -f3); do let UIDsum+=$i done echo "Username&UID:" echo "$(grep "bash$" /etc/passwd | cut -d":" -f1,3)" echo "UIDsum=$UIDsum"
12、寫一個腳本,顯示當前系統上所有,擁有附加組的用戶的用戶名;并說明共有多少個此類用戶;
#!/bin/bash # declare -i j=0 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,確??s減完成后原有數據完全可用;
[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
原創文章,作者:Bazinga,如若轉載,請注明出處:http://www.www58058.com/38445
如果raid的描述能夠做到圖文并茂就更好了