馬哥教育網絡20期+第7周課程練習

1、創建一個10G分區,并格式為ext4文件系統;

[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-7832, default 1): 
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-7832, default 7832): +10G
Command (m for help): p
Disk /dev/sdb: 64.4 GB, 64424509440 bytes
255 heads, 63 sectors/track, 7832 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: 0x9f86e179
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        1306    10490413+  83  Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.

   (1) 要求其block大小為2048, 預留空間百分比為2, 卷標為MYDATA, 默認掛載屬性包含acl;

[root@localhost ~]# mke2fs -t ext4 -b 2048 -m 2 -L 'MYDATA' /dev/sdb1
[root@localhost ~]# tune2fs -o acl /dev/sdb1

   (2) 掛載至/data/mydata目錄,要求掛載時禁止程序自動運行,且不更新文件的訪問時間戳;

[root@localhost ~]# mount -o noexec,noatime /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): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (1307-7832, default 1307): 
Using default value 1307
Last cylinder, +cylinders or +size{K,M,G} (1307-7832, default 7832): +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): p
Disk /dev/sdb: 64.4 GB, 64424509440 bytes
255 heads, 63 sectors/track, 7832 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: 0x9f86e179
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        1306    10490413+  83  Linux
/dev/sdb2            1307        1438     1060290   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.


[root@localhost ~]# mkswap /dev/sdb2
[root@localhost ~]# swapon /dev/sdb2

3、寫一個腳本

   (1)、獲取并列出當前系統上的所有磁盤設備;

   (2)、顯示每個磁盤設備上每個分區相關的空間使用信息;

#!/bin/bash
#
echo "當前系統的磁盤設備有:"
fdisk -l | grep "^Disk /dev/sd"
echo "每個磁盤的分區以及空間使用信息:"
fdisk -l | grep "^/dev/"
df -h /dev/sd*

4、總結RAID的各個級別及其組合方式和性能的不同;

     RAID 0又稱為Stripe或Strping,一般由2兩個或以上相同型號和容量的磁盤組成,代表了所有RAID級別中的最高存儲性能。

    提高存儲性能的原理是:RAID事先將磁盤切出等量的區塊(chunk),一旦有數據需要寫入RAID設備時就會按照區塊大小切割好,

    依次放在各磁盤中,這樣當系統有數據請求就可以被多個磁盤并行執行,這種數據上的并行操作可以充分利用總線的帶寬,顯著提高磁盤整體存取性能。

     RAID 1鏡像存儲(mirroring),是一種安全的 RAID 模式。數據被分切(方法和RAID 0)后同等地寫入兩個或多個磁盤中,導致寫入速度會比較 慢,但讀取時還是可以多個磁盤并行處理,所以速度會比較快。

    讀取速度可以接近所有磁盤吞吐量的總和,寫入速度受限于最慢 的磁盤。 RAID1也是磁盤利用率最低的一個。如果用兩個不同大小的磁盤建立RAID1,可以用空間為最小的那個磁盤,較大的磁盤多出來的部分可以作他用,不會浪費。如果其中一個物理磁盤出現故障,可以立即從第二個磁盤上獲取數據。即使一個磁盤出現故障,也不會丟失任何數據。

    RAID 3 使用字節級別的條帶化技術,并采用專用的奇偶校驗磁盤RAID 3 陣列能在一個磁盤出現故障的情況下確保數據不丟失。如果一個物理磁盤出現故障,該磁盤上的數據可以重建到更換磁盤上。如果數據尚未重建到更換磁盤上,而此時又有一個磁盤出現故障,那么陣列中的所有數據都將丟失。并且由于存放奇偶校驗碼的磁盤壓力很大,容易成為瓶頸

    RAID 5將奇偶校驗碼分散在各個磁盤上,避免了單塊校驗盤出現瓶頸。RAID5的讀出效率很高,寫入效率一般,塊式的集體訪問效率不錯。 因為奇偶校驗碼在不同的磁盤上,所以提高了可靠性。但是它對數據傳輸的并行性解決不好,而且控制器的設計也相當困難。 RAID 3 與RAID 5相比,重要的區別在于RAID 3每進行一次數據傳輸,需涉及到所有的陣列盤。而對于RAID 5來說,大部分數據傳輸只對一塊磁盤操作,可進行并行操作。在RAID 5中有“寫損失”,即每一次寫操作,將產生四個實際的讀/寫操作,其中兩次讀舊的數據及奇偶信息,兩次寫新的數據及奇偶信息。 最多允許損壞1塊磁盤。

    RAID 01和RAID 10這個RAID級別就是針對上面的特點與不足,把RAID 0和RAID 1這兩個結合起來了。 所謂的RAID 01就是:1.先讓組成 RAID 02.再組成 RAID 1,這就是 RAID 0+1 所謂的RAID 10就是:1.先組成 RAID 12.再組成 RAID 0,這就是RAID 1+0 特點與不足:由于具有 RAID 0 的優點,所以效能得以提升,由于具有 RAID 1 的優點,所以數據得以備份。 但是也由于 RAID 1 的缺點,所以總容量會少一半用來做為備份。

    

