N26-第七周

1、創建一個10G分區,并格式為ext4文件系統;
   (1) 要求其block大小為2048, 預留空間百分比為2, 卷標為MYDATA, 默認掛載屬性包含acl;

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

[root@localhost ~]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x151eee1f.

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-41943039, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): +10G
Partition 1 of type Linux and of size 10 GiB is set

Command (m for help): t  
Hex code (type L to list all codes): 83 
[root@localhost ~]# mkfs.ext4 -b 2048 -m 2 -L MYDATA /dev/sdb1 mke2fs 1.42.9 (28-Dec-2013) Filesystem label=MYDATA OS type: Linux Block size=2048 (log=1) Fragment size=2048 (log=1) Stride=0 blocks, Stripe width=0 blocks 655360 inodes, 5242880 blocks 104857 blocks (2.00%) reserved for the super user First data block=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: done                             Writing inode tables: done                             Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done   [root@localhost ~]# mount -o noexec,acl,noatime /dev/sdb1 /data/mydata/

2、創建一個大小為1G的swap分區,并創建好文件系統,并啟用之;

[root@localhost ~]# mkswap /dev/sdb2 
Setting up swapspace version 1, size = 1048572 KiB
no label, UUID=fd915379-a879-409b-8343-5698350022e6
[root@localhost ~]# swapon  /dev/sdb2

3、寫一個腳本
   (1)、獲取并列出當前系統上的所有磁盤設備;

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

#!/bin/bash
#
#
#
ls /dev/[s,h]d[a-z]
fdisk -l `ls /dev/[s,h]d[a-z]`   

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

    RAID0:將多塊硬盤組合成一塊硬盤使用,讀寫性能都有提升,磁盤利用率100%,無冗余能力,至少需要2塊硬盤

    RAID1:將一份數據存儲兩份,讀能力有提升,寫能力下將,磁盤利用率50%,有冗余能力,至少需要兩塊硬盤

    RAID2、3、4:現在基本沒有使用

    RAID5:將數據拆分存儲并加入校驗碼技術,讀寫能力均有提升,磁盤利用率為 (磁盤數-1)/磁盤數,最多允許壞一塊硬盤,至少需要3塊硬盤 

    RAID10:將磁盤先做raid1后再做raid0,讀寫能力均有提升,磁盤利用率為50%,每組最多允許壞一塊硬盤,至少需要4塊硬盤

    RAID01:將磁盤先做raid0后再做raid1,讀寫能力均有提升,磁盤利用率為50%,每組最多允許壞一塊硬盤,至少需要4塊硬盤

    注:RAID 10在整體容錯能力和恢復代價上比RAID 01更有優勢

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

[root@localhost scripts]# mdadm -C /dev/md1 -n 2 -x 1 -c 128 -l 1 /dev/sdb1 /dev/sdb2 /dev/sdb3
mdadm: /dev/sdb1 appears to contain an ext2fs file system
       size=10485760K  mtime=Sat Mar  4 13:38:10 2017
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? 
Continue creating array? (y/n) y
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md1 started.
[root@localhost scripts]# mdadm -D /dev/md1 
/dev/md1:
        Version : 1.2
  Creation Time : Sat Mar  4 16:27:42 2017
     Raid Level : raid1
     Array Size : 5238784 (5.00 GiB 5.36 GB)
  Used Dev Size : 5238784 (5.00 GiB 5.36 GB)
   Raid Devices : 2
  Total Devices : 3
    Persistence : Superblock is persistent

    Update Time : Sat Mar  4 16:27:58 2017
          State : clean, resyncing 
 Active Devices : 2
Working Devices : 3
 Failed Devices : 0
  Spare Devices : 1

  Resync Status : 64% complete

           Name : localhost.localdomain:1  (local to host localhost.localdomain)
           UUID : 345d614a:1c8921d7:4a62d97c:6d9555cc
         Events : 10

    Number   Major   Minor   RaidDevice State
       0       8       17        0      active sync   /dev/sdb1
       1       8       18        1      active sync   /dev/sdb2

       2       8       19        -      spare   /dev/sdb3

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

root@localhost scripts]# mdadm -C /dev/md5 -n 4 -c 256 -l 5 /dev/sdb1 /dev/sdb2 /dev/sdb3 /dev/sdb4
mdadm: /dev/sdb1 appears to contain an ext2fs file system
       size=10485760K  mtime=Sat Mar  4 13:38:10 2017
mdadm: /dev/sdb1 appears to be part of a raid array:
       level=raid1 devices=2 ctime=Sat Mar  4 16:27:42 2017
