lv创建并配置成nfs服务

环境:centos7

1、准备挂载盘 (创建pv-vg-lv)

[root@node3 ~]# pvcreate /dev/sdb
  Physical volume "/dev/sdb" successfully created.
[root@node3 ~]# pvs
  PV         VG Fmt  Attr PSize   PFree
  /dev/sda2  cl lvm2 a--  929.39g 4.00m
  /dev/sdb      lvm2 ---    1.82t 1.82t
[root@node3 ~]# vgcreate nfs-data /dev/sdb
  Volume group "nfs-data" successfully created
[root@node3 ~]# vgs
  VG       #PV #LV #SN Attr   VSize   VFree
  cl         1   3   0 wz--n- 929.39g 4.00m
  nfs-data   1   0   0 wz--n-   1.82t 1.82t
[root@node3 ~]# lvcreate -l 100%VG -n lv-nfs-data nfs-data
  Logical volume "lv-nfs-data" created.
[root@node3 ~]# lvs
  LV          VG       Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  home        cl       -wi-ao---- 847.95g                                                    
  root        cl       -wi-ao----  50.00g                                                    
  swap        cl       -wi-ao----  31.44g                                                    
  lv-nfs-data nfs-data -wi-a-----   1.82t  
#格式化
[root@node3 ~]# mkfs.xfs /dev/mapper/nfs--data-lv--nfs--data
meta-data=/dev/mapper/nfs--data-lv--nfs--data isize=512    agcount=4, agsize=122009088 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=488036352, imaxpct=5
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=238299, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
#挂载
[root@node3 ~]# mkdir /nfs-data
[root@node3 ~]# blkid|grep nfs--data
/dev/mapper/nfs--data-lv--nfs--data: UUID="646a7aed-5467-437f-8db9-d646e77eaab4" TYPE="xfs"
[root@node3 ~]# cat /etc/fstab |grep nfs
UUID=646a7aed-5467-437f-8db9-d646e77eaab4 /nfs-data                  xfs     defaults        0 0
[root@node3 ~]# mount -a
[root@node3 ~]# df -h|grep nfs
/dev/mapper/nfs--data-lv--nfs--data  1.9T   33M  1.9T   1% /nfs-data

2、nfs  server端安装

yum -y install nfs-utils rpcbind
#centos7自带了rpcbind,rpc监听在111端口。
配置
#创建配置文件
vim /etc/exports
[root@node4 ~]# cat /etc/exports
/nfs-data *(rw,no_root_squash,async,fsid=0)
#/nfs-data 为共享目录
#再次修改后,执行exportfs –rv让配置立即生效

启动server端
#启动顺序一定是rpcbind->nfs
# systemctl start rpcbind.service
# systemctl enable rpcbind.service
# systemctl start nfs.service
# systemctl enable nfs.service

3、client安装

yum install -y nfs-utils rpcbind
# 此处nfs-utils 只安装不启动,方便执行查看命令。
启动
systemctl start rpcbind
systemctl enable rpcbind

挂载
1,直接挂载
#  mount -t nfs 100.98.100.244:/nfs-data /nfs-data
也可将挂载配置写入fstab文件中,与普通磁盘挂载一样,挂载时同样可以指定权限,只是类型为nfs。
2,autofs挂载(它会持续的检测某个指定的目录,并进行自动挂载的操作)
# yum -y install autofs
# vi /etc/auto.master
#添加一行
/-    /etc/auto.mount
# vi /etc/auto.mount
#添加一行
/nfs-data -fstype=nfs,rw  100.98.100.244:/nfs-data

#启动服务
# systemctl start autofs 
# systemctl enable autofs

  

  

posted @ 2021-04-25 15:03  苍茫宇宙  阅读(164)  评论(0编辑  收藏  举报