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

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

(0)
SnooSnoo
上一篇 2016-08-01 17:46
下一篇 2016-08-01 18:11

相關推薦

  • keepalived實現高可用LVS

    前言 vrrp介紹:  vrrp(Virtual Router Redundancy Protocol)虛擬路由冗余協議;就是把多個路由器或多個網關設備加入到組中,然后在這一組中虛擬出一個路由器,此虛擬路由器有真是的IP和MAC地址,客戶端將網關指向此虛擬路由器的IP;客戶端向此虛擬路由器的IP和MAC地址發起請求時,由活動路由器負責響應;當活動路…

    Linux干貨 2015-07-23
  • linux中權限管理

    權限的描述:           權限的意思就是用戶擁有的對系統支配能力的大小在linux中是嚴格控制用戶權限的,不同的用戶給予不同的權限,權限應遵循能少給就盡量少給的原則從而增加系統的安全性。 進程安全上下文:    進程對問件訪問權限的應用模型:進程的屬主與文件的屬主是否相同,如果相同…

    系統運維 2016-08-05
  • Linux基礎知識之WMware Tools的安裝

    該博文以CentOS6.8_x86_64系統為基礎,tty終端登錄CentOS6.8系統,以root身份登錄系統。 為什么要安裝WMware Tools?                    VMware Tools是VMware虛擬機中自帶的一種增強工具,…

    Linux干貨 2016-07-29
  • 第五周作業

    1、顯示/boot/grub/grub.conf中以至少一個空白字符開頭的行; grep“^[[:space:]]\+” /boot/grub/grub.conf grep  -E “^[[:space:]]+” /boot/grub/grub.conf 2、顯示/etc…

    Linux干貨 2017-02-20
  • 對文件目錄操作命令詳解

    對文件目錄操作命令詳解 cd——切換目錄 pwd——顯示當前工作目錄 ls——列出目錄內容 touch——創建空文件和刷新時間 stat——查看文件狀態 cp——復制文件和目錄 mv——移動和重命名文件 rm——刪除文件或目錄 目錄操作 tree 顯示目錄樹 mkdir 創建目錄 rmdir 刪除空目錄 rm -r 遞歸刪除目錄樹 alias——命令別名 文…

    Linux干貨 2016-09-06
  • 2018近期it運維大會合集,這五場值得關注!

    17年,我們不僅看到Google、Facebook、Amazon、LinkedIn、Netflix、Airbnb等互聯網巨頭在與DevOps親密接觸,傳統軟件公司如Adobe、IBM、Microsoft、SAP等,亦或是網絡業務非核心的蘋果、沃爾瑪、索尼影視娛樂、星巴克等都在采用DevOps,更看到了國內一大片企業開始鐘情于此。

    2018-03-01

評論列表(1條)

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

    寫的很好,排版也很棒,加油

欧美性久久久久