Continue creating array? y
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md5 started.
[root@localhost scripts]# mdadm -D /dev/md5 
/dev/md5:
        Version : 1.2
  Creation Time : Sat Mar  4 16:33:41 2017
     Raid Level : raid5
     Array Size : 3142656 (3.00 GiB 3.22 GB)
  Used Dev Size : 1047552 (1023.17 MiB 1072.69 MB)
   Raid Devices : 4
  Total Devices : 4
    Persistence : Superblock is persistent

    Update Time : Sat Mar  4 16:33:47 2017
          State : clean 
 Active Devices : 4
Working Devices : 4
 Failed Devices : 0
  Spare Devices : 0

         Layout : left-symmetric
     Chunk Size : 256K

           Name : localhost.localdomain:5  (local to host localhost.localdomain)
           UUID : afc5cf68:aa1f4f34:f3047c47:d0b6f61c
         Events : 18

    Number   Major   Minor   RaidDevice State
       0       8       17        0      active sync   /dev/sdb1
       1       8       18        1      active sync   /dev/sdb2
       2       8       19        2      active sync   /dev/sdb3
       4       8       20        3      active sync   /dev/sdb4
[root@localhost scripts]# echo "/dev/md5 /backup ext4 defaults,acl,noatime,nodiratime 0 0" >> /etc/fstab [root@localhost scripts]# mount -a

7、寫一個腳本
   (1) 接受一個以上文件路徑作為參數;
   (2) 顯示每個文件擁有的行數;

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

