1、磁盘lvm管理,完成下面要求,并写出详细过程:
- 创建一个至少有两个PV组成的大小为20G的名为testvg的VG;要求PE大小 为16MB, 而后在卷组中创建大小为5G的逻辑卷testlv;挂载至/users目录
格式成LVM分区:
[root@localhost ~]#fdisk /dev/sdb
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-13054, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-13054, default 13054): +10G
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (1307-13054, default 1307):
Using default value 1307
Last cylinder, +cylinders or +size{K,M,G} (1307-13054, default 13054): +10G
Command (m for help): p
Device Boot Start End Blocks Id System
/dev/sdb1 1 1306 10490413+ 83 Linux
/dev/sdb2 1307 2612 10490445 83 Linux
Command (m for help): t
Partition number (1-4): 1
Hex code (type L to list codes): L
0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris
1 FAT12 39 Plan 9 82 Linux swap / So c1 DRDOS/sec (FAT-
2 XENIX root 3c PartitionMagic 83 Linux c4 DRDOS/sec (FAT-
3 XENIX usr 40 Venix 80286 84 OS/2 hidden C: c6 DRDOS/sec (FAT-
4 FAT16 <32M 41 PPC PReP Boot 85 Linux extended c7 Syrinx
5 Extended 42 SFS 86 NTFS volume set da Non-FS data
6 FAT16 4d QNX4.x 87 NTFS volume set db CP/M / CTOS / .
7 HPFS/NTFS 4e QNX4.x 2nd part 88 Linux plaintext de Dell Utility
8 AIX 4f QNX4.x 3rd part 8e Linux LVM df BootIt
9 AIX bootable 50 OnTrack DM 93 Amoeba e1 DOS access
a OS/2 Boot Manag 51 OnTrack DM6 Aux 94 Amoeba BBT e3 DOS R/O
b W95 FAT32 52 CP/M 9f BSD/OS e4 SpeedStor
c W95 FAT32 (LBA) 53 OnTrack DM6 Aux a0 IBM Thinkpad hi eb BeOS fs
e W95 FAT16 (LBA) 54 OnTrackDM6 a5 FreeBSD ee GPT
f W95 Ext'd (LBA) 55 EZ-Drive a6 OpenBSD ef EFI (FAT-12/16/
10 OPUS 56 Golden Bow a7 NeXTSTEP f0 Linux/PA-RISC b
11 Hidden FAT12 5c Priam Edisk a8 Darwin UFS f1 SpeedStor
12 Compaq diagnost 61 SpeedStor a9 NetBSD f4 SpeedStor
14 Hidden FAT16 <3 63 GNU HURD or Sys ab Darwin boot f2 DOS secondary
16 Hidden FAT16 64 Novell Netware af HFS / HFS+ fb VMware VMFS
17 Hidden HPFS/NTF 65 Novell Netware b7 BSDI fs fc VMware VMKCORE
18 AST SmartSleep 70 DiskSecure Mult b8 BSDI swap fd Linux raid auto
1b Hidden W95 FAT3 75 PC/IX bb Boot Wizard hid fe LANstep
1c Hidden W95 FAT3 80 Old Minix be Solaris boot ff BBT
1e Hidden W95 FAT1
Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM)
Command (m for help): t
Partition number (1-4): 2
Hex code (type L to list codes): 8e
Changed system type of partition 2 to 8e (Linux LVM)
Command (m for help): p
Device Boot Start End Blocks Id System
/dev/sdb1 1 1306 10490413+ 8e Linux LVM
/dev/sdb2 1307 2612 10490445 8e Linux LVM
Expert command (m for help): w
[root@localhost ~]#partx -a /dev/sdb :同步硬盘信息
BLKPG: Device or resource busy
error adding partition 1
BLKPG: Device or resource busy
error adding partition 2
准备好了实验空间:
[root@localhost ~]#lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sr0 11:0 1 3.7G 0 rom /media/CentOS_6.10_Final_
sr1 11:1 1 2G 0 rom /media/CentOS_6.10_Final
sda 8:0 0 200G 0 disk
├─sda1 8:1 0 1G 0 part /boot
├─sda2 8:2 0 100G 0 part /
├─sda3 8:3 0 50G 0 part /app
├─sda4 8:4 0 1K 0 part
└─sda5 8:5 0 2G 0 part [SWAP]
sdb 8:16 0 100G 0 disk
├─sdb1 8:17 0 10G 0 part
└─sdb2 8:18 0 10G 0 part
[root@localhost ~]#
创建pv卷:
[root@localhost ~]#pvcreate /dev/sdb{1,2}
Physical volume "/dev/sdb1" successfully created
Physical volume "/dev/sdb2" successfully created
创建vg组:
[root@localhost ~]#vgcreate -s 16M testvg /dev/sdb{1,2} :PE大小为16MB
Volume group "testvg" successfully created
[root@localhost ~]#vgdisplay testvg
--- 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 20.00 GiB
PE Size 16.00 MiB
Total PE 1280
Alloc PE / Size 0 / 0
Free PE / Size 1280 / 20.00 GiB
VG UUID BSoTiQ-UdaW-KKxP-PQcC-ddoY-rVn6-UMbUDF
创建lv卷:
[root@localhost ~]#lvcreate -L 5G -n testlv /dev/testvg
Logical volume "testlv" created.
[root@localhost ~]#lvdisplay /dev/testvg/testlv
--- Logical volume ---
LV Path /dev/testvg/testlv
LV Name testlv
VG Name testvg
LV UUID g3C2fF-mZ4O-q6wn-1jaK-t8TY-wfcP-HDkxMr
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2019-05-31 12:14:41 +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 256
Block device 253:0
挂载至/users目录:
[root@localhost ~]#mkfs.ext4 /dev/testvg/testlv :格式化为ext4文件系统类型
[root@localhost ~]#blkid /dev/testvg/testlv :查看是否分配了UUID
/dev/testvg/testlv: UUID="6d65db30-9b69-41ed-bbc6-523272c1afc7" TYPE="ext4"
[root@localhost ~]# mkdir users :创建目录
[root@localhost ~]# mount /dev/testvg/testlv /users/ :挂载至/users目录
[root@localhost ~]#df -h | grep "/users" :查看分区情况和大小
/dev/mapper/testvg-testlv 4.8G 10M 4.6G 1% /users
- 扩展testlv至7G,要求archlinux用户的文件不能丢失
[root@localhost ~]# useradd archlinux -d /users/archlinux :创建用户并指定其家目录
[root@localhost ~]# su - archlinux :切换用户
[archlinux@localhost ~]$ cp -av /etc/pam.d /users/archlinux :复制文件
[archlinux@localhost ~]$ ls /users/archlinux/pam.d/ | wc -l :查看文件个数
57
[root@localhost ~]#vgs
VG #PV #LV #SN Attr VSize VFree
testvg 2 1 0 wz--n- 20.00g 15.00g :还剩15G空间,足够使用
[root@localhost ~]#lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
testlv testvg -wi-ao---- 5.00g
[root@localhost ~]#lvextend -L +2G -r /dev/testvg/testlv :原有5G加2G扩充至7G
Size of logical volume testvg/testlv changed from 5.00 GiB (320 extents) to 7.00 GiB (448 extents).
Logical volume testlv successfully resized.
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/mapper/testvg-testlv is mounted on /users; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 1
Performing an on-line resize of /dev/mapper/testvg-testlv to 1835008 (4k) blocks.
The filesystem on /dev/mapper/testvg-testlv is now 1835008 blocks long.
[root@localhost ~]#lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
testlv testvg -wi-ao---- 7.00g :扩充成功
[root@localhost ~]#df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 99G 3.6G 90G 4% /
tmpfs 931M 76K 931M 1% /dev/shm
/dev/sda3 50G 52M 47G 1% /app
/dev/sda1 976M 39M 887M 5% /boot
/dev/sr1 2.1G 2.1G 0 100% /media/CentOS_6.10_Final
/dev/sr0 3.8G 3.8G 0 100% /media/CentOS_6.10_Final_
/dev/mapper/testvg-testlv
6.8G 12M 6.5G 1% /users :原来4.8,现在6.8扩充成功
[root@localhost ~]#ls /users/archlinux/pam.d/|wc -l :查看文件数有没有丢失
57
- 收缩testlv至3G,要求archlinux用户的文件不能丢失
[root@localhost ~]#umount /dev/testvg/testlv :必须先卸载
[root@localhost ~]#e2fsck -fy /dev/testvg/testlv :检查文件系统
e2fsck 1.41.12 (17-May-2010)
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: 78/458752 files (0.0% non-contiguous), 64509/1835008 blocks
[root@localhost ~]#resize2fs /dev/testvg/testlv 3G :设置文件系统大小
resize2fs 1.41.12 (17-May-2010)
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 :缩减逻辑卷为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 testlv successfully resized.
[root@localhost ~]#lvs :查看逻辑卷大小
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
testlv testvg -wi-a----- 3.00g
[root@localhost ~]#mount /dev/testvg/testlv /users :挂载
[root@localhost ~]#df -h :查看物理卷为2.9有一点误差正常
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 99G 3.6G 90G 4% /
tmpfs 931M 76K 931M 1% /dev/shm
/dev/sda3 50G 52M 47G 1% /app
/dev/sda1 976M 39M 887M 5% /boot
/dev/sr1 2.1G 2.1G 0 100% /media/CentOS_6.10_Final
/dev/sr0 3.8G 3.8G 0 100% /media/CentOS_6.10_Final_
/dev/mapper/testvg-testlv
2.9G 7.8M 2.7G 1% /users
[root@localhost ~]#ls /users/archlinux/pam.d/ | wc -l :查看文件数是否丢失
57
- 对testlv创建快照,并尝试基于快照备份数据,验证快照的功能
[root@localhost ~]#lvcreate -L 1G -s -n testanap -p r /dev/testvg/testlv :用lvcreate创建快照 -n指定快照名 -s表示为快照 -p r 为只读属性 -L 指定快照大小 /dev/testvg/testlv为源逻辑卷
Logical volume "testanap" created.
[root@localhost ~]#lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
testanap testvg sri-a-s--- 1.00g testlv 0.00
testlv testvg owi-aos--- 3.00g
[root@localhost ~]#mkdir /users/testsnap
[root@localhost ~]#mount /dev/testvg/testanap /users/testsnap/
mount: block device /dev/mapper/testvg-testanap is write-protected, mounting read-only
[root@localhost ~]#rm -f /users/archlinux/pam.d/a* :删掉一些数据
[root@localhost ~]#ls /users/archlinux/pam.d/|wc -l
51
[root@localhost ~]#ls /users/testsnap/archlinux/pam.d/|wc -l :快照的数据
57
[root@localhost ~]#umount /users/testsnap/:先卸载,再用快照还原
[root@localhost ~]#umount /users/
[root@localhost ~]#lvconvert --merge /dev/testvg/testanap :将快照进行还原
Merging of volume testanap started.
testlv: Merged: 100.0%
Merge of snapshot into logical volume testlv has finished.
Logical volume "testanap" successfully removed
[root@localhost ~]#mount /dev/testvg/testlv /users
[root@localhost ~]#ls /users/archlinux/pam.d/|wc -l :快照还原成功
57
[root@localhost ~]#
2、创建一个可用空间为1G的RAID1设备,文件系统为ext4,有一个空闲盘,开机可自动挂载至/backup目录
[root@localhost ~]#lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sr0 11:0 1 3.7G 0 rom /media/CentOS_6.10_Final_
sr1 11:1 1 2G 0 rom /media/CentOS_6.10_Final
sdb 8:16 0 100G 0 disk
├─sdb1 8:17 0 10G 0 part
│ └─testvg-testlv (dm-0) 253:0 0 3G 0 lvm
└─sdb2 8:18 0 10G 0 part
sdc 8:32 0 50G 0 disk
sda 8:0 0 200G 0 disk
├─sda1 8:1 0 1G 0 part /boot
├─sda2 8:2 0 100G 0 part /
├─sda3 8:3 0 50G 0 part /app
├─sda4 8:4 0 1K 0 part
└─sda5 8:5 0 2G 0 part [SWAP]
sdd 8:48 0 50G 0 disk
[root@localhost ~]#mdadm -C -a yes /dev/md0 -l 1 -n 2 /dev/sd{c,d} :创建RAID1mdadm -C 创建 -a yes 初始化设备 /dev/md0设备 -l raid级别 -n 几个成员 /dev/sd{c,d}raid成员
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? yes
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.
[root@localhost ~]#lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sr0 11:0 1 3.7G 0 rom /media/CentOS_6.10_Final_
sr1 11:1 1 2G 0 rom /media/CentOS_6.10_Final
sdb 8:16 0 100G 0 disk
├─sdb1 8:17 0 10G 0 part
│ └─testvg-testlv (dm-0) 253:0 0 3G 0 lvm
└─sdb2 8:18 0 10G 0 part
sdc 8:32 0 50G 0 disk
└─md0 9:0 0 50G 0 raid1
sda 8:0 0 200G 0 disk
├─sda1 8:1 0 1G 0 part /boot
├─sda2 8:2 0 100G 0 part /
├─sda3 8:3 0 50G 0 part /app
├─sda4 8:4 0 1K 0 part
└─sda5 8:5 0 2G 0 part [SWAP]
sdd 8:48 0 50G 0 disk
└─md0 9:0 0 50G 0 raid1
[root@localhost ~]#mkfs.ext4 /dev/md0 :文件系统ext4
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
3276800 inodes, 13099008 blocks
654950 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
400 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
perblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 26 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@localhost ~]#vim /etc/fstab :末行模式:r!blkid /dev/md0 得到UUID
UUID下加一行,实现自动挂载
UUID="72ee9911-c031-4ee5-a910-1caf1c44caaa" /backup ext4 defaults 0 0
~
"/etc/fstab" 18L, 1089C written
[root@localhost ~]#
3、简述TCP链接建立和断开过程
TCP协议的链接特性:
常见状态:
LISTEN:监听;
ESTABLISHED:建立的连接;
FIN_WAIT_1:发送断开后等待断开确认;
FIN_WAIT_2:收到断开后确认断开;
SYN_SENT:确认收到断开信号;
SYN_RECV:确认;
建立连接:三次握手;
tcp建立连接时,在两个方向上要分别建立虚链路,一个是客户端发SYN=1,seq=x,服务器端收,另一个是服务器端发SYN=1,ACK=1,seq=y,ack=x+1,客户端收并发出确认信息ACK=1,seq=x+1,ack=y+1;所以第一次握手,是客户端发请求与服务端通信,第二次是服务器端响应并请求与客户端通信,第三次是客户端响应,所以是三次握手建立连接;接下来就是建立连接双方通信;
断开连接:四次挥手;
断开链接时,一般是发起请求的一方即客户端发起断开请求,断开分为4次,第一次是客户端请求断开发送FIN=1,seq=u,第二次服务端响应客户端并发出确认收到报文ACK=1,seq=v,ack=u+1,第三次是服务器传送中的数据全部完成后发送断开连接信息FIN=1,ACK=1,seq=w,ack=u+1,第四次是客户端响应服务端ACK=1,seq=u+1,ack=w+1;因此断开时,第一次是客户端请求断开自己的链接,并等待对方响应,而第三次是服务端请求断开自己的链接,并等待对方响应的过程;
4、简述TCP和UDP的区别
tcp:面向连接的协议;通信开始之前,要建立一个虚链路;通信完成后还要拆除连接;
udp:无连接的协议;直接发送数据报文(不管对方能不能接收到,竭尽全力的发);