1、磁盘lvm管理,完成下面要求,并写出详细过程:
创建一个至少有两个PV组成的大小为20G的名为testvg的VG;要求PE大小 为16MB, 而后在卷组中创建大小为5G的逻辑卷testlv;挂载至/users目录
格式成LVM分区:
[root@localhost ~]# pvcreate /dev/sd{b,c}
[root@localhost ~]# vgcreate -s 16M testvg /dev/sd{b,c}
[root@localhost ~]# lvcreate -L 5G -n testlv testvg
[root@localhost ~]# mkdir /users
[root@localhost ~]# mkfs.ext4 /dev/testvg/testlv
[root@localhost ~]# mount /dev/testvg/testlv /users
准备好了实验空间:
[root@localhost ~]#lsblkNAMEMAJ:MIN RM SIZE RO TYPE MOUNTPOINTsr011:013.7G0rom /media/CentOS_6.10_Final_sr111:112G0rom /media/CentOS_6.10_Finalsda8:00200G0disk ├─sda18:101G0part /boot├─sda28:20100G0part /├─sda38:3050G0part /app├─sda48:401K0part └─sda58:502G0part [SWAP]sdb8:160100G0disk ├─sdb18:17010G0part └─sdb28:18010G0part [root@localhost ~]#
创建pv卷:
[root@localhost ~]#pvcreate /dev/sdb{1,2}Physical volume"/dev/sdb1"successfully createdPhysical volume"/dev/sdb2"successfully created
创建vg组:
[root@localhost ~]#vgcreate -s 16M testvg /dev/sdb{1,2} :PE大小为16MBVolume group"testvg"successfully created
[root@localhost ~]#vgdisplay testvg--- Volume group ---VG Name testvgSystem ID Format lvm2Metadata Areas2Metadata Sequence No1VG Access read/writeVG Status resizableMAX LV0Cur LV0Open LV0Max PV0Cur PV2Act PV2VG Size20.00GiBPE Size16.00MiBTotal PE1280Alloc PE / Size0/0Free PE / Size1280/20.00GiBVG UUID BSoTiQ-UdaW-KKxP-PQcC-ddoY-rVn6-UMbUDF
创建lv卷:
[root@localhost ~]#lvcreate -L 5G -n testlv /dev/testvgLogical volume"testlv"created.
[root@localhost ~]#lvdisplay /dev/testvg/testlv--- Logical volume ---LV Path /dev/testvg/testlvLV Name testlvVG Name testvgLV UUID g3C2fF-mZ4O-q6wn-1jaK-t8TY-wfcP-HDkxMrLV Write Accessread/writeLV Creation host, time localhost.localdomain, 2019-05-31 12:14:41 +0800LV Status available# open 0LV Size 5.00 GiBCurrent LE 320Segments 1Allocation inheritRead ahead sectors auto- currentlysetto 256Block 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-testlv4.8G10M4.6G1% /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 ~]#vgsVG#PV #LV #SN Attr VSize VFree testvg210wz--n-20.00g15.00g :还剩15G空间,足够使用
[root@localhost ~]#lvsLV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Converttestlv testvg -wi-ao----5.00g [root@localhost ~]#lvextend -L +2G -r /dev/testvg/testlv :原有5G加2G扩充至7GSize of logical volume testvg/testlv changedfrom5.00GiB (320extents) to7.00GiB (448extents).Logical volume testlv successfully resized.resize2fs1.41.12(17-May-2010)Filesystem at /dev/mapper/testvg-testlvismounted on /users; on-line resizing requiredold desc_blocks =1, new_desc_blocks =1Performing an on-line resize of /dev/mapper/testvg-testlv to1835008(4k) blocks.The filesystem on /dev/mapper/testvg-testlvisnow1835008blocks long.
[root@localhost ~]#lvsLV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Converttestlv testvg -wi-ao----7.00g :扩充成功
[root@localhost ~]#df -h Filesystem Size Used Avail Use% Mounted on/dev/sda299G3.6G90G4% /tmpfs931M76K931M1% /dev/shm/dev/sda350G52M47G1% /app/dev/sda1976M39M887M5% /boot/dev/sr12.1G2.1G0100% /media/CentOS_6.10_Final/dev/sr03.8G3.8G0100% /media/CentOS_6.10_Final_/dev/mapper/testvg-testlv6.8G12M6.5G1% /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 :检查文件系统e2fsck1.41.12(17-May-2010)Pass1: Checking inodes, blocks,andsizesPass2: Checking directory structurePass3: Checking directory connectivityPass4: Checking reference countsPass5: Checking group summary information/dev/testvg/testlv:78/458752files (0.0% non-contiguous),64509/1835008blocks
[root@localhost ~]#resize2fs /dev/testvg/testlv 3G :设置文件系统大小resize2fs1.41.12(17-May-2010)Resizing the filesystem on /dev/testvg/testlv to786432(4k) blocks.The filesystem on /dev/testvg/testlv is now786432blocks long.
[root@localhost ~]#lvreduce -L 3G /dev/testvg/testlv :缩减逻辑卷为3GWARNING: Reducing active logical volume to3.00GiB.THIS MAY DESTROY YOUR DATA (filesystem etc.)Doyou really want to reduce testvg/testlv? [y/n]: ySize of logical volume testvg/testlv changed from7.00GiB (448extents) to3.00GiB (192extents).Logical volume testlv successfully resized.
[root@localhost ~]#lvs :查看逻辑卷大小LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Converttestlv testvg -wi-a-----3.00g
[root@localhost ~]#mount /dev/testvg/testlv /users :挂载
[root@localhost ~]#df -h :查看物理卷为2.9有一点误差正常Filesystem Size Used AvailUse%Mountedon/dev/sda299G3.6G90G4% /tmpfs931M76K931M1% /dev/shm/dev/sda350G52M47G1% /app/dev/sda1976M39M887M5% /boot/dev/sr12.1G2.1G0 100% /media/CentOS_6.10_Final/dev/sr03.8G3.8G0 100% /media/CentOS_6.10_Final_/dev/mapper/testvg-testlv2.9G7.8M2.7G1% /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 ~]#lvsLV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Converttestanap testvg sri-a-s---1.00g testlv0.00testlv 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 -l51
[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 ~]#lsblkNAMEMAJ:MIN RM SIZE RO TYPE MOUNTPOINTsr011:013.7G0rom /media/CentOS_6.10_Final_sr111:112G0rom /media/CentOS_6.10_Finalsdb8:160100G0disk ├─sdb18:17010G0part │ └─testvg-testlv (dm-0)253:003G0lvm └─sdb28:18010G0part sdc8:32050G0disk sda8:00200G0disk ├─sda18:101G0part /boot├─sda28:20100G0part /├─sda38:3050G0part /app├─sda48:401K0part └─sda58:502G0part [SWAP]sdd8:48050G0disk
[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 startandmaynotbe suitable as a boot device. If you plan to store'/boot'on this device pleaseensurethat your boot-loader understands md/v1.x metadata,oruse --metadata=0.90Continue creating array? yesmdadm:Defaulting to version1.2metadatamdadm:array /dev/md0started.
[root@localhost ~]#lsblkNAMEMAJ:MIN RM SIZE RO TYPE MOUNTPOINTsr011:013.7G0rom /media/CentOS_6.10_Final_sr111:112G0rom /media/CentOS_6.10_Finalsdb8:160100G0disk ├─sdb18:17010G0part │ └─testvg-testlv (dm-0)253:003G0lvm └─sdb28:18010G0part sdc8:32050G0disk └─md09:0050G0raid1 sda8:00200G0disk ├─sda18:101G0part /boot├─sda28:20100G0part /├─sda38:3050G0part /app├─sda48:401K0part └─sda58:502G0part [SWAP]sdd8:48050G0disk └─md09:0050G0raid1 [root@localhost ~]#mkfs.ext4 /dev/md0 :文件系统ext4mke2fs1.41.12(17-May-2010)Filesystem label=OStype:LinuxBlock size=4096(log=2)Fragment size=4096(log=2)Stride=0blocks, Stripe width=0blocks3276800inodes,13099008blocks654950blocks (5.00%) reservedforthesuperuserFirst data block=0Maximum filesystem blocks=4294967296400block groups32768blocks per group,32768fragments per group8192inodes per groupperblock backups stored onblocks:32768,98304,163840,229376,294912,819200,884736,1605632,2654208,4096000,7962624,11239424Writing inodetables:done Creating journal (32768blocks): doneWriting superblocksandfilesystem accountinginformation:doneThis filesystem will be automatically checked every26mountsor180days, whichever comes first. Use tune2fs -cor-i to override.[root@localhost ~]#vim /etc/fstab :末行模式:r!blkid /dev/md0 得到UUID UUID下加一行,实现自动挂载UUID="72ee9911-c031-4ee5-a910-1caf1c44caaa"/backup ext4 defaults00~"/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:无连接的协议;直接发送数据报文(不管对方能不能接收到,竭尽全力的发)