久久国产乱子伦精品免费M,亚洲一区二区三区91,欧美国产在线视频,国产精品视频久久

N26 第七周作業

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

Command (m for help): d
Selected partition 1
Partition 1 is deleted

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p):
Using default response p
Partition number (1-4, default 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): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost ~]# mke2fs -b 2048 -m 2 -t ext4 -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 ~]# tune2fs -o acl /dev/sdb1
tune2fs 1.42.9 (28-Dec-2013)
[root@localhost ~]# tune2fs -l /dev/sdb1
tune2fs 1.42.9 (28-Dec-2013)
Filesystem volume name:   MYDATA
Last mounted on:          <not available>
Filesystem UUID:          ddd0ab73-0f58-414c-ae46-d2b354d2bdde
Filesystem magic number:  0xEF53
Filesystem revision #:    1 (dynamic)
Filesystem features:      has_journal ext_attr resize_inode dir_index filetype 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:       Sat Feb  4 11:31:58 2017
Last mount time:          n/a
Last write time:          Sat Feb  4 11:32:29 2017
Mount count:              0
Maximum mount count:      -1
Last checked:             Sat Feb  4 11:31:58 2017
Check interval:           0 (<none>)
Lifetime writes:          65 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:      a05dbfa7-5483-4885-9295-2418b7bd76ea
Journal backup:           inode blocks

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

[root@localhost ~]# mount -o noexec,noatime /dev/sdb1 /data/mydata
[root@localhost ~]# stat /data/mydata/aaa.txt
  File: ‘/data/mydata/aaa.txt’
  Size: 15           Blocks: 4          IO Block: 2048   regular file
Device: 811h/2065d   Inode: 16          Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Context: unconfined_u:object_r:unlabeled_t:s0
Access: 2017-02-04 10:45:12.167018328 +0600
Modify: 2017-02-04 10:45:12.167018328 +0600
Change: 2017-02-04 10:45:12.197018328 +0600
 Birth: -
# 讀取文件后Access時間戳不會改變
[root@localhost ~]# cat /data/mydata/aaa.txt
I study Linux.
[root@localhost ~]# stat /data/mydata/aaa.txt
  File: ‘/data/mydata/aaa.txt’
  Size: 15           Blocks: 4          IO Block: 2048   regular file
Device: 811h/2065d   Inode: 16          Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Context: unconfined_u:object_r:unlabeled_t:s0
Access: 2017-02-04 10:45:12.167018328 +0600
Modify: 2017-02-04 10:45:12.167018328 +0600
Change: 2017-02-04 10:45:12.197018328 +0600
 Birth: -
# 即使設置掛載選項noatime,修改文件或touch文件仍然可以改變時間戳
[root@localhost ~]# touch /data/mydata/aaa.txt
[root@localhost ~]# stat /data/mydata/aaa.txt
  File: ‘/data/mydata/aaa.txt’
  Size: 15           Blocks: 4          IO Block: 2048   regular file
Device: 811h/2065d   Inode: 16          Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Context: unconfined_u:object_r:unlabeled_t:s0
Access: 2017-02-04 10:48:16.080017861 +0600
Modify: 2017-02-04 10:48:16.080017861 +0600
Change: 2017-02-04 10:48:16.080017861 +0600
 Birth: -

# 運行二進制程序會提示“權限拒絕”
[root@localhost ~]# /data/mydata/bash
-bash: /mnt/bash: Permission denied

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

