LVM逻辑卷以及配置NFS服务相关实验
实验要求
- 创建一个逻辑卷
请按下列要求创建一个新的逻辑卷:
创建一个名为 datastore 的卷组,卷组的大小为4G
逻辑卷的名字为 database ,所属卷组为 datastore,该逻辑卷大小为3G
将新建的逻辑卷格式化为 xfs 文件系统, - 通过自动挂载将该逻辑卷到/volume/lv1
- 扩大卷组扩展上题database逻辑卷的大小为5G。
- 配置nfs服务
将/home/tom(该目录为uid=1111,gid=1111的tom用户的家目录)目录仅共享给172.24.8.129这台主机上的jerry用户,jerry对该目录具有访问、新建和删除文件的权限。
创建逻辑卷
- 关闭虚拟机,点击编辑虚拟机设置,添加一块20G的NVMe类型的虚拟磁盘
[root@localhost ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sr0 11:0 1 10.2G 0 rom /mnt/cdrom nvme0n1 259:0 0 20G 0 disk ├─nvme0n1p1 259:1 0 1G 0 part /boot ├─nvme0n1p2 259:2 0 2G 0 part [SWAP] └─nvme0n1p3 259:3 0 16G 0 part / nvme0n2 259:4 0 20G 0 disk [root@localhost ~]# fdisk /dev/nvme0n2 //创建分区 Welcome to fdisk (util-linux 2.32.1). 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. Created a new DOS disklabel with disk identifier 0x352d50e4. Command (m for help): n //新建分区 Partition type p primary (0 primary, 0 extended, 4 free) e extended (container for logical partitions) Select (default p): p //主分区 Partition number (1-4, default 1): First sector (2048-41943039, default 2048): Last sector, +sectors or +size{K,M,G,T,P} (2048-41943039, default 41943039): +4G Created a new partition 1 of type 'Linux' and of size 4 GiB. Command (m for help): n Partition type p primary (1 primary, 0 extended, 3 free) e extended (container for logical partitions) Select (default p): p Partition number (2-4, default 2): First sector (8390656-41943039, default 8390656): Last sector, +sectors or +size{K,M,G,T,P} (8390656-41943039, default 41943039): +4G Created a new partition 2 of type 'Linux' and of size 4 GiB. Command (m for help): w The partition table has been altered. Calling ioctl() to re-read partition table. Syncing disks. [root@localhost ~]# pvcreate /dev/nvme0n2p{1,2} //创建物理卷 Physical volume "/dev/nvme0n2p1" successfully created. Physical volume "/dev/nvme0n2p2" successfully created. [root@localhost ~]# pvs //查看物理卷 PV VG Fmt Attr PSize PFree /dev/nvme0n2p1 lvm2 --- 4.00g 4.00g /dev/nvme0n2p2 lvm2 --- 4.00g 4.00g [root@localhost ~]# vgcreate datastore /dev/nvme0n2p1 //创建卷组 Volume group "datastore" successfully created [root@localhost ~]# lvcreate -n database -L 3G datastore //创建逻辑卷;-n:命名;-L:指定容量为3G Logical volume "database" created. [root@localhost ~]# mkfs.xfs /dev/datastore/database //格式化为xfs文件系统 meta-data=/dev/datastore/database isize=512 agcount=4, agsize=196608 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=1, sparse=1, rmapbt=0 = reflink=1 data = bsize=4096 blocks=786432, 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
通过自动挂载将该逻辑卷到/volume/lv1
1.通过yum命令安装autofsrpm包
[root@localhost /]# yum install autofs -y
2.配置挂载点父目录及子参数文件
[root@localhost /]# systemctl restart autofs.service [root@localhost /]# vim /etc/auto.master # 挂载点的主目录 映射配置文件 /volume /etc/auto.nfs
3.编辑映射配置文件
[root@localhost /]# vim /etc/auto.nfs #挂载目录名 -选项(权限等) 共享目录 lv1 -fstype=xfs,defaults :/dev/datastore/database
4.查看挂载
[root@localhost /]# mount /etc/auto.nfs on /volume type autofs (rw,relatime,fd=12,pgrp=27190,timeout=300,minproto=5,maxproto=5,indirect,pipe_ino=64583)
5.进入/volume/lv1进行检验
[root@localhost lv1]# systemctl restart autofs.service [root@localhost volume]# cd /volume/lv1/ [root@localhost lv1]# ll total 0 [root@localhost lv1]# cd lv1 [root@localhost lv1]#
扩大卷组扩展上题database逻辑卷的大小为5G。
[root@server ~]# vgextend datastore /dev/nvme0n2p2 //给卷组扩容 [root@server datastore]# lvextend -L +2G /dev/datastore/database //加两个G [root@server datastore]# xfs_growfs /dev/datastore/database //同步格式化 [root@server datastore]# df -h //查看
配置nfs服务
服务端
[root@localhost ~]# systemctl stop firewalld [root@localhost ~]# setenforce 0 [root@localhost ~]# systemctl restart nfs-server.service [root@server datastore]# useradd -u 1111 tom //创建用户tom [root@server tom]#vim /etc/exports //修改配置文件 /home/tom 192.168.133.150(rw,sync) [root@server tom]#exportfs -ra //重新加载文件 [root@server tom]#useradd -u 3333 jerry //创建用户jerry [root@server tom]#setfacl -m u:jerry:rwx /home/tom //赋予用户ACL权限
客户端
[root@localhost ~]#useradd -u 3333 jerry [root@localhost ~]#mkdir /t [root@localhost ~]#mount 192.168.233.131:/home/tom /t
测试
[root@localhost ~]# ll /t ls: cannot open directory '/t': Permission denied [root@localhost ~]# su jerry [jerry@localhost root]$ ll /t total 0