1、創建一個10G分區,并格式為ext4文件系統;
(1) 要求其block大小為2048, 預留空間百分比為2, 卷標為MYDATA, 默認掛載屬性包含acl;
[root@centos ~]# mke2fs -t ext4 -b 2048 -m 2 -L "MYDATA" /dev/sdb1 mke2fs 1.41.12 (17-May-2010) Filesystem label=MYDATA OS type: Linux Block size=2048 (log=1) Fragment size=2048 (log=1) Stride=0 blocks, Stripe width=0 blocks 328440 inodes, 2626610 blocks 52532 blocks (2.00%) reserved for the super user First data block=0 [root@centos ~]# mount -o acl /dev/sdb1 /test/ [root@centos ~]# mount /dev/mapper/vg_centos-lv_root on / type ext4 (rw) /dev/sdb1 on /test type ext4 (rw,acl)
(2) 掛載至/data/mydata目錄,要求掛載時禁止程序自動運行,且不更新文件的訪問時間戳;
[root@centos ~]# mount -o noexec,noatime /dev/sdb1 /data/mydata/ [root@centos ~]# mount /dev/mapper/vg_centos-lv_root on / type ext4 (rw) /dev/sdb1 on /data/mydata type ext4 (rw,noexec,noatime)
2、創建一個大小為1G的swap分區,并創建好文件系統,并啟用之;
[root@centos ~]# mkswap /dev/sdb1 && swapon /dev/sdb1 Setting up swapspace version 1, size = 1060252 KiB no label, UUID=fb9d419c-2190-4e1b-964c-0e2614bc74f0 [root@centos ~]# free total used free shared buffers cached Mem: 1012292 913096 99196 3664 34452 544528 -/+ buffers/cache: 334116 678176 Swap: 2633112 8 2633104 [root@centos ~]# swapoff /dev/sdb1 [root@centos ~]# free total used free shared buffers cached Mem: 1012292 913352 98940 3664 34192 545180 -/+ buffers/cache: 333980 678312 Swap: 1572860 8 1572852
3、寫一個腳本
(1)、獲取并列出當前系統上的所有磁盤設備;
(2)、顯示每個磁盤設備上每個分區相關的空間使用信息;
[root@centos ~]# /test/exercise1.sh total diskes: Disk /dev/sda Disk /dev/sdb diskes used: Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg_centos-lv_root 13G 3.7G 8.4G 31% / tmpfs 495M 76K 495M 1% /dev/shm /dev/sda1 477M 29M 424M 7% /boot /dev/sr0 4.4G 4.4G 0 100% /media/CentOS_6.6_Final [root@centos ~]# vim /test/exercise1.sh [root@centos ~]# /test/exercise1.sh total diskes: Disk /dev/sda Disk /dev/sdb diskes used: Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg_centos-lv_root 13G 3.7G 8.4G 31% / tmpfs 495M 76K 495M 1% /dev/shm /dev/sda1 477M 29M 424M 7% /boot /dev/sr0 4.4G 4.4G 0 100% /media/CentOS_6.6_Final [root@centos ~]# cat /test/exercise1.sh #!/bin/bash disk=$(fdisk -l | grep "Disk /dev/[sh]d" | cut -d: -f1) echo -e "total diskes:\n $disk" diskused=$(fdisk -l | grep "/dev/[sh]d[a-z][1-9]"| awk '{print $1}'| df -h) echo -e "diskes used: \n $diskused"
4、總結RAID的各個級別及其組合方式和性能的不同;
首先 :RAID通過在多個磁盤上同時存儲和讀取數據來大幅提高存儲系統的數據吞吐量;
通過數據校檢提供容錯功能。
RAID0 : n>=2,磁盤容量不相等時,以最小容量為基準,取每個磁盤的容量組成raid0,并行讀寫,性能最好,但無容錯能力,利用率100%
RAID1 : n>=2,磁盤容量不相等時,以最小容量為基準,每個磁盤存儲原始數據的鏡像,成本高,有冗余,利 用率50%
RAID2 :n>=3 采用海明碼做數據校檢,條塊單位是位或者字節,校驗碼存儲到陣列中的一個磁盤上,其他磁盤并行讀寫,有冗余,校驗盤有可能成為瓶頸。
RAID3 :n>=3 采用奇偶校驗碼碼做數據校檢,條塊單位是位或者字節,校驗碼存儲到陣列中的一個磁盤上,其他磁盤并行讀寫,有冗余,校驗盤有可能成為瓶頸。
RAID4 : n>=3 采用奇偶校驗碼碼做數據校檢,條塊單位是數據塊,校驗碼存儲到陣列中的一個磁盤上,其他 磁盤并行讀寫,有冗余,校驗盤有可能成為瓶頸。
RAID4 : n>=3 采用奇偶校驗碼碼做數據校檢,條塊單位是數據塊,校驗碼存儲到陣列中的一個磁盤上,其他 磁盤并行讀寫,有冗余,校驗盤有可能成為瓶頸。
RAID5 :n>=3,把數據和相對應的奇偶校驗信息存儲到組成RAID5的各個磁盤上,并且奇偶校驗信息和相對應的數據分別存儲于不同的磁盤上,其中任意N-1塊磁盤上都存儲完整的數據,沒有獨立的奇偶校驗盤,所有校驗信息分散放在所有磁盤上, 只占用一個磁盤的容量,并行讀寫,可以壞一塊,利用率(n-1)/n。
RAID10 :先做raid1鏡像陣列,然后條帶陣列。
RAID01 :先做條帶陣列,再做鏡像陣列,條帶磁盤壞一塊,數據不容易恢復,冗余性不好,不建議使用。
5、創建一個大小為10G的RAID1,要求有一個空閑盤,而且CHUNK大小為128k;
[root@centos ~]# mdadm -C /dev/md0 -n3 -l 1 -c 128 -x1 /dev/sdb{1,2,3} [root@centos ~]# mdadm -D /dev/md0 /dev/md0: Version : 1.2 [root@centos ~]# cat /proc/mdstat Personalities : [raid1] md0 : active raid1 sdb3[2](S) sdb2[1] sdb1[0] 2102400 blocks super 1.2 [2/2] [UU] unused devices: <none>
6、創建一個大小為4G的RAID5設備,chunk大小為256k,格式化ext4文件系統,要求可開機自動掛載至/backup目錄,而且不更新訪問時間戳,且支持acl功能;
[root@centos ~]# mdadm -C /dev/md0 -n2 -l 5 -c 256 -x1 /dev/sdb{1,2,3} [root@centos ~]# cat /proc/mdstat Personalities : [raid1] [raid6] [raid5] [raid4] md0 : active raid5 sdb2[3] sdb3[2](S) sdb1[0] 2102272 blocks super 1.2 level 5, 256k chunk, algorithm 2 [2/2] [UU] unused devices: <none> [root@centos ~]# mkfs -t ext4 /dev/md0 [root@centos ~]# cat /etc/fstab /dev/md0 /backup ext4 noatime,acl 0 0 [root@centos ~]# mount -a [root@centos ~]# mount /dev/md0 on /backup type ext4 (rw,noatime,acl)
7、寫一個腳本
(1) 接受一個以上文件路徑作為參數;
(2) 顯示每個文件擁有的行數;
(3) 總結說明本次共為幾個文件統計了其行數;
[root@centos test]# ./exercise3.sh /etc/passwd 34 /etc/passwd filesnumber:1 [root@centos test]# ./exercise3.sh /etc/passwd /etc/issue 34 /etc/passwd 3 /etc/issue filesnumber:2 [root@centos test]# ./exercise3.sh /etc/passwd /etc/issue /etc/ 34 /etc/passwd 3 /etc/issue filesnumber:2 [root@centos test]# ./exercise3.sh must input files! [root@centos test]# ./exercise3.sh /etc/passwd /etc/issue /etc/ /etc/rc.d/rc.sysinit 34 /etc/passwd 3 /etc/issue 687 /etc/rc.d/rc.sysinit filesnumber:3 [root@centos test]# cat exercise3.sh #!/bin/bash declare -i count if [ $# -gt 0 ];then for i in $* ; do if [ ! -f $i ];then continue fi wc -l $i if [ $? -eq 0 ];then let count++ fi done echo -e "filesnumber:$count" fi if [ $# -eq 0 ]; then echo "must input files!" fi
8、寫一個腳本
(1) 傳遞兩個以上字符串當作用戶名;
(2) 創建這些用戶;且密碼同用戶名;
(3) 總結說明共創建了幾個用戶;
[root@centos test]# ./exercise4.sh test1 test2 at least 3 users! [root@centos test]# ./exercise4.sh test1 test2 test3 Changing password for user test1. passwd: all authentication tokens updated successfully. user:test1 added Changing password for user test2. passwd: all authentication tokens updated successfully. user:test2 added Changing password for user test3. passwd: all authentication tokens updated successfully. user:test3 added [root@centos test]# vim /test/exercise4.sh [root@centos test]# ./exercise4.sh test1 test2 test3 Changing password for user test1. passwd: all authentication tokens updated successfully. user:test1 added Changing password for user test2. passwd: all authentication tokens updated successfully. user:test2 added Changing password for user test3. passwd: all authentication tokens updated successfully. user:test3 added total 3 [root@centos test]# cat exercise4.sh #!/bin/bash declare -i count if [ $# -lt 3 ];then echo "at least 3 users!" exit 12 fi for i in $*;do id $i &>/dev/null if [ $? -eq 0 ];then echo "$i exsits!" else useradd $i && echo "$i" | passwd --stdin "$i" let count++ echo "user:$i added" fi done echo "total $count"
9、寫一個腳本,新建20個用戶,visitor1-visitor20;計算他們的ID之和;
[root@centos test]# cat exercise1.sh #/bin/bash for m in {1..20};do useradd visitor$m && echo "user:visitor$m added!" || echo "user exsits!" done declare -i sum=0 for i in $(cat /etc/passwd | cut -d: -f3 | tail -20);do let sum+=$i done echo "users id sums: $sum"
10、寫一腳本,分別統計/etc/rc.d/rc.sysinit、/etc/rc.d/init.d/functions和/etc/fstab文件中以#號開頭的行數之和,以及總的空白行數;
[root@centos test]# cat exercise2.sh #/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+=$(cat $i | grep "^[#]" | wc -l) let sum2+=$(cat $i | grep "^$" | wc -l) done echo "#begins lines:$sum1" echo "spaces lines:$sum2" [root@centos test]# bash -x exercise2.sh #begins lines:91 + echo 'spaces lines:173' spaces lines:173
11、寫一個腳本,顯示當前系統上所有默認shell為bash的用戶的用戶名、UID以及此類所有用戶的UID之和;
[root@centos test]# cat exercise3.sh #/bin/bash declare -i sum1=0 for i in $(cat /etc/passwd | cut -d: -f3);do let sum+=$i done printf "%s,%s,%s,%d,$(cat /etc/passwd | cut -d: -f1,3,7), uidsums:$sum \n" [root@centos test]# ./exercise3.sh ntp:38:/sbin/nologin apache:48:/sbin/nologin pulse:497:/sbin/nologin sshd:74:/sbin/nologin tcpdump:72:/sbin/nologin derulo:500:/bin/bash, uidsums:68821
12、寫一個腳本,顯示當前系統上所有,擁有附加組的用戶的用戶名;并說明共有多少個此類用戶;
[root@centos test]# cat exercise5.sh #/bin/bash declare -i sum=0 for i in $(cat /etc/passwd | cut -d: -f1 );do id $i | grep "," | cut -d " " -f1 | egrep -o "\(.*\)" | tr "()" " " id $i | grep "," &>/dev/null if [ $? -eq 0 ];then let sum++ fi done echo "uidsums:$sum" [root@centos test]# ./exercise5.sh bin daemon adm postfix test test1 uidsums:6
13、創建一個由至少兩個物理卷組成的大小為20G的卷組;要求,PE大小為8M;而在卷組中創建一個大小為5G的邏輯卷mylv1,格式化為ext4文件系統,開機自動掛載至/users目錄,支持acl;
[root@centos ~]# pvcreate /dev/sd[b,c] [root@centos ~]# vgcreate -s 8M myvg /dev/sd[b,c] [root@centos ~]# lvcreate -L 5G -n /dev/myvg/mylv1 /dev/myvg [root@centos ~]# mkfs -t ext4 /dev/myvg/mylv1 [root@centos ~]# cat /etc/fstab /dev/myvg/mylv1 /users ext4 acl 0 0 [root@centos ~]# mount -a [root@centos ~]# mount /dev/mapper/myvg-mylv1 on /users type ext4 (rw,acl)
14、新建用戶magedu;其家目錄為/users/magedu,而后su切換至此用戶,復制多個文件至家目錄;
[root@centos ~]# su - magedu [magedu@centos ~]$ cp /etc/issue /etc/fstab ./
15、擴展mylv1至9G,確保擴展完成后原有數據完全可用;
[root@centos users]# df -h /dev/mapper/myvg-mylv1 4.8G 10M 4.6G 1% /users [root@centos users]# lvextend -L 9G -n /dev/myvg/mylv1 [root@centos users]# resize2fs /dev/myvg/mylv1 [root@centos users]# ls index.html lost+found
16、縮減mylv1至7G,確??s減完成后原有數據完全可用;
[root@centos ~]# umount /users/ [root@centos ~]# e2fsck -f /dev/myvg/mylv1 [root@centos ~]# resize2fs /dev/myvg/mylv1 7G [root@centos ~]# lvreduce -L 7G -n /dev/myvg/mylv1
17、對mylv1創建快照,并通過備份數據;要求保留原有的屬主屬組等信息;
[root@centos users]# cp -a /etc/issue ./ [root@centos users]# ls issue lost+found [root@centos ~]# lvcreate -L 6G -s -n mylv1s myvg/mylv1 [root@centos ~]# mkdir /snapshot [root@centos ~]# mount /dev/myvg/mylv1s /snapshot/ [root@centos ~]# cp -a /etc/fstab /users/ [root@centos test]# cd /users/ [root@centos users]# ls fstab issue lost+found [root@centos users]# cd /snapshot/ [root@centos snapshot]# ls issue lost+found
原創文章,作者:Snoo,如若轉載,請注明出處:http://www.www58058.com/25736
寫的很好,排版也很棒,加油