其他分享
首页 > 其他分享> > 第五周作业

第五周作业

作者:互联网

1、LVM逻辑卷管理
1)创建一个至少有两个PV组成的大小为20G的名为testvg的 VG;要求PE大小为16MB, 而后在卷组中创建大小为5G的逻辑卷testlv;挂载至/users目录

[root@zeedu tool]# fdisk -l

Disk /dev/sda: 128.8 GB, 128849018880 bytes, 251658240 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: 0x0000d0bc

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200    65013759    31457280   83  Linux
/dev/sda3        65013760    85985279    10485760   83  Linux
/dev/sda4        85985280   251658239    82836480    5  Extended
/dev/sda5        85987328    92278783     3145728   82  Linux swap / Solaris
/dev/sda6        92280832   102766591     5242880   83  Linux
/dev/sda7       102768640   123740159    10485760   8e  Linux LVM
/dev/sda8       123742208   144713727    10485760   8e  Linux LVM
[root@zeedu tool]# lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0  120G  0 disk 
├─sda1   8:1    0    1G  0 part /boot
├─sda2   8:2    0   30G  0 part /data
├─sda3   8:3    0   10G  0 part /
├─sda4   8:4    0    1K  0 part 
├─sda5   8:5    0    3G  0 part [SWAP]
└─sda6   8:6    0    5G  0 part /home
sr0     11:0    1  4.3G  0 rom  
[root@zeedu tool]# partprobe
Warning: Unable to open /dev/sr0 read-write (Read-only file system).  /dev/sr0 has been opened read-only.
[root@zeedu tool]# 
[root@zeedu tool]# 
[root@zeedu tool]# lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0  120G  0 disk 
├─sda1   8:1    0    1G  0 part /boot
├─sda2   8:2    0   30G  0 part /data
├─sda3   8:3    0   10G  0 part /
├─sda4   8:4    0  512B  0 part 
├─sda5   8:5    0    3G  0 part [SWAP]
├─sda6   8:6    0    5G  0 part /home
├─sda7   8:7    0   10G  0 part 
└─sda8   8:8    0   10G  0 part 
sr0     11:0    1  4.3G  0 rom  
[root@zeedu tool]# 
[root@zeedu tool]# 
[root@zeedu tool]# pvcreate /dev/sda{7,8}
  Physical volume "/dev/sda7" successfully created.
  Physical volume "/dev/sda8" successfully created.
[root@zeedu tool]# 
[root@zeedu tool]# 
[root@zeedu tool]# 
[root@zeedu tool]# pvs
  PV         VG Fmt  Attr PSize  PFree 
  /dev/sda7     lvm2 ---  10.00g 10.00g
  /dev/sda8     lvm2 ---  10.00g 10.00g
[root@zeedu tool]# 
[root@zeedu tool]# 
[root@zeedu tool]# 
[root@zeedu tool]# vgs
[root@zeedu tool]# 
[root@zeedu tool]# 
[root@zeedu tool]# vgcreate -s 16M testvg /dev/sda{7,8}
  Volume group "testvg" successfully created
[root@zeedu tool]# 
[root@zeedu tool]# 
[root@zeedu tool]# vgs
  VG     #PV #LV #SN Attr   VSize   VFree  
  testvg   2   0   0 wz--n- <19.97g <19.97g
[root@zeedu tool]# vgdisplay
  --- Volume group ---
  VG Name               testvg
  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               <19.97 GiB
  PE Size               16.00 MiB
  Total PE              1278
  Alloc PE / Size       0 / 0   
  Free  PE / Size       1278 / <19.97 GiB
  VG UUID               PAWE1V-jRWM-90W0-FmNo-1jZB-UMZz-uQJwFQ

[root@zeedu tool]# 
[root@zeedu tool]# 
[root@zeedu tool]# lvcreate -L 5G -n testlv testvg
  Logical volume "testlv" created.
[root@zeedu tool]# 
[root@zeedu tool]# 
[root@zeedu tool]# lvs
  LV     VG     Attr       LSize Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  testlv testvg -wi-a----- 5.00g                                                    
[root@zeedu tool]# 
[root@zeedu tool]# 
[root@zeedu tool]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/testvg/testlv
  LV Name                testlv
  VG Name                testvg
  LV UUID                1156UT-M3RT-Zgo7-8DPI-x2VI-jqqz-A9JlHw
  LV Write Access        read/write
  LV Creation host, time zeedu, 2019-05-02 23:09:48 +0800
  LV Status              available
  # open                 0
  LV Size                5.00 GiB
  Current LE             320
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0