5、創建一個大小為10G的RAID1,要求有一個空閑盤,而且CHUNK大小為128k;

[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): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 3
First cylinder (1439-7832, default 1439): 
Using default value 1439
Last cylinder, +cylinders or +size{K,M,G} (1439-7832, default 7832): +10G

Command (m for help): t
Partition number (1-4): 3
Hex code (type L to list codes): fd
Changed system type of partition 3 to fd (Linux raid autodetect)

Command (m for help): p

Disk /dev/sdb: 64.4 GB, 64424509440 bytes
255 heads, 63 sectors/track, 7832 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: 0x9f86e179

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        1306    10490413+  83  Linux
/dev/sdb2            1307        1438     1060290   82  Linux swap / Solaris
/dev/sdb3            1439        2744    10490445   fd  Linux raid autodetect

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.
[root@localhost ~]# partx -a /dev/sdb
BLKPG: Device or resource busy
error adding partition 1
BLKPG: Device or resource busy
error adding partition 2

[root@localhost ~]# mdadm -C /dev/md0 -n2 -ayes -x1 -c128 -l1 /dev/sdb3 /dev/sda3

6、創建一個大小為4G的RAID5設備,chunk大小為256k,格式化ext4文件系統,要求可開機自動掛

[root@localhost ~]# mdadm -C /dev/md0 -n3 -ayes -x1 -c256 -l5 /dev/sdb3 /dev/sda3 /dev/sdc1
[root@localhost ~]# mke2fs -t ext4 /dev/md0
[root@localhost ~]# mount -o noatime,acl /dev/md0 /backup

7、寫一個腳本

   (1) 接受一個以上文件路徑作為參數;

   (2) 顯示每個文件擁有的行數;

   (3) 總結說明本次共為幾個文件統計了其行數;

