馬哥教育網絡班21期-第七周課程練習

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

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

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

[root@localhost ~]# mkfs.ext4 -b 2048 -L MYDATA -m 2 /dev/sdb1
[root@localhost ~]# mount -o noexec,noatime,acl /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): 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-1305, default 1): 
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-1305, default 1305): +1G

Command (m for help): t
Selected partition 1
Hex code (type L to list codes): 82
Changed system type of partition 1 to 82 (Linux swap / Solaris)

Command (m for help): p

Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 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: 0xeafee498

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         132     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: 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 ~]# mkswap /dev/sdb1
[root@localhost ~]# swapon /dev/sdb1

3、寫一個腳本

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

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

#!/bin/bash
#

fdisk -l | grep "^Disk /dev" | awk '{print $2}'| cut -d: -f1    #獲取磁盤設備
for list in `fdisk -l | grep "^/" | awk '{print $1}'`;do     #顯示空間使用
  df -h $list 
done

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

 級別 組合方式 性能
raid0 條帶式,至少2塊盤 提升讀寫性能,無冗余
raid1 鏡像式,至少2塊盤 略提升讀性能,寫性能下降,有冗余
raid5 輪流校驗,至少3塊盤 讀寫性能提升,可容錯1塊盤
raid10 先鏡像,后分條帶,至少4塊盤 讀寫性能提升,有冗余,每組鏡像可容錯一塊盤

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

[root@localhost ~]# mdadm -C /dev/md-test -n 2 -l 1 -c 128 /dev/sd{b,c}

6、創建一個大小為4G的RAID5設備,chunk大小為256k,格式化ext4文件系統,要求可開機自動掛載至/backup目錄,而且不更新訪問時間戳,且支持acl功能;

[root@localhost ~]# mdadm -C /dev/md1 -c 256 -l 5 -n 3 /dev/sd{b,c,d}
[root@localhost ~]# mount -a -o noatime,acl /dev/md1 /backup

7、寫一個腳本

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

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

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

#!/bin/bash
#