[root@zeedu tool]# mkfs.xfs /dev/testvg/testlv 
meta-data=/dev/testvg/testlv     isize=512    agcount=4, agsize=327680 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=1310720, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
[root@zeedu tool]# 
[root@zeedu tool]# 
[root@zeedu tool]# 
[root@zeedu tool]# lvs
  LV     VG     Attr       LSize Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  testlv testvg -wi-a----- 5.00g                                                    
[root@zeedu tool]# 
[root@zeedu tool]# 
[root@zeedu tool]# mkdir /users
[root@zeedu tool]# mount /dev/testvg/testlv /users
[root@zeedu tool]# 
[root@zeedu tool]# 
[root@zeedu tool]# df -h
Filesystem                 Size  Used Avail Use% Mounted on
/dev/sda3                   10G  1.7G  8.4G  17% /
devtmpfs                   476M     0  476M   0% /dev
tmpfs                      487M     0  487M   0% /dev/shm
tmpfs                      487M  7.8M  479M   2% /run
tmpfs                      487M     0  487M   0% /sys/fs/cgroup
/dev/sda2                   30G   42M   30G   1% /data
/dev/sda6                  5.0G   33M  5.0G   1% /home
/dev/sda1                 1014M  127M  888M  13% /boot
tmpfs                       98M     0   98M   0% /run/user/0
/dev/mapper/testvg-testlv  5.0G   33M  5.0G   1% /users
[root@zeedu tool]# 
[root@zeedu tool]# vi /etc/fstab
[root@zeedu tool]# 
[root@zeedu tool]# 
[root@zeedu tool]# blkid
/dev/sda1: UUID="28db4a53-1e2a-465d-9c47-6b335168a055" TYPE="xfs" 
/dev/sda2: UUID="89f030f0-85e9-4352-ba99-fc1a849a949a" TYPE="xfs" 
/dev/sda3: UUID="f9cba076-314d-44a2-9364-3a55ae4cfe51" TYPE="xfs" 
/dev/sda5: UUID="e9e9830e-61f1-4e8f-8fa0-55a5ae593d99" TYPE="swap" 
/dev/sda6: UUID="24142266-6ed9-42d0-bab2-c159a42f56d2" TYPE="xfs" 
/dev/sda7: UUID="zG969c-EMCC-sbeN-arbm-CEaH-9QPM-f7pOKK" TYPE="LVM2_member" 
/dev/sda8: UUID="J3nHwE-2Z95-2DuT-RNzP-4wH7-44Ix-rfekEV" TYPE="LVM2_member" 
/dev/sr0: UUID="2018-11-25-23-54-16-00" LABEL="CentOS 7 x86_64" TYPE="iso9660" PTTYPE="dos" 
/dev/mapper/testvg-testlv: UUID="50ac6476-468c-4ea6-8475-56d893ce65f5" TYPE="xfs" 
[root@zeedu tool]# vi /etc/fstab

[No write since last change]

Press ENTER or type command to continue
[No write since last change]
/bin/bash: r: command not found

shell returned 127

Press ENTER or type command to continue
[root@zeedu tool]# 
[root@zeedu tool]# 
[root@zeedu tool]# 
[root@zeedu tool]# more /etc/fstab

#
# /etc/fstab
# Created by anaconda on Thu May  2 16:11:23 2019
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=f9cba076-314d-44a2-9364-3a55ae4cfe51 /                       xfs     defaults  
      0 0
UUID=28db4a53-1e2a-465d-9c47-6b335168a055 /boot                   xfs     defaults  
      0 0
UUID=89f030f0-85e9-4352-ba99-fc1a849a949a /data                   xfs     defaults  
      0 0
UUID=24142266-6ed9-42d0-bab2-c159a42f56d2 /home                   xfs     defaults  
      0 0
UUID=e9e9830e-61f1-4e8f-8fa0-55a5ae593d99 swap                    swap    defaults  
      0 0
UUID=50ac6476-468c-4ea6-8475-56d893ce65f5 /users          xfs     defaults   0 0
[root@zeedu tool]# 

ext4:
vgcreate -s 16M testvg /dev/sda{7,8}
vgs
lvcreate -L +5G -n testlv testvg
lvs
mkfs.ext4 /dev/testvg/testlv
lvs
lsblk
blkid
ll -d /users
ll /users
clear
mount /dev/testvg/testlv /users
df -h

