1、創建一個10G分區,并格式為ext4文件系統;
(1) 要求其block大小為2048, 預留空間百分比為2, 卷標為MYDATA, 默認掛載屬性包含acl;
(2) 掛載至/data/mydata目錄,要求掛載時禁止程序自動運行,且不更新文件的訪問時間戳;
[root@localhost ~]# fdisk /dev/sda 歡迎使用 fdisk (util-linux 2.23.2)。 更改將停留在內存中,直到您決定將更改寫入磁盤。 使用寫入命令前請三思。 命令(輸入 m 獲取幫助):n Partition type: p primary (2 primary, 0 extended, 2 free) e extended Select (default p): p 分區號 (3,4,默認 3): 起始 扇區 (90193920-251658239,默認為 90193920): 將使用默認值 90193920 Last 扇區, +扇區 or +size{K,M,G} (90193920-251658239,默認為 251658239):+10G 分區 3 已設置為 Linux 類型,大小設為 10 GiB 命令(輸入 m 獲取幫助):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) 正在同步磁盤。 [root@localhost ~]# partx -a /dev/sda partx: /dev/sda: error adding partitions 1-3 [root@localhost ~]# partx -a /dev/sda partx: /dev/sda: error adding partitions 1-3 [root@localhost ~]# mke2fs -t ext4 -b 2048 -m 2 /dev/sda3 mke2fs 1.42.9 (28-Dec-2013) 文件系統標簽= OS type: Linux 塊大小=2048 (log=1) 分塊大小=2048 (log=1) Stride=0 blocks, Stripe width=0 blocks 655360 inodes, 5242880 blocks 104857 blocks (2.00%) reserved for the super user 第一個數據塊=0 Maximum filesystem blocks=273678336 320 block groups 16384 blocks per group, 16384 fragments per group 2048 inodes per group Superblock backups stored on blocks: 16384, 49152, 81920, 114688, 147456, 409600, 442368, 802816, 1327104, 2048000, 3981312 Allocating group tables: 完成 正在寫入inode表: 完成 Creating journal (32768 blocks): 完成 Writing superblocks and filesystem accounting information: 完成 [root@localhost ~]# tune2fs -o acl -L MYDATA /dev/sda3 tune2fs 1.42.9 (28-Dec-2013) [root@localhost ~]# mkdir -p /data/mydata [root@localhost ~]# mount -o noexec,noatime /dev/sda3 /data/mydata [root@localhost ~]# tune2fs -l /dev/sda3 tune2fs 1.42.9 (28-Dec-2013) Filesystem volume name: MYDATA Last mounted on: <not available> Filesystem UUID: c92424b0-608c-4b36-b0b1-34e195a3e50f Filesystem magic number: 0xEF53 Filesystem revision #: 1 (dynamic) Filesystem features: has_journal ext_attr resize_inode dir_index filetype needs_recovery extent 64bit flex_bg sparse_super huge_file uninit_bg dir_nlink extra_isize Filesystem flags: signed_directory_hash Default mount options: user_xattr acl Filesystem state: clean Errors behavior: Continue Filesystem OS type: Linux Inode count: 655360 Block count: 5242880 Reserved block count: 104857 Free blocks: 5121266 Free inodes: 655349 First block: 0 Block size: 2048 Fragment size: 2048 Group descriptor size: 64 Reserved GDT blocks: 512 Blocks per group: 16384 Fragments per group: 16384 Inodes per group: 2048 Inode blocks per group: 256 Flex block group size: 16 Filesystem created: Mon Jul 3 13:17:08 2017 Last mount time: Mon Jul 3 13:28:50 2017 Last write time: Mon Jul 3 13:28:50 2017 Mount count: 2 Maximum mount count: -1 Last checked: Mon Jul 3 13:17:08 2017 Check interval: 0 (<none>) Lifetime writes: 225 MB Reserved blocks uid: 0 (user root) Reserved blocks gid: 0 (group root) First inode: 11 Inode size: 256 Required extra isize: 28 Desired extra isize: 28 Journal inode: 8 Default directory hash: half_md4 Directory Hash Seed: ba9fed8b-cb70-46fa-b0bb-b86ef90d2948 Journal backup: inode blocks [root@localhost ~]# mount | grep "/dev/sda3" /dev/sda3 on /data/mydata type ext4 (rw,noexec,noatime,seclabel,data=ordered)
2、創建一個大小為1G的swap分區,并創建好文件系統,并啟用之;
[root@localhost ~]# fdisk /dev/sda 歡迎使用 fdisk (util-linux 2.23.2)。 更改將停留在內存中,直到您決定將更改寫入磁盤。 使用寫入命令前請三思。 命令(輸入 m 獲取幫助):n Partition type: p primary (3 primary, 0 extended, 1 free) e extended Select (default e): e 已選擇分區 4 起始 扇區 (111165440-251658239,默認為 111165440): 將使用默認值 111165440 Last 扇區, +扇區 or +size{K,M,G} (111165440-251658239,默認為 251658239): 將使用默認值 251658239 分區 4 已設置為 Extended 類型,大小設為 67 GiB 命令(輸入 m 獲取幫助):n All primary partitions are in use 添加邏輯分區 5 起始 扇區 (111167488-251658239,默認為 111167488): 將使用默認值 111167488 Last 扇區, +扇區 or +size{K,M,G} (111167488-251658239,默認為 251658239):+1G 分區 5 已設置為 Linux 類型,大小設為 1 GiB 命令(輸入 m 獲取幫助):t 分區號 (1-5,默認 5):5 Hex 代碼(輸入 L 列出所有代碼):82 已將分區“Linux”的類型更改為“Linux swap / Solaris” 命令(輸入 m 獲取幫助):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) 正在同步磁盤。 [root@localhost ~]# partx -a /dev/sda partx: /dev/sda: error adding partitions 1-5 [root@localhost ~]# partx -a /dev/sda partx: /dev/sda: error adding partitions 1-5 [root@localhost ~]# mkswap /dev/sda5 mkswap: /dev/sda5: warning: wiping old linux_raid_member signature. 正在設置交換空間版本 1,大小 = 10485756 KiB 無標簽,UUID=80095efc-eed6-4f8b-9ba6-44a8e0afccc2 [root@localhost ~]# swapon /dev/sda5 [root@localhost ~]# swapon -s 文件名 類型 大小 已用 權限 /dev/dm-1 partition 2097148 0 -1 /dev/sda5 partition 10485756 0 -2
3、寫一個腳本
(1)、獲取并列出當前系統上的所有磁盤設備;
(2)、顯示每個磁盤設備上每個分區相關的空間使用信息;
#!/bin/bash SD=$(fdisk -l | grep -o "\</dev/sd[a-z]\>") for FILESYSTEM in $SD ; do df -lh $FILESYSTEM; done
4、總結RAID的各個級別及其組合方式和性能的不同;
磁盤陣列全名是Redundant Arrays of Independent Disk,RAID,英翻中的意思為:獨立冗余磁盤陣列,舊稱廉價冗余磁盤陣列,RAID可以通過一個技術,將多個較小的磁盤整合成一個較大的磁盤裝置;而這個較大的磁盤功能不知是存儲,還具有資料保護的功能。整個RAID由于選擇等級不同使得整合后的磁盤具有不同的功能,常見的level有這幾種:
RAID-0:
這種模式若使用相同型號容量的磁盤來組成效果最佳。這種模式RAID會先將磁盤切出等量的區塊chunk,當文件要存入RAID時先按照chunk的大小切割好,再依次存放到各個磁盤中去,由于磁盤會交錯存放數據,因此數據會均勻的存儲到各個磁盤上去,由于數據已經被切割并放置到不同的磁盤上,因此每個磁盤所負責的數據量都降低了。越多顆磁盤組成的RAID0性能會越好,因為每顆磁盤負責的數據量更低,每顆磁盤的容量最終會變成RAID0的總容量。由于數據是分散存放在各個磁盤上的,若有一磁盤損壞則整個RAID上的數據都將遺失。
RAID-1:
這種模式也是需要相同容量的磁盤,最好是一模一樣的磁盤。如果不同容量的磁盤組成RAID-1,則以容量最小的一顆磁盤為主。這種模式的主要目的是讓同一份數據,完整的保存在兩顆磁盤上。一份數據傳送到RAID-1后會被分成兩股,并分別寫到各個磁盤中去,由于同一份數據會被分別寫入其他不同的磁盤,因此如果要寫入100M數據時,數據先傳送到I/O總線后會被復制多份到各個磁盤,結果數據量就變大了,因此在大量寫入的 RAID-1的情況下,寫入的性能會變得非常差。由于兩顆磁盤內的數據一模一樣,所以任何一顆磁盤損壞時,磁盤的數據還是可以完整的保存下來的。
RAID-5:
RAID-5至少需要3顆以上的磁盤才能組成這種類型的磁盤陣列,這種磁盤陣列的數據寫入有些類似于RAID-0,不過每個循環的寫入過程中,在每顆磁盤還加入一個同位檢查數據,這個數據會記錄其他磁盤的備份數據,用于當有磁盤損毀時的救援。每個循環寫入時都會有部分的同位校驗碼被記錄起來,且每次都依次記錄在不同的磁盤上,因此當任何一個磁盤損壞時都能通過其他兩個磁盤計算出此磁盤內的數據。不過由于有同位校驗碼存在,RAID5的總容量是整體磁盤數量減一顆,若損毀的磁盤數大于等于2顆時,整個RAID5數據將損毀。在讀寫性能上讀取性能和RAID0有的一比,寫性能由于數據在寫入時要計算校驗碼,所以寫性能增加有限。
RAID-6:
由于RAID5僅支持損毀一顆磁盤,后來又發展出另一種等級RAID6.RAID6最少需要4顆磁盤才能組成,使用2顆磁盤作校驗碼,此時磁盤損壞2顆時仍然能正常讀取數據,讀寫性能上與RAID5類似。
RAID-01:
RAID01是先將2顆磁盤作RAID0,再將兩顆組成RAID0的磁盤組成RAID1,此種陣列方式兼備了RAID0的優勢,又具備RAID1的備份優勢,不過若兩組RAID0中同時損壞一個磁盤時,RAID01上的數據將有可能遺失,非常不安全。于是便出現了RAID0。
RAID-10:
RAID10在讀寫性能上與RAID10相同,不同的是他先將2個磁盤組成RAID1,然后再組成RAID0,此時每組RAID1都能損壞1顆磁盤。理論上最大磁盤的損壞量至少可以達到磁盤數的一半,數據的安全性極佳。
總結
項目 | RAID0 | RAID1 | RAID10 | RAID5 | RAID6 |
最少磁盤數 | 2 | 2 | 4 | 3 | 4 |
最大容錯磁盤數 | 無 | n-1 | n/2 | 1 | 2 |
數據安全性 | 完全沒有 | 最佳 | 最佳 | 好 | 比RAID5好 |
理論寫入性能 | n | 1 | n/2 | <n-1 | <n-2 |
理論讀出性能 | n | n | n | <n-1 | <n-2 |
可用容量 | n | 1 | n/2 | n-1 | n-2 |
5、創建一個大小為10G的RAID1,要求有一個空閑盤,而且CHUNK大小為128k;
[root@localhost ~]# fdisk /dev/sda 歡迎使用 fdisk (util-linux 2.23.2)。 更改將停留在內存中,直到您決定將更改寫入磁盤。 使用寫入命令前請三思。 命令(輸入 m 獲取幫助):n All primary partitions are in use 添加邏輯分區 5 起始 扇區 (111167488-251658239,默認為 111167488): 將使用默認值 111167488 Last 扇區, +扇區 or +size{K,M,G} (111167488-251658239,默認為 251658239):+10G 分區 5 已設置為 Linux 類型,大小設為 10 GiB 命令(輸入 m 獲取幫助):n All primary partitions are in use 添加邏輯分區 6 起始 扇區 (132141056-251658239,默認為 132141056): 將使用默認值 132141056 Last 扇區, +扇區 or +size{K,M,G} (132141056-251658239,默認為 251658239):+10G 分區 6 已設置為 Linux 類型,大小設為 10 GiB 命令(輸入 m 獲取幫助):n All primary partitions are in use 添加邏輯分區 7 起始 扇區 (153114624-251658239,默認為 153114624): 將使用默認值 153114624 Last 扇區, +扇區 or +size{K,M,G} (153114624-251658239,默認為 251658239):+10G 分區 7 已設置為 Linux 類型,大小設為 10 GiB 命令(輸入 m 獲取幫助):t 分區號 (1-7,默認 7):5 Hex 代碼(輸入 L 列出所有代碼):fd 已將分區“Linux”的類型更改為“Linux raid autodetect” 命令(輸入 m 獲取幫助):t 分區號 (1-7,默認 7):6 Hex 代碼(輸入 L 列出所有代碼):fd 已將分區“Linux”的類型更改為“Linux raid autodetect” 命令(輸入 m 獲取幫助):t 分區號 (1-7,默認 7):7 Hex 代碼(輸入 L 列出所有代碼):fd 已將分區“Linux”的類型更改為“Linux raid autodetect” 命令(輸入 m 獲取幫助):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) 正在同步磁盤。 [root@localhost ~]# partx -a /dev/sda partx: /dev/sda: error adding partitions 1-6 [root@localhost ~]# partx -a /dev/sda partx: /dev/sda: error adding partitions 1-7 [root@localhost ~]# mdadm -C /dev/md0 -a yes -c 128K -n 2 -x 1 -l 1 /dev/sda{5,6,7} mdadm: Note: this array has metadata at the start and may not be suitable as a boot device. If you plan to store '/boot' on this device please ensure that your boot-loader understands md/v1.x metadata, or use --metadata=0.90 Continue creating array? y mdadm: Defaulting to version 1.2 metadata mdadm: array /dev/md0 started. [root@localhost ~]# mdadm -D /dev/md0 /dev/md0: Version : 1.2 Creation Time : Mon Jul 3 13:02:33 2017 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 : Mon Jul 3 13:03:29 2017 State : clean, resyncing Active Devices : 2 Working Devices : 3 Failed Devices : 0 Spare Devices : 1 Resync Status : 41% complete Name : localhost.localdomain:0 (local to host localhost.localdomain) UUID : 5978a305:cc3929ac:b06a5262:e756335a Events : 6 Number Major Minor RaidDevice State 0 8 5 0 active sync /dev/sda5 1 8 6 1 active sync /dev/sda6 2 8 7 - spare /dev/sda7
6、創建一個大小為4G的RAID5設備,chunk大小為256k,格式化ext4文件系統,要求可開機自動掛載至/backup目錄,而且不更新訪問時間戳,且支持acl功能;
[root@localhost ~]# fdisk /dev/sda 歡迎使用 fdisk (util-linux 2.23.2)。 更改將停留在內存中,直到您決定將更改寫入磁盤。 使用寫入命令前請三思。 命令(輸入 m 獲取幫助):n All primary partitions are in use 添加邏輯分區 5 起始 扇區 (111167488-251658239,默認為 111167488): 將使用默認值 111167488 Last 扇區, +扇區 or +size{K,M,G} (111167488-251658239,默認為 251658239):+2G 分區 5 已設置為 Linux 類型,大小設為 2 GiB 命令(輸入 m 獲取幫助):n All primary partitions are in use 添加邏輯分區 6 起始 扇區 (115363840-251658239,默認為 115363840): 將使用默認值 115363840 Last 扇區, +扇區 or +size{K,M,G} (115363840-251658239,默認為 251658239):+2G 分區 6 已設置為 Linux 類型,大小設為 2 GiB 命令(輸入 m 獲取幫助):n All primary partitions are in use 添加邏輯分區 7 起始 扇區 (119560192-251658239,默認為 119560192): 將使用默認值 119560192 Last 扇區, +扇區 or +size{K,M,G} (119560192-251658239,默認為 251658239):+2G 分區 7 已設置為 Linux 類型,大小設為 2 GiB 命令(輸入 m 獲取幫助):t 分區號 (1-7,默認 7):5 Hex 代碼(輸入 L 列出所有代碼):fd 已將分區“Linux”的類型更改為“Linux raid autodetect” 命令(輸入 m 獲取幫助):t 分區號 (1-7,默認 7):6 Hex 代碼(輸入 L 列出所有代碼):fd 已將分區“Linux”的類型更改為“Linux raid autodetect” 命令(輸入 m 獲取幫助):t 分區號 (1-7,默認 7):7 Hex 代碼(輸入 L 列出所有代碼):fd 已將分區“Linux”的類型更改為“Linux raid autodetect” 命令(輸入 m 獲取幫助):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) 正在同步磁盤。 [root@localhost ~]# partx -a /dev/sda partx: /dev/sda: error adding partitions 1-7 [root@localhost ~]# partx -a /dev/sda [root@localhost ~]# mdadm -C /dev/md0 -a yes -n 3 -l 5 -c 256K /dev/sda{5,6,7} mdadm: /dev/sda6 appears to be part of a raid array: level=raid1 devices=2 ctime=Mon Jul 3 13:02:33 2017 mdadm: /dev/sda7 appears to be part of a raid array: level=raid1 devices=2 ctime=Mon Jul 3 13:02:33 2017 Continue creating array? yes mdadm: Defaulting to version 1.2 metadata mdadm: array /dev/md0 started. [root@localhost ~]# mdadm -D /dev/md0 /dev/md0: Version : 1.2 Creation Time : Mon Jul 3 13:50:54 2017 Raid Level : raid5 Array Size : 20955136 (19.98 GiB 21.46 GB) Used Dev Size : 10477568 (9.99 GiB 10.73 GB) Raid Devices : 3 Total Devices : 3 Persistence : Superblock is persistent Update Time : Mon Jul 3 13:56:11 2017 State : clean Active Devices : 3 Working Devices : 3 Failed Devices : 0 Spare Devices : 0 Layout : left-symmetric Chunk Size : 256K Name : localhost.localdomain:0 (local to host localhost.localdomain) UUID : 96fbb2b4:f258315a:1d8bf46d:fb634a02 Events : 18 Number Major Minor RaidDevice State 0 8 5 0 active sync /dev/sda5 1 8 6 1 active sync /dev/sda6 3 8 7 2 active sync /dev/sda7 [root@localhost ~]# mke2fs -t ext4 /dev/md0 mke2fs 1.42.9 (28-Dec-2013) 文件系統標簽= OS type: Linux 塊大小=4096 (log=2) 分塊大小=4096 (log=2) Stride=64 blocks, Stripe width=128 blocks 1310720 inodes, 5238784 blocks 261939 blocks (5.00%) reserved for the super user 第一個數據塊=0 Maximum filesystem blocks=2153775104 160 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000 Allocating group tables: 完成 正在寫入inode表: 完成 Creating journal (32768 blocks): 完成 Writing superblocks and filesystem accounting information: 完成 [root@localhost ~]# mkdir /backup [root@localhost ~]# blkid /dev/md0 /dev/md0: UUID="c355dac6-07f1-4db8-be6d-7db631b5b2a5" TYPE="ext4" [root@localhost ~]# vim /etc/fstab # # /etc/fstab # Created by anaconda on Thu Jun 15 18:59:54 2017 # # Accessible filesystems, by reference, are maintained under '/dev/disk' # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info # /dev/mapper/cl-root / xfs defaults 0 0 UUID=e2876e74-00e5-4f80-818d-1e2f47a3fe64 /boot xfs defaults 0 0 /dev/mapper/cl-home /home xfs defaults 0 0 /dev/mapper/cl-swap swap swap defaults 0 0 UUID=c355dac6-07f1-4db8-be6d-7db631b5b2a5 /backup ext4 defaults,acl,noatime 0 0 ~
7、寫一個腳本
(1) 接受一個以上文件路徑作為參數;
(2) 顯示每個文件擁有的行數;
(3) 總結說明本次共為幾個文件統計了其行數;
#!/bin/bash if [ $# -lt 1 ]; then echo "need a parameter"; fi for FILEPATH in $*;do if [ -f $FILEPATH ];then line=$(wc -l $FILEPATH | cut -d " " -f 1); echo "$FILEPATH has $line lines"; let sumline=$sumline+$line; else echo "$FILEPATH Must a File" exit 2 fi done echo "A total of $# files are displayed this time,with a total of $sumline lines"
8、寫一個腳本
(1) 傳遞兩個以上字符串當作用戶名;
(2) 創建這些用戶;且密碼同用戶名;
(3) 總結說明共創建了幾個用戶;
if [ $# -lt 1 ] ;then echo "need a string" exit 2 fi for USERNAME in $*;do if [ $(echo $USERNAME | wc -m) -lt 4 ];then echo "need more than 2 chars" exit 2 fi if id $USERNAME &> /dev/null ; then echo "$USERNAME is exist" exit 2 else useradd $USERNAME; echo "$USERNAME" | passwd --stdin $USERNAME > /dev/null; echo "$USERNAME already created" let SUM+=1 fi done echo "$SUM user has created"
9、寫一個腳本,新建20個用戶,visitor1-visitor20;計算他們的ID之和;
#!/bin/bash SUM=0 for i in {1..20};do useradd visitor$i UIDNUM=$(id -u visitor$i) let SUM=$SUM+$UIDNUM done echo "UIDSUM=$SUM"
原創文章,作者:M36-Masuri,如若轉載,請注明出處:http://www.www58058.com/79049
可以看出有在很認真的整理,這些將來都是自己的理論積累,加油。
@馬哥教育:第三題