if [ $# -gt 0 ];then 
  for file_path in $*;do
    if [ -f $file_path ];then
       awk 'END{print NR}' $file_path
    else 
      echo "$file_path is not a file!"
    fi
  done
else 
  echo "you must input one file_path at least!"
fi
echo "count $# files"

8、寫一個腳本

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

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

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

#!/bin/bash
#
declare -i sum=0
newuser () {
    for user in $*;do
      if id $user &> /dev/null;then
        echo $user is exist
      else
        useradd $user
        echo "$user" | passwd --stdin $user
        let sum++
      fi
    done
}

if [ $# -lt 2 ];then
     echo "usage: newuser arg1 arg2 ...(at least 2 args)"
     exit
fi
newuser $*
echo "you add $sum users in this operation"

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

#!/bin/bash
#
declare -i num=1
declare -i sum=0
while [ $num -le 20 ];do
    useradd visitor$num
    let num++
  done

for list in $(seq 1 20);do
  id_number=$(id visitor$list | awk -F [=\(] '{print $2}')
  let sum+=$id_number
done
echo "sum of total ID is $sum"

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

#!/bin/bash
#
a="/etc/rc.d/rc.sysinit"
b="/etc/rc.d/init.d/functions"
c="/etc/fstab"
declare -i sum=0

for list in $a $b $c;do
  echo "$list have $(grep -c "^#" $list) lines"
  space_line=$(grep -c "^$" $list)
  let sum+=$space_line
done

echo "sum of total space lines is $sum"

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

#!/bin/bash
#
declare -i sum=0
awk -F: ' BEGIN{printf "%-15s %s\n","Username","ID"}$7 ~ /\/bin\/bash/{printf "%-15s %d\n",$1,$3 }' /etc/passwd

for num in $(awk -F: '{print $3}' /etc/passwd);do
   let sum+=$num
done
echo "sum of total user_id is $sum"

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

#!/bin/bash
#
declare -i sum=0
for user in $(awk -F: '{print $1}' /etc/passwd);do
   result=$(id $user | awk -F, '{print $2}')
   if [ ! -z "$result" ];then
     echo $user
     let sum++
   fi
done
echo "total is $sum"

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

[root@www1 ~]# pvcreate /dev/sd{b1,c1}
[root@www1 ~]# vgcreate -s 8M test-vg /dev/sd{b1,c1}
[root@www1 ~]# lvcreate -L 5G -n mylv1 test-vg
[root@www1 ~]# mkfs.ext4  /dev/test-vg/mylv1
[root@www1 ~]# echo "/dev/test-vg/mylv1  /users  ext4  defaults,acl  0  0" >> /etc/fstab

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

[root@www1 ~]# useradd -d /users/magedu magedu
[root@www1 ~]# su - magedu
[magedu@www1 ~]$ cp /tmp/* .

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

[root@www1 ~]# lvextend -L +4G -r /dev/test-vg/mylv1

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

[root@www1 ~]# lvreduce -L -2G -r /dev/test-vg/mylv1

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

[root@www1 ~]# lvcreate -s -L 100M -n mylv1.snapshot /dev/test-vg/mylv1

原創文章,作者:Net21_木頭,如若轉載,請注明出處:http://www.www58058.com/36555

(0)
Net21_木頭Net21_木頭
上一篇 2016-08-29
下一篇 2016-08-29

相關推薦

  • 馬哥教育網絡班22期+第五周課程練習

    1、顯示當前系統上root、fedora或user1用戶的默認shell; ~]# cat /etc/passwd |grep -E  "^(root|fedora|user1)" |awk -F: '{print $NF}'/bin/bash/bin/bash/bin/bash 2、找出/etc/rc.d/…

    Linux干貨 2016-09-19
  • N26-第十五周

    溫故知新1、總結sed和awk的詳細用法;sed stream EDitor 流編輯器,行級sed  [option] …’script’ [input-file]script 地址定界編輯命令常用選項-n 靜默模式 ,不輸出模式空間中的內容至屏幕-e script –expression …

    Linux干貨 2017-08-24
  • 互聯網安全之iptables/netfilter入門到進階

    隨著互聯網技術的方興未艾,各種網絡應用層出不窮,網絡攻擊、黑客入侵也成了網民暢游互聯網的心頭大患,互聯網安全也愈加受到了人們的重視。網絡防火墻,作為一種簡單高效的互聯網防御手段,逐漸成為了網民暢游網絡世界的保護傘。下面筆者介紹下Linux系統的守衛者——iptables/netfilter。 ?一 兄弟齊心,其利斷金 ?iptables/netfilter就…

    Linux干貨 2017-05-06
  • 誤刪除libc.so.6時,該怎么恢復

           一周一周光陰似流水,轉瞬即逝,又到了該說點什么的時候了。這周老師給我們出了一道實驗題,內容是當你不小心誤刪除了libc.so.6這個庫文件時,怎么恢復。意不意外?驚不驚喜?那下面就來簡單說說(呃……為什么不是詳細說說呢,因為這個這個水平有限,也只能是理解多少,給…

    2017-08-11
  • Linux基礎與命令解釋

    Linux基礎與命令 Linux起源     ? 1984 年:Richard Stallman 發起GNU 項目和自由軟件基金會 創建開源的UNIX 實用工具版本 創建通用公共許可證(GPL) ) 開源軟件許可實施原則 ? 1991 年:Linus Torvalds 發布Linux 創建開放源碼,類Unix 的內核,在GPL 下發布 下…

    Linux干貨 2017-03-17
  • 馬哥教育網絡班N22期+第9周課程練習

    1、寫一個腳本,判斷當前系統上所有用戶的shell是否為可登錄shell(即用戶的shell不是/sbin/nologin);分別這兩類用戶的個數;通過字符串比較來實現; #!/bin/bashnolo_user=0login_user=0while read user;do    bash_type=$(e…

    Linux干貨 2016-10-21

評論列表(1條)

  • 馬哥教育
    馬哥教育 2016-08-30 13:20

    第一個問題可以嘗試一下用腳本搞定,應該不難

欧美性久久久久