目录
一.创建一个逻辑卷
(1)先添加一个新磁盘10G如图
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 19G 0 part
├─rhel-root 253:0 0 17G 0 lvm /
└─rhel-swap 253:1 0 2G 0 lvm [SWAP]
sdb 8:16 0 10G 0 disk
(2)将新磁盘分成两个5G的分区
[root@localhost ~]# fdisk -l /dev/sdb
Disk /dev/sdb: 10 GiB, 10737418240 bytes, 20971520 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
Disklabel type: dos
Disk identifier: 0x9579e442
Device Boot Start End Sectors Size Id Type
/dev/sdb1 2048 10487807 10485760 5G 83 Linux
/dev/sdb2 10487808 20971519 10483712 5G 83 Linux
(3)把两个分区创建成两个物理卷
[root@localhost ~]# pvcreate /dev/sdb{1,2}
Physical volume "/dev/sdb1" successfully created.
Physical volume "/dev/sdb2" successfully created.
(4)创建一个名为 datastore 的卷组,卷组的大小为4G
[root@localhost ~]# vgcreate datastore -s 4G /dev/sdb1
Volume group "datastore" successfully created
[root@localhost ~]# vgs
VG #PV #LV #SN Attr VSize VFree
datastore 1 0 0 wz--n- 4.00g 4.00g
rhel 1 2 0 wz--n- <19.00g 0
(5)创建逻辑卷的名字为 database ,所属卷组为 datastore,该逻辑卷大小为3G
[root@localhost ~]# lvcreate -n database -L 3G datastore
Rounding up size to full physical extent 4.00 GiB
Logical volume "database" created.
sdb 8:16 0 10G 0 disk
├─sdb1 8:17 0 5G 0 part
│ └─datastore-database 253:2 0 4G 0 lvm
└─sdb2 8:18 0 5G 0 part
(6)将新建的逻辑卷格式化为 xfs 文件系统
[root@localhost ~]# mkfs.xfs /dev/datastore/database
二.通过自动挂载将该逻辑卷到/volume/lv1
(1)配置挂载点主目录及子参数文件
/volume/lv1 /etc/auto.nfs
(2)在子参数文件中配置
lv1 :/dev/datastore/database
(3)mount查看挂载
/etc/auto.nfs on /volume/lv1 type autofs (rw,relatime,fd=12,pgrp=36298,timeout=300,minproto=5,maxproto=5,indirect,pipe_ino=101127)
(4)进入volume/lv1进行操作
[root@localhost ~]# cd /volume/lv1/
[root@localhost lv1]# ll
total 0
[root@localhost lv1]#
三.扩大卷组扩展上题database逻辑卷的大小为5G。
(1)把datastore卷组扩大
[root@localhost ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 rhel lvm2 a-- <19.00g 0
/dev/sdb1 datastore lvm2 a-- 4.00g 0
/dev/sdb2 lvm2 --- <5.00g <5.00g
[root@localhost ~]# vgextend datastore /dev/sdb2
Volume group "datastore" successfully extended
[root@localhost ~]# vgs
VG #PV #LV #SN Attr VSize VFree
datastore 2 1 0 wz--n- 8.00g 0
rhel 1 2 0 wz--n- <19.00g 0
(2)把database逻辑卷的大小改为5G。
[root@localhost ~]# lvreduce -L 5G /dev/datastore/database
四.配置nfs服务
服务端配置
(1)关闭防火墙
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0
(2)启动nfs和rpc服务
[root@localhost ~]# systemctl restart nfs-server.service
(3)修改配置文件
[root@localhost ~]# vim /etc/exports
/home/tom 192.168.87.133(rw,sync)
(4)创建用户tom
[root@localhost ~]# useradd -u 1111 tom
[root@localhost ~]# ll /home/tom/
total 0
[root@localhost ~]# touch /home/tom/t1
(5)创建用户jerry并给它赋予权限
[root@localhost ~]# useradd -u 3333 jerry
[root@localhost ~]# setfacl -m u:jerry:rwx /home/tom/
(6)重启nfs
[root@localhost ~]# exportfs -ra
客户端配置
(1)创建用户jerry
[root@localhost ~]# useradd -u 3333 jerry
(2)进行挂载
[root@localhost ~]# mkdir /z
[root@localhost ~]# mount 192.168.87.128:/home/tom /z
(3)测试只有jerry有权限
[root@localhost ~]# ll /z
ls: cannot open directory '/z': Permission denied
[root@localhost ~]# su jerry
[jerry@localhost root]$ ll /z
total 0