[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.

Command (m for help): n
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p): 1
Invalid partition type `1'

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-41943039, default 20973568):
Using default value 20973568
Last sector, +sectors or +size{K,M,G} (20973568-41943039, default 41943039): +1G     
Partition 2 of type Linux and of size 1 GiB is set

Command (m for help): t
Partition number (1,2, default 2): 2
Hex code (type L to list all codes): L

 0  Empty           24  NEC DOS         81  Minix / old Lin bf  Solaris        
 1  FAT12           27  Hidden NTFS Win 82  Linux swap / So c1  DRDOS/sec (FAT-
 2  XENIX root      39  Plan 9          83  Linux           c4  DRDOS/sec (FAT-
 3  XENIX usr       3c  PartitionMagic  84  OS/2 hidden C:  c6  DRDOS/sec (FAT-
 4  FAT16 <32M      40  Venix 80286     85  Linux extended  c7  Syrinx         
 5  Extended        41  PPC PReP Boot   86  NTFS volume set da  Non-FS data    
 6  FAT16           42  SFS             87  NTFS volume set db  CP/M / CTOS / .
 7  HPFS/NTFS/exFAT 4d  QNX4.x          88  Linux plaintext de  Dell Utility   
 8  AIX             4e  QNX4.x 2nd part 8e  Linux LVM       df  BootIt         
 9  AIX bootable    4f  QNX4.x 3rd part 93  Amoeba          e1  DOS access     
 a  OS/2 Boot Manag 50  OnTrack DM      94  Amoeba BBT      e3  DOS R/O        
 b  W95 FAT32       51  OnTrack DM6 Aux 9f  BSD/OS          e4  SpeedStor      
 c  W95 FAT32 (LBA) 52  CP/M            a0  IBM Thinkpad hi eb  BeOS fs        
 e  W95 FAT16 (LBA) 53  OnTrack DM6 Aux a5  FreeBSD         ee  GPT            
 f  W95 Ext'd (LBA) 54  OnTrackDM6      a6  OpenBSD         ef  EFI (FAT-12/16/
10  OPUS            55  EZ-Drive        a7  NeXTSTEP        f0  Linux/PA-RISC b
11  Hidden FAT12    56  Golden Bow      a8  Darwin UFS      f1  SpeedStor      
12  Compaq diagnost 5c  Priam Edisk     a9  NetBSD          f4  SpeedStor      
14  Hidden FAT16 <3 61  SpeedStor       ab  Darwin boot     f2  DOS secondary  
16  Hidden FAT16    63  GNU HURD or Sys af  HFS / HFS+      fb  VMware VMFS    
17  Hidden HPFS/NTF 64  Novell Netware  b7  BSDI fs         fc  VMware VMKCORE
18  AST SmartSleep  65  Novell Netware  b8  BSDI swap       fd  Linux raid auto
1b  Hidden W95 FAT3 70  DiskSecure Mult bb  Boot Wizard hid fe  LANstep        
1c  Hidden W95 FAT3 75  PC/IX           be  Solaris boot    ff  BBT            
1e  Hidden W95 FAT1 80  Old Minix      
Hex code (type L to list all codes): 82
Changed type of partition 'Linux' to 'Linux swap / Solaris'

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost ~]# mkswap /dev/sdb2
Setting up swapspace version 1, size = 1048572 KiB
no label, UUID=00550b28-79e0-4a67-9a8f-020adf3bd811
[root@localhost ~]# swapon /dev/sdb2
[root@localhost ~]# lsblk
NAME            MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda               8:0    0   120G  0 disk
├─sda1            8:1    0   500M  0 part /boot
└─sda2            8:2    0 119.5G  0 part
  ├─centos-root 253:0    0    50G  0 lvm  /
  ├─centos-swap 253:1    0     2G  0 lvm  [SWAP]
  └─centos-home 253:2    0  67.5G  0 lvm  /home
sdb               8:16   0    20G  0 disk
├─sdb1            8:17   0    10G  0 part
└─sdb2            8:18   0     1G  0 part [SWAP]
sr0              11:0    1   7.2G  0 rom 

3、寫一個腳本
   (1)、獲取并列出當前系統上的所有磁盤設備;
   (2)、顯示每個磁盤設備上每個分區相關的空間使用信息;

#!/bin/bash

fdisk -l | grep "Disk /dev/sd." | cut -d: -f1
echo
df

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

RAID分為以下幾個級別
RAID0 條帶卷
   最少磁盤數量:2
   讀寫性能:讀寫性能均有提升
   容錯能力:沒有容錯能力,一旦有一塊磁盤損壞,將丟失全部數據
   磁盤空間:最小磁盤容量 * 磁盤數量
RAID1
   最少磁盤數量:2 一般不會多于2塊
   讀寫性能:讀數據性能提升,寫數據性能略有下降
   容錯能力:有容錯能力,允許一塊磁盤損壞
   磁盤空間:最小磁盤的磁盤容量
RAID4
   最少磁盤數量:3
   讀寫性能:讀寫性能均有提升
   容錯能力:有容錯能力,允許一塊磁盤損壞,但因為使用單獨磁盤做校驗盤,所以校驗盤讀寫壓力大,也增加了校驗盤損壞的風險
   磁盤空間:最小磁盤容量 * ( 磁盤數量-1 )
RAID5
   最少磁盤數量:3
   讀寫性能:正常工作時讀寫性能均有提升,如果有一塊磁盤損壞,則讀寫性能均會下降
   容錯能力:有容錯能力,允許一塊磁盤損壞
   磁盤空間:最小磁盤容量 * ( 磁盤數量-1 )
RAID6
   最少磁盤數量:4 兩塊磁盤做校驗盤
   讀寫性能:讀寫性能均有提升
   容錯能力:最多允許壞兩塊盤,但不允許兩塊數據盤同時損壞
   磁盤空間:最小磁盤容量 * ( 磁盤數量-2 )
以下為組合類型
RAID10
   實質是先把磁盤兩兩組成RAID1,然后再把RAID1組成RAID0,進一步提升了容錯能力,最多允許每一組RAID1中有一塊磁盤損壞
RAID01
   實質是先把一批磁盤分為兩組,然后每組磁盤組成RAID0,然后再把兩組RAID0組成RAID1,也能進一步提升容錯能力,但這種組合寫數據能力較RAID10偏低,因為這種組合需要數據兩級切片
RAID50
   先組RAID5,再組RAID0

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

[root@localhost ~]# fdisk /dev/sdb

Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x2b8c50c6.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

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): 1
First cylinder (1-1305, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-1305, default 1305):
Using default value 1305

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

[root@localhost ~]# fdisk /dev/sdc
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x9aef7b46.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

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): 1
First cylinder (1-2610, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610):
Using default value 2610

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

[root@localhost ~]# fdisk /dev/sdd
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x5ca49bc1.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

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): 1
First cylinder (1-1958, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-1958, default 1958):
Using default value 1958

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

[root@localhost ~]# lsblk
NAME                        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sr0                          11:0    1   4.2G  0 rom  
sda                           8:0    0   120G  0 disk
├─sda1                        8:1    0   500M  0 part /boot
└─sda2                        8:2    0 119.5G  0 part
  ├─VolGroup-lv_root (dm-0) 253:0    0    50G  0 lvm  /
  ├─VolGroup-lv_swap (dm-1) 253:1    0     2G  0 lvm  [SWAP]
  └─VolGroup-lv_home (dm-2) 253:2    0  67.6G  0 lvm  /home
sdb                           8:16   0    10G  0 disk
└─sdb1                        8:17   0    10G  0 part
sdc                           8:32   0    20G  0 disk
└─sdc1                        8:33   0    20G  0 part
sdd                           8:48   0    15G  0 disk
└─sdd1                        8:49   0    15G  0 part
# 三塊硬盤大小不同
[root@localhost ~]# mdadm -C /dev/md0 -l 1 -c 128 --raid-devices=2 /dev/sd[bc]1 --spare-devices=1 /dev/sdd1
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
mdadm: largest drive (/dev/sdc1) exceeds size (10474176K) by more than 1%
# 因為用做raid的磁盤大小差異太大,上面一行給出提示,下面一行詢問是否繼續創建
Continue creating array? (y/n) y  
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.
# 剛剛創建完成,執行掛載命令,提示必須先指定“文件系統類型”
# 看來沒有指定文件系統的設備是無法掛載的
[root@localhost ~]# mount /dev/md0 /mnt
mount: you must specify the filesystem type
# -D 選項查看剛剛創建在raid在詳細信息
[root@localhost ~]# mdadm -D /dev/md0
/dev/md0:
        Version : 1.2
  Creation Time : Sat Feb  4 11:29:15 2017
     Raid Level : raid1
     Array Size : 10474176 (9.99 GiB 10.73 GB)
  Used Dev Size : 10474176 (9.99 GiB 10.73 GB)
   Raid Devices : 2
  Total Devices : 3
    Persistence : Superblock is persistent

    Update Time : Sat Feb  4 11:30:08 2017
          State : clean
 Active Devices : 2
Working Devices : 3
 Failed Devices : 0
  Spare Devices : 1

           Name : localhost.localdomain:0  (local to host localhost.localdomain)
           UUID : a944c4e6:68ee9c12:baf9ff54:cec61ecf
         Events : 17

    Number   Major   Minor   RaidDevice State
       0       8       17        0      active sync   /dev/sdb1
       1       8       33        1      active sync   /dev/sdc1

       2       8       49        -      spare   /dev/sdd1

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

[root@localhost ~]# mdadm -C /dev/md1 -l5 -c256 --raid-devices=3 /dev/sd[efg]

mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md1 started.
[root@localhost ~]# mdadm --detail /dev/md1
/dev/md1:
        Version : 1.2
  Creation Time : Mon Feb  6 23:23:54 2017
     Raid Level : raid5
     Array Size : 4190208 (4.00 GiB 4.29 GB)
  Used Dev Size : 2095104 (2046.00 MiB 2145.39 MB)
   Raid Devices : 3
  Total Devices : 3
    Persistence : Superblock is persistent

    Update Time : Mon Feb  6 23:24:06 2017
          State : clean
 Active Devices : 3
Working Devices : 3
 Failed Devices : 0
  Spare Devices : 0

         Layout : left-symmetric
     Chunk Size : 256K

           Name : localhost.localdomain:1  (local to host localhost.localdomain)
           UUID : 177e560f:12fbca97:110aa862:ae27995c
         Events : 18

    Number   Major   Minor   RaidDevice State
       0       8       64        0      active sync   /dev/sde
       1       8       80        1      active sync   /dev/sdf
       3       8       96        2      active sync   /dev/sdg

[root@localhost ~]# mkfs.ext4 /dev/md1
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=64 blocks, Stripe width=128 blocks
262144 inodes, 1047552 blocks
52377 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1073741824
32 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

Writing inode tables: done                            
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 36 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@localhost ~]# blkid /dev/md1
/dev/md1: UUID="4dce67bd-a912-458c-9ab3-125de499f60e" TYPE="ext4"

[root@localhost ~]# mkdir /backup
[root@localhost ~]# vim /etc/fstab
# 添加一行,創建raid時使用/dev/md1但自動掛載時不一定是這個設備名稱,所以掛載時使用了UUID
UUID=4dce67bd-a912-458c-9ab3-125de499f60e   /backup     ext4  defaults,acl,noatime  0 0
# 重啟系統使用mount命令檢查是否自動掛載
[root@localhost ~]# mount
/dev/mapper/VolGroup-lv_root on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
/dev/sda1 on /boot type ext4 (rw)
/dev/mapper/VolGroup-lv_home on /home type ext4 (rw)
/dev/md126 on /backup type ext4 (rw,noatime,acl)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)

7、寫一個腳本
   (1) 接受一個以上文件路徑作為參數;
   (2) 顯示每個文件擁有的行數;
   (3) 總結說明本次共為幾個文件統計了其行數;

#!/bin/bash

# filename rptnof.sh
# report number of each ASCII text file, and give statistic info.

if [ $# -eq 0 ]; then
        echo "At least one path argument" && exit 1
fi

declare -i m=0 n=0;
for i in $@; do
        if [[  $(file -b $i) = "ASCII text" ]]; then
                echo $(wc -l $i)
                let m++;
        else
                let n++
        fi
done

echo -e "\nTotal $# files, $m text files and report number of lines, $n files not text file "

# 添加屬主執行權限
[root@localhost scripts]# chmod u+x rptnof.sh

[root@localhost scripts]# ./rptnof.sh /etc/fstab /etc/passwd /bin/bash
17 /etc/fstab
29 /etc/passwd

Total 3 files, 2 text files and report number of lines, 1 files not text file

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

#!/bin/bash

# add a batch of users

if [ $# -eq 0 ]; then
        echo "Usage: $(basename $0) username [,username]..."
fi

#!/bin/bash
# add a batch of users

if [ $# -eq 0 ]; then
        echo "Usage: $(basename $0) username [,username]..."
        exit 1
fi

declare -i num=0;
declare -a u;
for i in $@; do
        id $i &> /dev/null
        if [ $? -eq 0 ]; then
                echo "user $i exists"
        else
                (useradd $i && echo $i | passwd --stdin $i) &> /dev/null
                let num++;
                u[${#u[@]}]=$i
        fi
done

echo "Total $num users added: ${u[@]}"

[root@localhost scripts]# bash add-users.sh zhsan lisi wangwu zhaoliu
user zhsan exists
user lisi exists
Total 2 users added: wangwu zhaoliu

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

#!/bin/bash

declare -i sum=0;
for i in {1..20};do
        username="visitor$i"
        useradd "$username" &> /dev/null && sum+=$(id -u $username )
done

echo The sum of userid is $sum.

[root@localhost scripts]# bash sumuid.sh
The sum of userid is 10490.

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

#!/bin/bash

echo "The number of lines of start with # is $(grep "^#" /etc/rc.d/rc.sysinit /etc/rc.d/init.d/functions /etc/fstab | wc -l)"
echo "The number of lines of blank is $(grep "[[:space:]]*" /etc/rc.d/rc.sysinit /etc/rc.d/init.d/functions /etc/fstab | wc -l) "

[root@localhost scripts]# bash speclinecount.sh
The number of lines of start with # is 91
The number of lines of blank is 1484

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

#!/bin/bash

declare -a auid;
grep "/bin/bash$" /etc/passwd | cut -d: -f1,3
auid=($(grep "/bin/bash$" /etc/passwd | cut -d: -f1,3 | cut -d: -f2))
declare -i sum;
for i in ${auid[@]}; do
        sum+=$i;
done
echo "The sum of uid of above users is $sum."

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

#!/bin/bash

aUser=($(cat /etc/passwd | cut -d: -f1))
declare -i num=0;
for i in ${aUser[@]};do
        id $i | grep -E "groups=[^,]+,.+"
        if [ $? -eq 0 ]; then
                let num++;
        fi
done

echo "Total $num user(s) have supplementary group "

[root@localhost scripts]# bash specuser.sh
uid=1(bin) gid=1(bin) groups=1(bin),2(daemon),3(sys)
uid=2(daemon) gid=2(daemon) groups=2(daemon),1(bin),4(adm),7(lp)
uid=3(adm) gid=4(adm) groups=4(adm),3(sys)
uid=89(postfix) gid=89(postfix) groups=89(postfix),12(mail)
Total 4 user(s) have supplementary group

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

# 修改分區類型為Linux LVM
[root@localhost scripts]# fdisk /dev/sdc

2017-02-07 21 34 11.gif
# 查看分區
[root@localhost scripts]# fdisk -l /dev/sdc

2017-02-07 21 37 06.gif
# 創建物理卷
[root@localhost scripts]# pvcreate /dev/sdc[1-3]
# 創建卷組
[root@localhost scripts]# vgcreate -s 8M MyVolGrp /dev/sdc[1-3]
# 查看卷組
[root@localhost scripts]# vgdisplay MyVolGrp

2017-02-07 21 38 59.gif
# 創建邏輯卷
[root@localhost scripts]# lvcreate -L 5G -n mylv1 MyVolGrp
[root@localhost scripts]# lvs

2017-02-07 21 42 00.gif
# 格式化
[root@localhost scripts]# mkfs.ext4 /dev/mapper/MyVolGrp-mylv1

2017-02-07 21 44 09.gif
# 創建目錄用于掛載
[root@localhost scripts]# mkdir /users
# 編輯配置文件實現開機自動掛載
[root@localhost scripts]# vim + /etc/fstab
## /dev/mapper/MyVolGrp-mylv1      /users  ext4  acl       0 0
# 檢查開機自動掛載
[root@localhost ~]# mount

2017-02-07 21 44 59.gif

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

[root@localhost ~]# useradd -d /users/magedu magedu
[root@localhost ~]# tail -1 /etc/passwd
[root@localhost ~]# useradd -d /users/magedu magedu
[root@localhost ~]# tail -1 /etc/passwd
[magedu@localhost ~]$ ll .

2017-02-07 21 27 06.gif

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

# 擴展邏輯卷
[root@localhost ~]# lvextend -L 9G /dev/MyVolGrp/mylv1 
[root@localhost ~]# lvs
# 檢查磁盤空間發現并沒有擴展,還是5G大小     
[root@localhost ~]# df
# 擴展文件系統
[root@localhost ~]# resize2fs /dev/mapper/MyVolGrp-mylv1 
# 現在磁盤空間已經擴展
[root@localhost ~]# df -h /dev/mapper/MyVolGrp-mylv1 
# 檢查空間擴展后文件的可用性
[root@localhost ~]# ll /users/magedu
[root@localhost ~]# tail -1 /users/magedu/passwd

   

2017-02-07 21 19 36.gif

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

[root@localhost ~]# umount /dev/mapper/MyVolGrp-mylv1 
[root@localhost ~]# e2fsck -f /dev/mapper/MyVolGrp-mylv1
[root@localhost ~]# resize2fs /dev/MyVolGrp/mylv1 7G
[root@localhost ~]# lvreduce -L 7G /dev/MyVolGrp/mylv1 
[root@localhost ~]# mount -a
[root@localhost ~]# tail -1 /users/magedu/passwd

2017-02-07 21 14 15.jpg

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

[root@localhost tmp]# lvcreate -L 10M -p r -s -n mylv1_snap /dev/MyVolGrp/mylv1 
[root@localhost tmp]# mount /dev/MyVolGrp/mylv1_snap /mnt
mount: block device /dev/mapper/MyVolGrp-mylv1_snap is write-protected, mounting read-only
[root@localhost tmp]# tar cJf /backup/test.tar.xz /mnt/magedu
tar: Removing leading `/' from member names
[root@localhost tmp]# ll /backup/test.tar.xz 
-rw-r--r--. 1 root root 1208 Feb  7 08:56 /backup/test.tar.xz
[root@localhost tmp]# tar tfv /backup/test.tar.xz

2017-02-07 21 06 52.jpg

相關新聞

歷經多年發展,已成為國內好評如潮的Linux云計算運維、SRE、Devops、網絡安全、云原生、Go、Python開發專業人才培訓機構!

    1. 主站蜘蛛池模板: 桦川县| 南召县| 汨罗市| 商丘市| 峨山| 五常市| 兰考县| 铜川市| 满洲里市| 青海省| 宜章县| 绥中县| 弋阳县| 洪泽县| 色达县| 开封县| 正蓝旗| 贺州市| 巴里| 渝北区| 上杭县| 景泰县| 太和县| 高台县| 西城区| 凉山| 乐都县| 莱阳市| 泸溪县| 微山县| 无棣县| 青冈县| 泰兴市| 交口县| 剑川县| 定陶县| 饶阳县| 保山市| 临泽县| 玉树县| 阿鲁科尔沁旗|