LVM逻辑卷以及配置NFS服务相关实验

简介: LVM逻辑卷以及配置NFS服务相关实验

LVM逻辑卷以及配置NFS服务相关实验

实验要求

  1. 创建一个逻辑卷
    请按下列要求创建一个新的逻辑卷:
    创建一个名为 datastore 的卷组,卷组的大小为4G
    逻辑卷的名字为 database ,所属卷组为 datastore,该逻辑卷大小为3G
    将新建的逻辑卷格式化为 xfs 文件系统,
  2. 通过自动挂载将该逻辑卷到/volume/lv1
  3. 扩大卷组扩展上题database逻辑卷的大小为5G。
  4. 配置nfs服务
    将/home/tom(该目录为uid=1111,gid=1111的tom用户的家目录)目录仅共享给172.24.8.129这台主机上的jerry用户,jerry对该目录具有访问、新建和删除文件的权限。

创建逻辑卷

  1. 关闭虚拟机,点击编辑虚拟机设置,添加一块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


相关文章
|
2月前
|
运维 Ubuntu 安全
在Linux中,如何配置NFS共享?
在Linux中,如何配置NFS共享?
|
2月前
|
存储 Ubuntu Linux
NFS服务部署全攻略:从零到一,轻松驾驭网络文件系统,让你的文件共享像飞一样畅快无阻!
【8月更文挑战第5天】NFS(网络文件系统)能让网络中的电脑无缝共享文件与目录。基于客户端-服务器模式,用户可像访问本地文件般透明操作远程文件。部署前需准备至少两台Linux机器:一台服务器,其余作客户端;确保已装NFS相关软件包且网络通畅。服务器端安装NFS服务与rpcbind,客户端安装nfs-utils。
61 4
|
2月前
|
Ubuntu Linux 网络安全
在Linux中,如何配置Samba或NFS文件共享?
在Linux中,如何配置Samba或NFS文件共享?
|
3月前
|
存储 算法框架/工具
Ceph提供nfs服务
Ceph提供nfs服务
45 6
|
2月前
|
Kubernetes 关系型数据库 MySQL
k8s练习--通过NFS+PV+PVC+POD,部署一个MySQL服务,并将MySQL的数据进行持久化存储
本文档介绍了如何使用Kubernetes (K8s)、NFS、PersistentVolume (PV)、PersistentVolumeClaim (PVC)和Pod来部署并实现MySQL服务的数据持久化存储。Kubernetes是一个用于自动化部署、扩展和管理容器化应用的强大平台。NFS作为一种网络文件系统协议,能够使Kubernetes集群中的Pod跨节点访问共享文件。PV和PVC机制则提供了持久化的存储解决方案,确保数据即使在Pod生命周期结束后仍得以保留。
|
4月前
|
Ubuntu
ubuntu搭建NFS服务 磁盘共享 nfs 搭建
ubuntu搭建NFS服务 磁盘共享 nfs 搭建
148 2
|
5月前
|
存储 网络协议 Linux
NFS(Network File System 网络文件服务)
NFS(Network File System 网络文件服务)
|
5月前
|
存储 Kubernetes 数据安全/隐私保护
|
5月前
|
存储 Kubernetes 应用服务中间件
k8s-配置与存储-持久化存储-NFS 挂载、StorageClass 存储类 动态创建NFS-PV案例
k8s-配置与存储-持久化存储-NFS 挂载、StorageClass 存储类 动态创建NFS-PV案例
471 0
|
5月前
|
Unix Linux Shell
linux 配置NFS
NFS(Network File System)是跨平台的网络文件系统,允许不同操作系统和硬件通过RPC协议共享文件系统。服务端启动RPC服务和NFS,注册端口信息。客户端请求服务器的NFS端口,建立连接进行数据传输。优点包括配置简单、数据可靠、支持多系统间文件共享。缺点包括端口不固定、数据明文传输、安全性较低(基于IP认证)。在Redhat 9环境下,通过安装nfs-utils和rpcbind,配置共享目录和exports文件,设置权限,客户端安装相同软件包,使用showmount命令查看共享,挂载NFS目录,实现透明访问。
105 1