#!/bin/bash
#
declare -i i=0
if (( $# < 1 )); then
echo "請輸入一個或以上字符串"
fi
for filename in $*; do
if [ -f $filename ]; then
echo "$filename line num: $( cat $filename | wc -l )"
let i=i+1
else
echo "file no exsit"
fi
done
echo "已統計文件數量:$i"

8、寫一個腳本

   (1) 傳遞兩個以上字符串當作用戶名;

   (2) 創建這些用戶;且密碼同用戶名;

   (3) 總結說明共創建了幾個用戶;

#!/bin/bash
#
declare -i i=0
if (( $# < 2 )); then
echo "請輸入兩個或以上字符串"
fi
for uname in $*; do
if id $uname &> /dev/null; then
echo "此用戶已存在,請重新輸入!"
else
useradd $uname
echo "$uname" | passwd --stdin $uname
let i=i+1
fi
done
echo "已創建用戶數量:$i"

9、寫一個腳本,新建20個用戶,visitor1-visitor20;計算他們的ID之和;

#!/bin/bash
#
declare -i i=1
declare -i uid=0
declare -i sum=0
declare -i a=0
while (( $i <= 20 )); do
#userdel -r visitor$i
useradd visitor$i
uid=$(tail -1 /etc/passwd | cut -d: -f3)
let sum=sum+$uid
let i++
done
echo "visitor1-visitor20的ID之和:$sum"

10、寫一腳本,分別統計/etc/rc.d/rc.sysinit、/etc/rc.d/init.d/functions和/etc/fstab文件中以#號開頭的行數之和,以及總的空白行數;

#!/bin/bash
#
declare -i i=0
for filename in {/etc/rc.d/rc.sysinit,/etc/rc.d/init.d/functions,/etc/fstab}; do
echo “$filename以#號開頭的行數:$(grep "^#" $filename | wc -l)”
echo "$filename的空白行數:$(grep "^$" $filename | wc -l)"
done

11、寫一個腳本,顯示當前系統上所有默認shell為bash的用戶的用戶名、UID以及此類所有用戶的UID之和;

#!/bin/bash
#
declare -i sum=0
declare -i num=0
awk -F: '/bash$/{print $1, $3}' /etc/passwd
for num in $(awk -F: '/bash$/{print $3}' /etc/passwd); do
let sum=sum+$num
done
echo $sum

12、寫一個腳本,顯示當前系統上所有,擁有附加組的用戶的用戶名;并說明共有多少個此類用戶;

[root@localhost ~]# cat test
#!/bin/bash
#
declare -i i=0
for uname in $(cut -d: -f1 /etc/passwd); do
group=$(id $uname | cut -d" " -f3 | awk -F, '{print $2}')
if [ -n "$group" ]; then
echo $uname
let i++
fi
done
echo $i

13、創建一個由至少兩個物理卷組成的大小為20G的卷組;要求,PE大小為8M;而在卷組中創建一個大小為5G的邏輯卷mylv1,格式化為ext4文件系統,開機自動掛載至/users目錄,支持acl;

[root@localhost ~]# pvcreate /dev/sd{b1,c1}
[root@localhost ~]# vgcreate -s 20G myvg /dev/sdb1 /dev/sdc1 -s 8M
  Volume group "myvg" successfully created
[root@localhost ~]# lvcreate -L 5G -n mylv1 myvg
  Logical volume "mylv1" created.
[root@localhost ~]# mkfs.ext4 /dev/myvg/mylv1
[root@localhost ~]# echo "UUID="79112d75-4482-4313-b9ac-3d2a930485c2"    /users    ext4    defaults,acl    0 0" >> /etc/fstab

14、新建用戶magedu;其家目錄為/users/magedu,而后su切換至此用戶,復制多個文件至家目錄;

[root@localhost ~]# useradd magedu -d /users/magedu
[root@localhost ~]# su magedu
[magedu@localhost root]$ cp /etc/fstab /etc/issue /etc/passwd ~
[magedu@localhost root]$ ll /users/magedu/
總用量 12
-rw-r--r-- 1 magedu magedu  862 7月  29 01:47 fstab
-rw-r--r-- 1 magedu magedu   47 7月  29 01:47 issue
-rw-r--r-- 1 magedu magedu 2570 7月  29 01:47 passwd

15、擴展mylv1至9G,確保擴展完成后原有數據完全可用;

[root@localhost ~]# lvextend -L 9G /dev/myvg/mylv1
  Size of logical volume myvg/mylv1 changed from 5.00 GiB (640 extents) to 9.00 GiB (1152 extents).
  Logical volume mylv1 successfully resized
[root@localhost ~]# df -h /dev/myvg/mylv1 
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/myvg-mylv1
                      4.8G   10M  4.6G   1% /users
[root@localhost ~]# resize2fs /dev/myvg/mylv1 
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/myvg/mylv1 is mounted on /users; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 1
Performing an on-line resize of /dev/myvg/mylv1 to 2359296 (4k) blocks.
The filesystem on /dev/myvg/mylv1 is now 2359296 blocks long.
[root@localhost ~]# df -h /dev/myvg/mylv1 
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/myvg-mylv1
                      8.8G   12M  8.3G   1% /users
[root@localhost ~]# ll /users/magedu/
總用量 12
-rw-r--r-- 1 magedu magedu  862 7月  29 02:04 fstab
-rw-r--r-- 1 magedu magedu   47 7月  29 02:04 issue
-rw-r--r-- 1 magedu magedu 2570 7月  29 02:04 passwd

16、縮減mylv1至7G,確??s減完成后原有數據完全可用;

[root@localhost ~]# umount /users
[root@localhost ~]# e2fsck -f /dev/myvg/mylv1 
e2fsck 1.41.12 (17-May-2010)
第一步: 檢查inode,塊,和大小
第二步: 檢查目錄結構
第3步: 檢查目錄連接性
Pass 4: Checking reference counts
第5步: 檢查簇概要信息
/dev/myvg/mylv1: 23/589824 files (0.0% non-contiguous), 72683/2359296 blocks
[root@localhost ~]# resize2fs /dev/myvg/mylv1 7G
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/myvg/mylv1 to 1835008 (4k) blocks.
The filesystem on /dev/myvg/mylv1 is now 1835008 blocks long.
[root@localhost ~]# lv
lvchange     lvdisplay    lvmchange    lvmdump      lvmsar       lvrename     lvscan       
lvconvert    lvextend     lvmconf      lvmetad      lvreduce     lvresize     
lvcreate     lvm          lvmdiskscan  lvmsadc      lvremove     lvs          
[root@localhost ~]# lvreduce -L 5G /dev/myvg/mylv1 
  WARNING: Reducing active logical volume to 5.00 GiB
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce mylv1? [y/n]: y
  Size of logical volume myvg/mylv1 changed from 9.00 GiB (1152 extents) to 5.00 GiB (640 extents).
  Logical volume mylv1 successfully resized

17、對mylv1創建快照,并通過備份數據;要求保留原有的屬主屬組等信息;

[root@6a magedu]# lvcreate -L 2G -s -p r -n sn_lv /dev/myvg/mylv1

原創文章,作者:mouse015110,如若轉載,請注明出處:http://www.www58058.com/25655

(0)
mouse015110mouse015110
上一篇 2016-08-02 10:55
下一篇 2016-08-02 10:55

相關推薦

  • 文本處理練習題

    文本處理練習:   1.找出本機ip地址   [root@localhost ~]# ifconfig |head -2 |tail -1 |tr -s ' ' ':' |cut -d: -f3   10.1.252.221   2.查看本機分區最大的利用率   [root@l…

    Linux干貨 2016-08-08
  • 內核配置和內核編譯

    內核配置 /proc目錄 內核把自己內部狀態信息及統計信息,以及可配置參數通 過proc偽文件系統加以輸出 sysctl命令 默認配置文件:/etc/sysctl.conf (1) 設置某參數 sysctl -w parameter=VALUE (2) 通過讀取配置文件讓設置的參數 生效;sysctl -p [/path/to/conf_file] (3) …

    Linux筆記 2018-05-11
  • Storm集群安裝詳解

    storm有兩種操作模式: 本地模式和遠程模式。 本地模式:你可以在你的本地機器上開發測試你的topology, 一切都在你的本地機器上模擬出來;  遠端模式:你提交的topology會在一個集群的機器上執行。 本文以Twitter Storm官方Wiki為基礎,詳細描述如何快速搭建一個Storm集群,其中,項目實踐中遇到的問題及經驗總結,在相應章…

    Linux干貨 2015-04-04
  • Linux中軟鏈接和硬鏈接的區別

    Linux中軟鏈接和硬鏈接的區別 鏈接文件:   Linux中包括兩種鏈接:硬鏈接(Hard Link)和軟鏈接(Soft Link),軟鏈接又稱為符號鏈接(Symbolic link)。 Inode 文件除了純數據本身之外,還必須包含有對這些純數據的管理信息 文件名; 訪問權限; 文件的屬主以; 該文件的數據所對應的磁盤數據塊; 文件的時間戳; …

    Linux干貨 2016-10-20
  • 0808文本處理作業

                           1 、刪除/etc/grub2.conf 文件中所有以空白開頭的行行首的空白字符。 答:sed  ‘@^[[:space]]\+@@’  /etc/grub2/cf…

    Linux干貨 2016-08-11

評論列表(1條)

  • 馬哥教育
    馬哥教育 2016-08-02 11:56

    寫的很好,排版也很棒,加油,所有的數值比較都不對,在回頭看看視頻吧

欧美性久久久久