1、創建一個10G分區,并格式為ext4文件系統;
(1) 要求其block大小為2048, 預留空間百分比為2, 卷標為MYDATA, 默認掛載屬性包含acl;
(2) 掛載至/data/mydata目錄,要求掛載時禁止程序自動運行,且不更新文件的訪問時間戳;
[root@centos7study ~]# fdisk /dev/sdc 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 0xe879321a. 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@centos7study ~]# cat /proc/partitions major minor #blocks name 8 0 20971520 sda 8 1 512000 sda1 8 2 10488832 sda2 8 3 4194304 sda3 8 16 5242880 sdb 8 17 1048576 sdb1 8 18 1048576 sdb2 8 19 1048576 sdb3 8 32 20971520 sdc 8 33 10485760 sdc1 11 0 617472 sr0 253 0 8388608 dm-0 253 1 2097152 dm-1 253 2 307200 dm-2 [root@centos7study ~]# mke2fs -t ext4 -b 2048 -m 2 -L MYDATA /dev/sdc1 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@centos7study ~]# mkdir -pv /data/mydata mkdir: created directory ‘/data’ mkdir: created directory ‘/data/mydata’ [root@centos7study ~]# echo '/dev/sdc1 /data/mydata ext4 defaults,noexec,nodiratime,acl 0 0' >> /etc/fstab [root@centos7study ~]# mount -a [root@centos7study ~]# mount | grep /dev/sdc1 /dev/sdc1 on /data/mydata type ext4 (rw,noexec,nodiratime,relatime,seclabel,data=ordered)
2、創建一個大小為1G的swap分區,并創建好文件系統,并啟用之;
[root@centos7study ~]# fdisk /dev/sdc 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): +1G Value out of range. 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): 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. 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@centos7study ~]# partx -a /dev/sdc partx: /dev/sdc: error adding partition 1 [root@centos7study ~]# !cat cat /proc/partitions major minor #blocks name 8 0 20971520 sda 8 1 512000 sda1 8 2 10488832 sda2 8 3 4194304 sda3 8 16 5242880 sdb 8 17 1048576 sdb1 8 18 1048576 sdb2 8 19 1048576 sdb3 8 32 20971520 sdc 8 33 10485760 sdc1 8 34 1048576 sdc2 11 0 617472 sr0 253 0 8388608 dm-0 253 1 2097152 dm-1 253 2 307200 dm-2 [root@centos7study ~]# mkswap /dev/sdc2 Setting up swapspace version 1, size = 1048572 KiB no label, UUID=0340f886-5d37-4c99-bb32-bd3cef571c02 [root@centos7study ~]# swapon -a /dev/sdc2 [root@centos7study ~]# swapon -s Filename Type Size Used Priority /dev/dm-1 partition 2097148 0 -1 /dev/sdc2 partition 1048572 0 -2
3、寫一個腳本
(1)、獲取并列出當前系統上的所有磁盤設備;
(2)、顯示每個磁盤設備上每個分區相關的空間使用信息;
[root@centos7study tmp]# cat fdisklist.sh #!/bin/bash echo -e "All of disk:\n`fdisk -l | grep -o "[sh]d[a-z]" | uniq `\n" echo "The Disk information:" for i in `fdisk -l | grep "^/dev/[sh]d[a-z][1-9]" | cut -d' ' -f1`; do df -h $i done
4、總結RAID的各個級別及其組合方式和性能的不同;
RAID-0: 讀、寫性能提升; 可用空間:N*min(S1,S2,...) 無容錯能力 最少磁盤數:2, 2+ RAID-1: 讀性能提升、寫性能略有下降; 可用空間:1*min(S1,S2,...) 有冗余能力 最少磁盤數:2, 2+ RAID-4: 1101, 0110, 1011 RAID-5: 讀、寫性能提升 可用空間:(N-1)*min(S1,S2,...) 有容錯能力:1塊磁盤 最少磁盤數:3, 3+ RAID-6: 讀、寫性能提升 可用空間:(N-2)*min(S1,S2,...) 有容錯能力:2塊磁盤 最少磁盤數:4, 4+ 混合類型 RAID-10: 讀、寫性能提升 可用空間:N*min(S1,S2,...)/2 有容錯能力:每組鏡像最多只能壞一塊; 最少磁盤數:4, 4+
5、創建一個大小為10G的RAID1,要求有一個空閑盤,而且CHUNK大小為128k;
[root@centos7study ~]# fdisk -l /dev/sdd Disk /dev/sdd: 10.7 GB, 10737418240 bytes, 20971520 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: dos Disk identifier: 0x645d84fd Device Boot Start End Blocks Id System /dev/sdd1 2048 4196351 2097152 83 Linux /dev/sdd2 4196352 8390655 2097152 83 Linux /dev/sdd3 8390656 12584959 2097152 83 Linux [root@centos7study ~]# mdadm -C /dev/md0 -n 2 -l 1 -a yes -c 128 -x 1 /dev/{sdd1,sdd2,sdd3} 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/md0 started. [root@centos7study ~]# mdadm -D /dev/md0 /dev/md0: Version : 1.2 Creation Time : Mon Aug 22 21:44:43 2016 Raid Level : raid1 Array Size : 2095104 (2046.34 MiB 2145.39 MB) Used Dev Size : 2095104 (2046.34 MiB 2145.39 MB) Raid Devices : 2 Total Devices : 3 Persistence : Superblock is persistent Update Time : Mon Aug 22 21:44:54 2016 State : clean Active Devices : 2 Working Devices : 3 Failed Devices : 0 Spare Devices : 1 Name : centos7study:0 (local to host centos7study) UUID : aeda4ef4:d7aaac0b:b062855f:81bfab77 Events : 17 Number Major Minor RaidDevice State 0 8 49 0 active sync /dev/sdd1 1 8 50 1 active sync /dev/sdd2 2 8 51 - spare /dev/sdd3
6、創建一個大小為4G的RAID5設備,chunk大小為256k,格式化ext4文件系統,要求可開機自動掛載至/backup目錄,而且不更新訪問時間戳,且支持acl功能;
[root@centos7study ~]# mdadm -C /dev/md1 -n 3 -l 5 -a yes -c 256 /dev/{sdd1,sdd2,sdd3} [root@centos7study ~]# mdadm -D /dev/md1 /dev/md1: Version : 1.2 Creation Time : Mon Aug 22 21:51:51 2016 Raid Level : raid5 Array Size : 4190208 (4.00 GiB 4.29 GB) Used Dev Size : 2095104 (2046.34 MiB 2145.39 MB) Raid Devices : 3 Total Devices : 3 Persistence : Superblock is persistent Update Time : Mon Aug 22 21:52:04 2016 State : clean Active Devices : 3 Working Devices : 3 Failed Devices : 0 Spare Devices : 0 Layout : left-symmetric Chunk Size : 256K Name : centos7study:1 (local to host centos7study) UUID : efffa3b7:b5728600:73535e40:c313a55c Events : 18 Number Major Minor RaidDevice State 0 8 49 0 active sync /dev/sdd1 1 8 50 1 active sync /dev/sdd2 3 8 51 2 active sync /dev/sdd3 [root@centos7study ~]# cat /proc/mdstat Personalities : [raid1] [raid6] [raid5] [raid4] md1 : active raid5 sdd3[3] sdd2[1] sdd1[0] 4190208 blocks super 1.2 level 5, 256k chunk, algorithm 2 [3/3] [UUU] unused devices: <none> [root@centos7study ~]# mkdir /backup [root@centos7study ~]# mke2fs -t ext4 /dev/md1 mke2fs 1.42.9 (28-Dec-2013) 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 Allocating group tables: done Writing inode tables: done Creating journal (16384 blocks): done Writing superblocks and filesystem accounting information: done [root@centos7study ~]# echo '/dev/md1 /backup ext4 defaults,noatime,acl 0 0' >> /etc/fstab [root@centos7study ~]# mount -a [root@centos7study ~]# mount | grep /dev/md1 /dev/md1 on /backup type ext4 (rw,noatime,seclabel,stripe=128,data=ordered)
7、寫一個腳本
(1) 接受一個以上文件路徑作為參數;
(2) 顯示每個文件擁有的行數;
(3) 總結說明本次共為幾個文件統計了其行數;
[root@centos7study tmp]# cat sumlines.sh #!/bin/bash if [ $# -eq 0 ];then echo "Please give a file name at least!" exit 1 fi for i in $* do echo "$i have $(wc -l $i | cut -d' ' -f1) lines" done echo "SUM $# FILES LINES!"
8、寫一個腳本
(1) 傳遞兩個以上字符串當作用戶名;
(2) 創建這些用戶;且密碼同用戶名;
(3) 總結說明共創建了幾個用戶;
[root@centos7study tmp]# cat createuser.sh #!/bin/bash if [ $# -lt 2 ];then echo "Please give 2 usernames at least !" exit 1 fi for i in $*;do useradd $i echo "$i:$i" | chpasswd done echo "Total Add $# users !"
9、寫一個腳本,新建20個用戶,visitor1-visitor20;計算他們的ID之和;
[root@centos7study tmp]# cat sumuid.sh #!/bin/bash declare -i sumuid for i in {1..20} do useradd visitor$i let sumuid+=$(id -u visitor$i) done echo "Total id is $sumuid !"
10、寫一腳本,分別統計/etc/rc.d/rc.sysinit、/etc/rc.d/init.d/functions和/etc/fstab文件中以#號開頭的行數之和,以及總的空白行數;
[root@centos7study tmp]# cat sumlines2.sh #!/bin/bash declare -i line declare -i nullline for i in {/etc/rc.d/rc.sysinit,/etc/rc.d/init.d/functions,/etc/fstab} do let line+=$(grep '^#' $i | wc -l | cut -d' ' -f1) let nullline+=$(grep '^[[:space:]]*$' $i | wc -l | cut -d' ' -f1) done echo "The lines with a beginning of '#' is $line lines !" echo "The lines with nothing is $nullline lines !"
11、寫一個腳本,顯示當前系統上所有默認shell為bash的用戶的用戶名、UID以及此類所有用戶的UID之和;
[root@centos7study tmp]# cat sumuid2.sh #!/bin/bash declare -i sum_uid grep "/bin/bash" /etc/passwd | cut -d':' -f 1,3 for i in `grep "/bin/bash" /etc/passwd | cut -d':' -f 3`;do let sum_uid+=i done echo "The uid sum is $sum_uid !"
12、寫一個腳本,顯示當前系統上所有,擁有附加組的用戶的用戶名;并說明共有多少個此類用戶;
[root@centos7study tmp]# cat sumuid2.sh #!/bin/bash declare -i sum_user for i in `cut -d: -f1 /etc/passwd`; do group=`id $i | awk -F, '{print $2}' ` if [ -n "$group" ];then echo "$i" let sum_user+=1 fi done echo "sum_user is $sum_user !"
13、創建一個由至少兩個物理卷組成的大小為20G的卷組;要求,PE大小為8M;而在卷組中創建一個大小為5G的邏輯卷mylv1,格式化為ext4文件系統,開機自動掛載至/users目錄,支持acl;
[root@centos7study data]# fdisk -l /dev/sdc Disk /dev/sdc: 21.5 GB, 21474836480 bytes, 41943040 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: dos Disk identifier: 0xe879321a Device Boot Start End Blocks Id System /dev/sdc1 2048 16779263 8388608 8e Linux LVM /dev/sdc2 16779264 33556479 8388608 8e Linux LVM [root@centos7study data]# pvcreate /dev/sdc{1,2} WARNING: ext4 signature detected on /dev/sdc1 at offset 1080. Wipe it? [y/n]: y Wiping ext4 signature on /dev/sdc1. Physical volume "/dev/sdc1" successfully created Physical volume "/dev/sdc2" successfully created [root@centos7study data]# pvs PV VG Fmt Attr PSize PFree /dev/sda2 centos_centos7study lvm2 a-- 10.00g 0 /dev/sdc1 lvm2 --- 8.00g 8.00g /dev/sdc2 lvm2 --- 8.00g 8.00g [root@centos7study data]# vgcreate -s 8M myvg1 /dev/sdc1 /dev/sdc2 Volume group "myvg1" successfully created [root@centos7study data]# vgdisplay -v myvg1 Using volume group(s) on command line. --- Volume group --- VG Name myvg1 System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 1 VG Access read/write VG Status resizable MAX LV 0 Cur LV 0 Open LV 0 Max PV 0 Cur PV 2 Act PV 2 VG Size 15.98 GiB PE Size 8.00 MiB Total PE 2046 Alloc PE / Size 0 / 0 Free PE / Size 2046 / 15.98 GiB VG UUID AWmd0l-iTIY-pv1z-lSGP-8mPB-QmcA-e7vdLI --- Physical volumes --- PV Name /dev/sdc1 PV UUID 0unhfN-c18W-TSnm-BTSp-5cFJ-aFdO-k2hfL3 PV Status allocatable Total PE / Free PE 1023 / 1023 PV Name /dev/sdc2 PV UUID 9z9ZOJ-ysmD-JTbH-VrCy-9LOB-aOV6-NSKcLH PV Status allocatable Total PE / Free PE 1023 / 1023 [root@centos7study data]# lvcreate -L 5G -n mylv1 myvg1 Logical volume "mylv1" created. [root@centos7study data]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert root centos_centos7study -wi-ao---- 8.00g swap centos_centos7study -wi-ao---- 2.00g mylv1 myvg1 -wi-a----- 5.00g [root@centos7study data]# mke2fs -t ext4 /dev/myvg1/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@centos7study data]# mkdir /users [root@centos7study data]# cat /etc/fstab /dev/myvg1/mylv1 /users ext4 defaults,acl 0 0 [root@centos7study data]# mount -a
14、新建用戶magedu;其家目錄為/users/magedu,而后su切換至此用戶,復制多個文件至家目錄;
[root@centos7study ~]# useradd -d /users/magedu magedu [root@centos7study ~]# su magedu [magedu@centos7study root]$ cp /etc/fstab /users/magedu [magedu@centos7study root]$ cp -r /tmp/mytest1 /users/magedu [magedu@centos7study root]$ cp -r /tmp/mylinux/ /users/magedu
15、擴展mylv1至9G,確保擴展完成后原有數據完全可用;
[root@centos7study ~]# lvextend -L +4g /dev/myvg1/mylv1 /dev/sdc{1,2} Size of logical volume myvg1/mylv1 changed from 5.00 GiB (640 extents) to 9.00 GiB (1152 extents). Logical volume mylv1 successfully resized. [root@centos7study ~]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert root centos_centos7study -wi-ao---- 8.00g swap centos_centos7study -wi-ao---- 2.00g mylv1 myvg1 -wi-ao---- 9.00g [root@centos7study ~]# resize2fs /dev/myvg1/mylv1 resize2fs 1.42.9 (28-Dec-2013) Filesystem at /dev/myvg1/mylv1 is mounted on /users; on-line resizing required old_desc_blocks = 1, new_desc_blocks = 2 The filesystem on /dev/myvg1/mylv1 is now 2359296 blocks long. [root@centos7study ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/centos_centos7study-root 8.0G 1.9G 6.2G 24% / devtmpfs 479M 0 479M 0% /dev tmpfs 489M 0 489M 0% /dev/shm tmpfs 489M 6.8M 483M 2% /run tmpfs 489M 0 489M 0% /sys/fs/cgroup /dev/mapper/myvg1-mylv1 8.8G 25M 8.3G 1% /users /dev/sda1 497M 123M 375M 25% /boot tmpfs 98M 0 98M 0% /run/user/0 [root@centos7study ~]# ls /users/magedu/ fstab mylinux mytest1 sysconfig [root@centos7study ~]# su magedu [magedu@centos7study root]$ cd ~ [magedu@centos7study ~]$ pwd /users/magedu
16、縮減mylv1至7G,確保縮減完成后原有數據完全可用;
[root@centos7study ~]# umount /dev/myvg1/mylv1 [root@centos7study ~]# e2fsck -f /dev/myvg1/mylv1 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/myvg1/mylv1: 30/589824 files (0.0% non-contiguous), 75874/2359296 blocks [root@centos7study ~]# lvreduce -L -2g /dev/myvg1/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 [root@centos7study ~]# resize2fs /dev/myvg1/mylv1 [root@centos7study ~]# mount -a [root@centos7study ~]# su magedu [magedu@centos7study root]$ cd ~ [magedu@centos7study ~]$ pwd /users/magedu
17、對mylv1創建快照,并通過備份數據;要求保留原有的屬主屬組等信息;
[root@centos7study ~]# lvcreate -L 3g -p r -s -n mylv_snapshot /dev/myvg1/mylv1 Logical volume "mylv_snapshot" created.
原創文章,作者:N21-孟然,如若轉載,請注明出處:http://www.www58058.com/38621
非常的棒,給出了操作詳細的過程,能把相關的知識在總結一下就更好哈,^_^