第七周作業
1、創建一個10G分區,并格式為ext4文件系統:
1、要求其block大小為2048,預留空間百分比為2,卷標為MYDATA,默認掛載屬性包括acl;
~]# mke2fs -t ext4 -b 2048 -m 2 -L MYDATA /dev/sdb1
2、掛載至/data/mydata目錄,要求掛載時禁止程序自動運行,縣不更新文件的訪問時間戳;
~]# mkdir /data/mydata
~]# mount -o noexec,noatime,acl /dev/sdb1 /data/mydata
2、創建一個大小為1G的swap分區,并創建好文件系統,并啟用之;
[root@yangjifeng ~]# 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): p
Disk /dev/sda: 53.7 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 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: 0x000658d7
Device Boot????? Start???????? End????? Blocks?? Id? System
/dev/sda1?? *?????????? 1????????? 64????? 512000?? 83? Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2???????????? 64??????? 1370??? 10485760?? 83? Linux
/dev/sda3?????????? 1370??????? 1892???? 4194304?? 82? Linux swap / Solaris
/dev/sda4?????????? 1892??????? 6527??? 37235039+?? 5? Extended
/dev/sda5?????????? 1892 ???????3197??? 10486783?? 83? Linux
Command (m for help): n
First cylinder (3198-6527, default 3198):
Using default value 3198
Last cylinder, +cylinders or +size{K,M,G} (3198-6527, default 6527): +1G
Command (m for help): p
Disk /dev/sda: 53.7 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 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: 0x000658d7
Device Boot ???Start???????? End????? Blocks?? Id? System
/dev/sda1?? *?????????? 1????????? 64????? 512000?? 83? Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2???????????? 64??????? 1370??? 10485760?? 83? Linux
/dev/sda3?????????? 1370??????? 1892 ????4194304?? 82? Linux swap / Solaris
/dev/sda4?????????? 1892??????? 6527??? 37235039+?? 5? Extended
/dev/sda5?????????? 1892??????? 3197??? 10486783?? 83? Linux
/dev/sda6?????????? 3198??????? 3329???? 1060258+? 83? Linux
Command (m for help): t
Partition number (1-6): 6
Hex code (type L to list codes): 82
Changed system type of partition 6 to 82 (Linux swap / Solaris)
Command (m for help): p
Disk /dev/sda: 53.7 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 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: 0x000658d7
Device Boot????? Start???????? End????? Blocks?? Id? System
/dev/sda1?? *?????????? 1?? ?????64????? 512000?? 83? Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2???????????? 64??????? 1370??? 10485760?? 83? Linux
/dev/sda3?????????? 1370??????? 1892???? 4194304?? 82? Linux swap / Solaris
/dev/sda4?????????? 1892??????? 6527??? 37235039+?? 5? Extended
/dev/sda5?????????? 1892??????? 3197??? 10486783?? 83? Linux
/dev/sda6?????????? 3198??????? 3329???? 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: 設備或資源忙.
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.
~]# partx -a /dev/sda
3、寫一個腳本:
1、獲取并列出妝前系統上的所有磁盤設備;
2、顯示每個磁盤設備上的分區相關的空間使用信息;
[root@yangjifeng scripts]# vim aboutdisk.sh
#!/bin/bash
#
FILESYSTEM=`fdisk -l|grep -o ‘/dev/s[hd][a-z]\>’`
for i in $FILESYSTEM;do
echo -e? “\033[31m disk : $i \033[0m”
echo
df -h|egrep “文件系統|Filesystem|$i”
echo “——————————————”
done
[root@yangjifeng scripts]# chmod +x aboutdisk.sh
[root@yangjifeng scripts]# ./aboutdisk.sh
4、總結RAID的各個級別及其組合方式和性能的不同;
??? RAID:Redundant Arrays of Inexpensive Disks
RAID級別:RAID0,RAID1,RAID5,RAID10,RAID01,RAID6,RAID50,RAID60
RAID-0
- 條帶卷
- 至少需要兩塊磁盤并行處理,將數據分兩部分讀寫
- 讀寫性能提高,raid中性能最高
- 無容錯性
- 可用空間:N*min(s1,s2,…)
RAID-1
- 鏡像卷
- 至少需要兩塊磁盤,兩塊磁盤存儲相同數據,用于備份
- 讀寫性能相當于一塊獨立磁盤,無提升
- 容錯性高,raid中容錯性最高
- 可用空間1*min(s1,s2,…)
RAID-4
- 至少三塊磁盤
- 兩塊磁盤做數據存儲,第三塊用作獨立存儲數據校驗碼
- 讀寫性能提高
- 有容錯性為一塊磁盤
RAID-5
- 至少三塊磁盤
- 三塊磁盤存儲數據及校驗碼,校驗碼分別存儲在三個磁盤上
- 讀寫性能提高
- 有容錯性為一塊磁盤
- 可用空間:(N-1)*min(s1,s2,…)
RAID-6
- 至少四塊磁盤
- 增加第二個獨立的奇偶校驗信息塊,分別以不同算法計算
- 有容錯性為兩塊磁盤
- 可用空間:(N-2)*min(s1,s2,…)
RAID-10
- 至少四塊磁盤
- 兩兩磁盤分別做raid1,再將兩raid1陣列做raid0
- 讀寫性能提高
- 有容錯性為兩塊,不同raid1中最多損失一塊
- 可用空間:N*min(s1,s2,…)/2
RAID-50
- 至少六塊磁盤
- 三三磁盤分別做raid5,再將兩raid5陣列做raid0
- 讀寫能力提高
- 有容錯性為兩塊磁盤,不同raid5中做多損失一塊磁盤
RAID-60
- 至少八塊磁盤
- 四四磁盤分別做raid6,再將兩raid6陣列做raid0
- 讀寫能力提高
- 有容錯性為四塊磁盤,不同raid6中最多損壞兩塊磁盤
5、創建一個大小為10G的RAID1,要求有一個空閑盤,而且CHUNK大小為128K;
~]# mdadm -C /dev/md1 -n 2 -x 1 -c 128 -l 1 /dev/sdb2 /dev/sdb3 /dev/sdb4
? ? ?~]# mdadm -D /dev/md1
6、創建一個大小為4G的RAID5設備,CHUNK大小為256k,格式化ext4文件系統,要求可開機自動掛載到/backup目錄,而且不要新訪問時間戳,且支持ACL功能;
?~]# mdadm -C /dev/md5 -n 3 -c 256 -l 5 /dev/sdb1 /dev/sdb2 /dev/sdb3
? ? ?~]# mdadm -D /dev/md5
? ? ?~]# mkfs -t ext4 /dev/md5
? ? ?~]# mount -o auto,acl,noatime /dev/md5 /backup
7、寫一個腳本:
1、接受一個以上文件路徑作為參數;
2、顯示每個擁有的行數;
3、總結說明本次共為幾個文件統計了其行數;
scripts]# vim filelines.sh
#!/bin/bash
#
SUM=0
[ $# -lt 1 ] && echo “Son,you must input something” && exit 2
for file in $@;do
if [ -f $file ];then
LINES=`cat $file |wc -l`
echo “$file have $LINES lines”
let SUM=$SUM+$LINES
else
echo “$file is not exist”
fi
done
echo “$@ have $SUM lines in total.”
scripts]# chmod +x filelines.sh
scripts]# ./filelines.sh /etc/issue /etc/rc.d/init.d/functions
/etc/issue have 3 lines
/etc/rc.d/init.d/functions have 815 lines
/etc/issue /etc/rc.d/init.d/functions have 818 lines in total.
8、寫一個腳本:
1、傳遞兩個以上字符串當作用戶名;
2、創建這些用戶,且密碼同用戶名;
3、總結說明共創建幾個用戶;
#!/bin/bash
#
SUM=0
[ $# -lt 1 ] && echo “Son,you are wrong” && exit 2
for string in $*;do
[ $(echo “$string” |wc -c) -le 3 ] && echo “$string less than 3 letters” && continue
if id $string &> /dev/null;then
echo “user $string is exist!”
else
useradd $string
echo “$string” |passwd –stdin $string &> /dev/null
echo “add user $string sucess!”
let SUM+=1
fi
done
echo “add $SUM users in total.”
9、寫一個腳本,新建20個用戶,visitor1-visitor20;計算他們的ID之和;
scripts]# vim useradd1.sh
#!/bin/bash
#
SUM_UID=0
for((i=1;i<=20;i++));do
adduser visitor$i
UID1=`id -u visitor$i`
let SUM_UID+=$UID1
done
echo “ID intotle $SUM_UID”
[root@yangjifeng scripts]# chmod +x useradd1.sh
[root@yangjifeng scripts]# ./useradd1.sh
ID intotle 10290
本文來自投稿,不代表Linux運維部落立場,如若轉載,請注明出處:http://www.www58058.com/87345