#!/bin/bash
#
#
#
SUM=$#
[[ $# -eq 0 ]] && echo "use $0 /path/tofilename ...."&& exit
while true;do
        NUM=`wc -l $1`
        echo $NUM 
        shift
        if [[ $# = 0 ]];then
        break
        fi
 done
 echo "file number is $SUM"                             

8、寫一個腳本
   (1) 傳遞兩個以上字符串當作用戶名;
   (2) 創建這些用戶;且密碼同用戶名;

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

#!/bin/bash
#
#
#
SUM=$#
[[ $# -le 2 ]] && echo "use $0 /path/tofilename ...."&& exit

while true;do
  id $1 &>/dev/null && echo "$1 is exits"&& break
        useradd $1 &>/dev/null
        echo "$1"| passwd --stdin $1 &>/dev/null
        echo "create  user $1 successful "
        shift
        if [[ $# = 0 ]];then
        break
        fi
 done
 echo "create user number is $SUM"

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

#!/bin/bash
#
#
#
SUM=0
for i in {1..20};do
        useradd vistor$i
        NUM=`id -u vistor$i`
        let SUM+=$NUM
done
echo $SUM                        

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

#!/bin/bash
#
#
#
NUM1=`grep "^[[:space:]]*$" /etc/fstab /etc/init.d/functions /etc/rc.d/rc.sysinit | wc -l`
NUM2=`grep "^#" /etc/fstab /etc/init.d/functions /etc/rc.d/rc.sysinit | wc -l`
echo "Blank line number is $NUM1"
echo "At the beginning of line No. # number is $NUM2"                                                                           

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

#!/bin/bash
#
#
#
SUM=0
grep "\<bash\>" /etc/passwd | awk -F: '{ OFS=" ";;print $1,$3 }'
for i in $(grep "\<bash\>" /etc/passwd | awk -F: '{print $3 }');do
        let SUM+=$i
done
echo $SUM
                                

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

#!/bin/bash
#
#
#
grep "[^:]$" /etc/group|cut -d: -f 4

grep "[^:]$" /etc/group|cut -d: -f 4|wc -l

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

[root@localhost ~]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0xb68ed7fc.

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-62914559, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-62914559, default 62914559): +10G
Partition 1 of type Linux and of size 10 GiB is set

Command (m for help): n
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p):  
Using default response p
Partition number (2-4, default 2): 
First sector (20973568-62914559, default 20973568): 
Using default value 20973568
Last sector, +sectors or +size{K,M,G} (20973568-62914559, default 62914559): +10G
Partition 2 of type Linux and of size 10 GiB is set

Command (m for help): t
Partition number (1,2, default 2): 
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'

Command (m for help): t
Partition number (1,2, default 2): 1
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'

Command (m for help): w
The partition table has been altered!
[root@localhost ~]# pvcreate /dev/sdb1 /dev/sdb2
  Physical volume "/dev/sdb1" successfully created
  Physical volume "/dev/sdb2" successfully created
[root@localhost ~]# vgcreate myvg -s 8M /dev/sdb1 /dev/sdb2
  Volume group "myvg" successfully created
[root@localhost ~]# lvcreate -n mylv1 -L  5G  myvg   Logical volume "mylv1" created.
[root@localhost ~]# mkfs.ext4 /dev/myvg/mylv1  mke2fs 1.42.9 (28-Dec-2013) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 327680 inodes, 1310720 blocks 65536 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=1342177280 40 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 Allocating group tables: done                             Writing inode tables: done                             Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done 
[root@localhost ~]# echo "/dev/myvg/mylv1 /users ext4 defaults,acl 0 0" >> /etc/fstab 
[root@localhost ~]# mount -a

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

useradd -d /users/magedu magedu
su - magedu
cp /etc/issue /etc/fstab .

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

[root@localhost ~]# lvextend -L +4G /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 ~]# resize2fs /dev/myvg/mylv1 
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/myvg/mylv1 to 2359296 (4k) blocks.
The filesystem on /dev/myvg/mylv1 is now 2359296 blocks long.

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

[root@localhost ~]# umount /users
[root@localhost ~]# fsck -t ext4 -f /dev/myvg/mylv1 
fsck from util-linux 2.23.2
e2fsck 1.42.9 (28-Dec-2013)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/mapper/myvg-mylv1: 11/589824 files (0.0% non-contiguous), 75551/2359296 blocks
[root@localhost ~]# resize2fs -f /dev/myvg/mylv1 7G
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/myvg/mylv1 to 1835008 (4k) blocks.
The filesystem on /dev/myvg/mylv1 is now 1835008 blocks long.
[root@localhost ~]# lvreduce -L -2G /dev/myvg/mylv1 
  WARNING: Reducing active logical volume to 7.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 7.00 GiB (896 extents).
  Logical volume mylv1 successfully resized.

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

# lvcreate -L 500M -p r -s mylv1-snapshot -n /dev/myvg1/mylv1                    
# mkidr /mnt/mylv_ss ; mount /dev/myvg1/mylv1-snapshot /mnt/mylv_ss
# cp -a /mnt/mylv_ss/*  /tmp                    
# umount /mnt/mylv_ss 
# lvremove /dev/myvg1/mylv1-snapshot

原創文章,作者:胡安慧,如若轉載,請注明出處:http://www.www58058.com/70454

(0)
胡安慧胡安慧
上一篇 2017-03-04 20:41
下一篇 2017-03-05 09:57

相關推薦

  • 文件管理命令及文件名通配

    Linux上的文件管理類命令都有哪些,其常用的使用方法及其相關示例演示。 目錄管理類的命令 mkdir 用法: mkdir [選項]… 目錄… 選項:  -p 遞歸創建多個目錄 實例: [root@centos7 ~]# mkdir -p /tmp/jerry/2016/…

    Linux干貨 2016-11-06
  • linux的發展史

                  linux的發展史     1  Linux的誕生:    1988年:芬蘭赫爾辛基大學迎來一位新生-linus benedict torvalds (后面簡稱linus)   2 &nbsp…

    Linux干貨 2016-10-19
  • 馬哥教育網絡班22期+第5周課程練習

    1、顯示當前系統上root、fedora或user1用戶的默認shell; [root@rhel677850 ~]# grep "^\(root\|fedora\|user1\)" /etc/passwd|awk -F: '{print $1,$7}&#039…

    Linux干貨 2016-09-26
  • mysql編譯安裝

    MYSQL編譯安裝:參考(http://v.youku.com/v_show/id_XMjc4MDUwNjYyOA==.html?from=s1.8-1-1.2&spm=a2h0k.8191407.0.0)(http://oldboy.blog.51cto.com/2561410/1917295)     編譯安裝mysql,最好…

    Linux干貨 2017-06-09
  • 加密通訊過程

    一次加密通訊的過程 1、client_hello   客戶端發起請求,以明文傳輸請求信息,包含版本信息,加密套件候選列表,壓縮算法候選列表,隨機數,擴展字段等信息,相關信息如下: 支持的最高TSL協議版本version,從低到高依次 SSLv2 SSLv3 TLSv1 TLSv1.1 TLSv1.2,當前基本不再使用低于 TLSv1 的版本 客戶端支持的加密…

    Linux干貨 2017-02-07
  • AWK基礎用法

    AWK: print 例子:給沒個/etc/passwd下的用戶都打招呼hello 答案: awk ‘{print “hello:”$1}’ /etc/passwd 內建變量 FS : 輸入分隔符 OFS: 輸出分隔符 RS : 行輸入分隔符 ORS: 行輸出分割符 NF : 字段數 NR : 行號數 FNR: 每個文件的行號數 ARGC: 參數個數 ARG…

    Linux干貨 2017-05-22

評論列表(2條)

  • 馬哥教育
    馬哥教育 2017-03-07 11:59

    完成的很好,14題的cp實現的功能是覆蓋吧!

  • 胡安慧
    胡安慧 2017-03-07 15:06

    阿西吧,少寫了個. ,這個比較簡單就沒有直接練習,直接寫出來的。。。。

欧美性久久久久