2)扩展testlv至7G,要求 archlinux用户的文件不能丢失
[root@zeedu ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 10G 1.7G 8.4G 17% /
devtmpfs 476M 0 476M 0% /dev
tmpfs 487M 0 487M 0% /dev/shm
tmpfs 487M 7.7M 479M 2% /run
tmpfs 487M 0 487M 0% /sys/fs/cgroup
/dev/sda2 30G 42M 30G 1% /data
/dev/sda6 5.0G 33M 5.0G 1% /home
/dev/sda1 1014M 127M 888M 13% /boot
tmpfs 98M 0 98M 0% /run/user/0
/dev/mapper/testvg-testlv 5.0G 33M 5.0G 1% /users
[root@zeedu users]# xfs_growfs /dev/testvg/testlv
meta-data=/dev/mapper/testvg-testlv isize=512 agcount=4, agsize=327680 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=1310720, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 1310720 to 1835008
[root@zeedu users]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
testlv testvg -wi-ao---- 7.00g
[root@zeedu /]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 10G 1.7G 8.4G 17% /
devtmpfs 476M 0 476M 0% /dev
tmpfs 487M 0 487M 0% /dev/shm
tmpfs 487M 7.7M 479M 2% /run
tmpfs 487M 0 487M 0% /sys/fs/cgroup
/dev/sda2 30G 42M 30G 1% /data
/dev/sda6 5.0G 33M 5.0G 1% /home
/dev/sda1 1014M 127M 888M 13% /boot
tmpfs 98M 0 98M 0% /run/user/0
/dev/mapper/testvg-testlv 7.0G 33M 7.0G 1% /users

ext4:
umount /dev/testvg/testlv
e2fsck /dev/testvg/testlv
lvextend -L +2G /dev/testvg/testlv
lvs
mount /users/
mount /dev/testvg/testlv /users
resize2fs /dev/testvg/testlv
df -h

3)收缩testlv至3G,要求archlinux文件不能丢失
root@zeedu /]# e2fsck /dev/testvg/testlv -f
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/testvg/testlv: 2537/458752 files (0.2% non-contiguous), 75965/1835008 blocks
[root@zeedu /]# resize2fs /dev/testvg/testlv 3G
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/testvg/testlv to 786432 (4k) blocks.
The filesystem on /dev/testvg/testlv is now 786432 blocks long.

[root@zeedu /]# lvreduce -L 3G /dev/testvg/testlv
WARNING: Reducing active logical volume to 3.00 GiB.
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce testvg/testlv? [y/n]: y
Size of logical volume testvg/testlv changed from 7.00 GiB (448 extents) to 3.00 GiB (192 extents).
Logical volume testvg/testlv successfully resized.
[root@zeedu /]#
[root@zeedu /]#
[root@zeedu /]# mount /dev/testvg/testlv /users/
[root@zeedu /]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 10G 1.7G 8.4G 17% /
devtmpfs 476M 0 476M 0% /dev
tmpfs 487M 0 487M 0% /dev/shm
tmpfs 487M 7.7M 479M 2% /run
tmpfs 487M 0 487M 0% /sys/fs/cgroup
/dev/sda2 30G 42M 30G 1% /data
/dev/sda6 5.0G 33M 5.0G 1% /home
/dev/sda1 1014M 127M 888M 13% /boot
tmpfs 98M 0 98M 0% /run/user/0
/dev/mapper/testvg-testlv 2.9G 49M 2.7G 2% /users
[root@zeedu /]#

4)对testlv创建快照,并尝试基于快照备份数据,验证快照的功能
首先需要确保/dev/testvg上有空间可以存放快照
[root@zeedu /]# lvcreate -n testlv_snap -s -L 1G /dev/testvg/testlv
Logical volume "testlv_snap" created.
[root@zeedu /]#
[root@zeedu /]# mkdir /users_snap
[root@zeedu /]# mount /dev/testvg/testlv_snap /users_snap
[root@zeedu /]# cd /users
users/ users_snap/
[root@zeedu /]# cd /users_snap/
[root@zeedu users_snap]# ls
etc fstab lost+found

2、创建一个可用空间为1G的RAID1设备,文件系统ext4,有一个空闲盘,开机挂载至/backup目录
mdadm -C /dev/md0 -l 1 -n 2 /dev/sda{9,10} -x 1 /dev/sda11
mkdir /backup
mkfs.ext4 /dev/md0
mount /dev/md0 /backup

df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 10G 1.8G 8.3G 18% /
devtmpfs 476M 0 476M 0% /dev
tmpfs 487M 0 487M 0% /dev/shm
tmpfs 487M 7.8M 479M 2% /run
tmpfs 487M 0 487M 0% /sys/fs/cgroup
/dev/sda2 30G 88M 30G 1% /data
/dev/sda6 5.0G 33M 5.0G 1% /home
/dev/sda1 1014M 127M 888M 13% /boot
tmpfs 98M 0 98M 0% /run/user/0
/dev/mapper/testvg-testlv 2.9G 49M 2.7G 2% /users
/dev/mapper/testvg-testlv_snap 2.9G 49M 2.7G 2% /users_snap
/dev/md0 990M 2.6M 921M 1% /backup

标签:testvg,zeedu,tool,作业,dev,第五,testlv,root
来源: https://blog.51cto.com/1456850/2388558