1、磁盘lvm管理,完成下面要求,并写出详细过程:
1) 创建一个至少有两个PV组成的大小为20G的名为testvg的VG;要求PE大小为16MB,而后在卷组中创建大小为5G的逻辑卷testlv;挂载至/users目录
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 200G 0 disk
├─sda1 8:1 0 4G 0 part /boot
├─sda2 8:2 0 30.2G 0 part /
├─sda3 8:3 0 30.2G 0 part /data
├─sda4 8:4 0 1K 0 part
├─sda5 8:5 0 20G 0 part /home
├─sda6 8:6 0 1M 0 part
└─sda7 8:7 0 10G 0 part
sdb 8:16 0 200G 0 disk
└─sdb1 8:17 0 10G 0 part
sr0 11:0 1 1024M 0 rom
[root@localhost ~]# pvcreate /dev/sda7 ## 创建pv
Physical volume "/dev/sda7" successfully created.
[root@localhost ~]# pvcreate /dev/sdb1 ## 创建pv
Physical volume "/dev/sdb1" successfully created.
[root@localhost ~]# vgcreate testvg -s 16M /dev/sda7 /dev/sdb1 ## 创建vg,指定名称为testvg,PE大小为16M,由sda7和sdb1两个pv组成
Volume group "testvg" successfully created
[root@localhost ~]# vgdisplay ## 查看vg状态
--- 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 bMPFGG-sPXf-YWY1-HRDi-HUa8-4cpC-dx2Dfg
[root@localhost ~]# lvcreate -n testlv -L 5G /dev/testvg ## 创建lv,指定名字为testlv,大小为5G,使用testvg创建
Logical volume "testlv" created.
[root@localhost ~]# lvdisplay ## 查看lv状态
--- Logical volume ---
LV Path /dev/testvg/testlv
LV Name testlv
VG Name testvg
LV UUID fspf1Q-zHJO-BKPF-9KkF-e5lO-2Ow6-7lH3bS
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2019-04-19 16:24: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@localhost ~]# mkfs.ext4 /dev/testvg/testlv ## 针对新建的testlv制作文件ext4系统
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 ~]# mount /dev/testvg/testlv /users ## 进行挂载操作
[root@localhost users]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 31G 3.5G 27G 12% /
devtmpfs 895M 0 895M 0% /dev
tmpfs 910M 0 910M 0% /dev/shm
tmpfs 910M 9.9M 900M 2% /run
tmpfs 910M 0 910M 0% /sys/fs/cgroup
/dev/sda5 20G 33M 20G 1% /home
/dev/sda3 31G 33M 31G 1% /data
/dev/sda1 4.0G 174M 3.9G 5% /boot
tmpfs 182M 0 182M 0% /run/user/0
/dev/mapper/testvg-testlv 4.8G 20M 4.6G 1% /users
2) 扩展testlv至7G,要求archlinux用户的文件不能丢失
[root@localhost users]# lvextend -L 7G /dev/testvg/testlv ## 对testlv进行扩容
Size of logical volume testvg/testlv changed from 5.00 GiB (320 extents) to 7.00 GiB (448 extents).
Logical volume testvg/testlv successfully resized.
[root@localhost users]# resize2fs /dev/testvg/testlv ## 重设文件系统大小
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/testvg/testlv is mounted on /users; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 1
The filesystem on /dev/testvg/testlv is now 1835008 blocks long.
[root@localhost users]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 31G 3.5G 27G 12% /
devtmpfs 895M 0 895M 0% /dev
tmpfs 910M 0 910M 0% /dev/shm
tmpfs 910M 9.9M 900M 2% /run
tmpfs 910M 0 910M 0% /sys/fs/cgroup
/dev/sda5 20G 33M 20G 1% /home
/dev/sda3 31G 33M 31G 1% /data
/dev/sda1 4.0G 174M 3.9G 5% /boot
tmpfs 182M 0 182M 0% /run/user/0
/dev/mapper/testvg-testlv 6.8G 23M 6.4G 1% /users
3) 收缩testlv至3G,要求archlinux用户的文件不能丢失
[root@localhost users]# ll
total 32
-rw-r--r-- 1 root root 10 Apr 19 16:32 f1
-rw-r--r-- 1 root root 10 Apr 19 16:32 f2
-rw-r--r-- 1 root root 10 Apr 19 16:32 f3
-rw-r--r-- 1 root root 10 Apr 19 16:32 f4
drwx------ 2 root root 16384 Apr 19 16:27 lost+found
[root@localhost ~]# umount /users/
[root@localhost ~]# resize2fs /dev/testvg/testlv 3G ##重设文件系统大小为3G
resize2fs 1.42.9 (28-Dec-2013)
Please run 'e2fsck -f /dev/testvg/testlv' first.
[root@localhost ~]# e2fsck -f /dev/testvg/testlv
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: 15/458752 files (0.0% non-contiguous), 48643/1835008 blocks
[root@localhost ~]# 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@localhost ~]# lvreduce -L 3G /dev/testvg/testlv ##缩容testlv大小为3G
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@localhost ~]# mount /dev/testvg/testlv /users
[root@localhost ~]# cd /users/
[root@localhost users]# ls
f1 f2 f3 f4 lost+found
[root@localhost users]# ll
total 32
-rw-r--r-- 1 root root 11 Apr 19 16:40 f1
-rw-r--r-- 1 root root 11 Apr 19 16:40 f2
-rw-r--r-- 1 root root 11 Apr 19 16:40 f3
-rw-r--r-- 1 root root 11 Apr 19 16:40 f4
drwx------ 2 root root 16384 Apr 19 16:40 lost+found
4) 对testlv创建快照,并尝试基于快照备份数据,验证快照的功能
[root@localhost users]# lvcreate -n test_snap -s -p r -L 1G /dev/testvg/testlv
Logical volume "test_snap" created.
[root@localhost users]# lvdisplay
--- Logical volume ---
LV Path /dev/testvg/testlv
LV Name testlv
VG Name testvg
LV UUID fspf1Q-zHJO-BKPF-9KkF-e5lO-2Ow6-7lH3bS
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2019-04-19 16:24:48 +0800
LV snapshot status source of
test_snap [active]
LV Status available
# open 1
LV Size 3.00 GiB
Current LE 192
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0
--- Logical volume ---
LV Path /dev/testvg/test_snap
LV Name test_snap
VG Name testvg
LV UUID R4vQXO-p97c-7jQn-8OqE-36XB-Evir-GgpyZW
LV Write Access read only
LV Creation host, time localhost.localdomain, 2019-04-19 17:04:39 +0800
LV snapshot status active destination for testlv
LV Status available
# open 0
LV Size 3.00 GiB
Current LE 192
COW-table size 1.00 GiB
COW-table LE 64
Allocated to snapshot 0.01%
Snapshot chunk size 4.00 KiB
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:3
[root@localhost ~]# lvconvert --merge /dev/testvg/testsnap
Merging of volume testvg/testsnap started.
testvg/testlv1: Merged: 2.75%
testvg/testlv1: Merged: 100.00%
[root@localhost ~]# lvdisplay
--- Logical volume ---
LV Path /dev/testvg/testlv1
LV Name testlv1
VG Name testvg
LV UUID T08G8I-c2mH-Mn9Q-Cx9U-VmJC-lpb3-GErcoF
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2019-04-19 17:30:49 +0800
LV Status available
# open 0
LV Size 3.00 GiB
Current LE 192
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0
[root@localhost users]# ll
total 16
-rw-r--r-- 1 root root 0 Apr 19 17:31 f1
-rw-r--r-- 1 root root 0 Apr 19 17:31 f2
-rw-r--r-- 1 root root 0 Apr 19 17:31 f3
drwx------ 2 root root 16384 Apr 19 17:31 lost+found
2、创建一个可用空间为1G的RAID1设备,文件系统为ext4,有一个空闲盘,开机可自动挂载至/backup目录
sde 8:64 0 1G 0 disk
sdf 8:80 0 1G 0 disk
sdg 8:96 0 1G 0 disk
[root@localhost host2]# mdadm -C /dev/md1 -l 1 -x 1 -n 2 -a yes /dev/sd{e,f,g}
[root@localhost ~]# mdadm -D /dev/md1
/dev/md1:
Version : 1.2
Creation Time : Sun Apr 21 14:01:10 2019
Raid Level : raid1
Array Size : 1046528 (1022.00 MiB 1071.64 MB)
Used Dev Size : 1046528 (1022.00 MiB 1071.64 MB)
Raid Devices : 2
Total Devices : 3
Persistence : Superblock is persistent
Update Time : Sun Apr 21 14:01:13 2019
State : clean
Active Devices : 2
Working Devices : 3
Failed Devices : 0
Spare Devices : 1
Consistency Policy : resync
Name : localhost.localdomain:1 (local to host localhost.localdomain)
UUID : 450fea84:f4fe63b2:70ac46e8:bd97bb16
Events : 17
Number Major Minor RaidDevice State
0 8 64 0 active sync /dev/sde
1 8 80 1 active sync /dev/sdf
2 8 96 - spare /dev/sdg
[root@localhost ~]# mkfs.ext4 /dev/md1
[root@localhost ~]# mkdir /backup
[root@localhost ~]# mount /dev/md1 /backup
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 31G 3.5G 27G 12% /
devtmpfs 895M 0 895M 0% /dev
tmpfs 910M 0 910M 0% /dev/shm
tmpfs 910M 10M 900M 2% /run
tmpfs 910M 0 910M 0% /sys/fs/cgroup
/dev/sda5 20G 33M 20G 1% /home
/dev/sda3 31G 33M 31G 1% /data
/dev/sda1 4.0G 174M 3.9G 5% /boot
tmpfs 182M 0 182M 0% /run/user/0
/dev/md1 990M 2.6M 921M 1% /backup
[root@localhost ~]# vim /etc/fstab
#
# /etc/fstab
# Created by anaconda on Tue Apr 9 14:09:59 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=15abebbd-68e9-4264-943c-1c8e5217049f / xfs defaults 0 0
UUID=15d7df2b-47e7-4dcf-8bed-e6055e44611b /boot xfs defaults 0 0
UUID=13025e14-b617-464a-9ce9-dcf18873fcc0 /data xfs defaults 0 0
UUID=025f5c61-af4e-44d2-8906-4707e13c2402 /home xfs defaults 0 0
UUID=5adcb06a-020d-4c67-829d-8f0eda0794b8 /backup ext4 defaults 0 0
3、简述TCP链接建立和断开过程
TCP建立连接的过程称为三次握手
主机A向主机B发送一个含有同步序列号标志位的数据段给主机B,向主机B请求建立连接,通过这个数据段,主机A向主机B传达两个信息:请求和你通信、你可以用哪个序列号作为初始数据段来回应我
主机B收到主机A的请求后,用一个带有确认应答ACK和同步序列号SYN标志位的数据段来响应主机A,也传达给主机A两个信息:我已经收到了你的连接请求,你可以传输数据了、你要用那个序列号作为其实数据段来回应我
主机A收到这个数据段后,再发送一个确认应答,确认已收到主机B的数据段,表示:我已收到回复,我现在要开始传输实际数据了
这样TCP三次握手就完成了,主机AB可以传输数据了。
特点:没有应用层的数据,SYN这个标志位只有在TCP建立连接时才会被置为1,握手完成后SYN标志位被置为0
TCP断开连接时的过程称为四次挥手
主机A向主机B发送一个FIN,用来关闭A到B的数据传输,此时主机A进入FIND_WAIT_1状态
主机B收到FIN后,发送一个确认信号ACK给主机A,表示我已经收到你要断开连接的消息,主机B进入CLOSE_WAIT状态
主机B发送一个FIN,用来关闭主机B到主机A的数据传输,主机B进入LAST_ACK状态
主机A收到FIN后,进入TIME_WAIT状态,接着发送一个ACK给主机B表示收到主机A关闭数据传输的消息,此时主机B进入CLOSED状态
4、简述TCP和UDP的区别
- TCP是面向连接协议,即发送数据前要先建立连接。UDP是非面向连接协议,发送数据前不需要先建立连接
- TCP为流模式,UDP是数据报模式
- TCP能是安全可靠的连接,能够保证数据的可靠性和正确性。UDP不可靠,体现在数据有可能丢失,只负责把数据发出去