1.逻辑卷技术
LVM(Logical Volume Manager,逻辑卷管理器)最早应用在IBM AIX系统上。它的主要作用是动态分配磁盘分区及调整磁盘分区大小,并且可以让多个分区或者物理硬盘作为一个逻辑卷(相当于一个逻辑硬盘)来使用。这种机制可以让磁盘分区容量划分变的更灵活。
通过使用Linux的逻辑卷管理器(Logical Volume Manager, LVM),用户可以在系统运行时动态调整文件系统的大小,把数据从一块硬盘重定位到另一块硬盘,也可以提高I/O操作的性能,以及提供冗余保护,它的快照功能允许用户对逻辑卷进行实时的备份。
对一般用户来讲,使用最多的是动态调整文件系统大小的功能。这样,你在分区时就不必为如何设置分区的大小而烦恼,只要在硬盘中预留出部分空闲空间,然后根据系统的使用情况,动态调整分区大小。
LVM进行逻辑卷的管理时,创建顺序是pv→vg→lv。也就是说,首先创建一个物理卷(对应一个物理硬盘分区或者一个物理硬盘),然后把这些分区或者硬盘加入到一个卷组中(相当于一个逻辑上的大硬盘),再在这个大硬盘上划分分区lv(逻辑上的分区,也就是逻辑卷),最后把lv逻辑卷格式化以后,就可以像使用一个传统分区那样,把它挂在到一个挂载点上,需要的时候,这个逻辑卷可以被动态缩放。
2.用硬盘创建
2.1创建物理卷
PV(Physical Volume,物理卷):物理卷就是指磁盘,磁盘分区或从逻辑上与磁盘分区具同样功能的设备(如RAID),是LVM的基本存储逻辑块,处于LVM的最底层,但和基本的物理存储介质(如分区、磁盘等)比较,却包含有与LVM相关的管理参数。
[root@wjl ~]# pvcreate /dev/sdb
Physical volume "/dev/sdb" successfully created.
[root@wjl ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 centos lvm2 a-- <59.00g 4.00m
/dev/sdb lvm2 --- 160.00g 160.00g
[root@wjl ~]# pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name centos
PV Size <59.00 GiB / not usable 3.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 15103
Free PE 1
Allocated PE 15102
PV UUID bKr5Dh-V7Iw-33NA-GQvW-6zCu-dnbt-c3mLWt
"/dev/sdb" is a new physical volume of "160.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sdb
VG Name
PV Size 160.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID iHm4ee-DZEY-1gaU-nKjg-D1cf-WCSI-fjhgdN
2.2创建卷组
VG(Volume Group,卷组):可以看成单独的逻辑磁盘,建立在PV之上,是PV的组合。一个卷组中至少要包括一个PV,在卷组建立之后可以动态的添加PV到卷组中 。
[root@wjl ~]# vgcreate xunihua01 /dev/sdb
Volume group "xunihua01" successfully created
[root@wjl ~]# vgs
VG #PV #LV #SN Attr VSize VFree
centos 1 3 0 wz--n- <59.00g 4.00m
xunihua01 1 0 0 wz--n- <160.00g <160.00g
[root@wjl ~]# vgdisplay
--- Volume group ---
VG Name centos
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 4
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 3
Open LV 3
Max PV 0
Cur PV 1
Act PV 1
VG Size <59.00 GiB
PE Size 4.00 MiB
Total PE 15103
Alloc PE / Size 15102 / 58.99 GiB
Free PE / Size 1 / 4.00 MiB
VG UUID htvqCN-hn4q-es13-XXoh-VQup-fFhf-XPgUHS
--- Volume group ---
VG Name xunihua01
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 1
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 0
Open LV 0
Max PV 0
Cur PV 1
Act PV 1
VG Size <160.00 GiB
PE Size 4.00 MiB
Total PE 40959
Alloc PE / Size 0 / 0
Free PE / Size 40959 / <160.00 GiB
VG UUID 1hzy6A-ch5K-l6JS-pDeF-oYpb-EI05-EBENI7
2.3创建逻辑卷
LV(Logical Volume,逻辑卷):相当于物理分区的/dev/sdaX。逻辑卷建立在卷组之上,卷组中的未分配空间可以用于建立新的逻辑卷,逻辑卷建立后可以动态的扩展或缩小空间。系统中的多个逻辑卷可以属于同一个卷组,也可以属于不同的多个卷组。
[root@wjl ~]# lvcreate -L 20G -n lv1 xunihua01
Logical volume "lv1" created.
[root@wjl ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
home centos -wi-ao---- <18.70g
root centos -wi-ao---- <38.30g
swap centos -wi-ao---- 2.00g
lv1 xunihua01 -wi-a----- 20.00g
#查看
[root@wjl ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 60G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 59G 0 part
├─centos-root 253:0 0 38.3G 0 lvm /
├─centos-swap 253:1 0 2G 0 lvm [SWAP]
└─centos-home 253:2 0 18.7G 0 lvm /home
sdb 8:16 0 160G 0 disk
└─xunihua01-lv1 253:3 0 20G 0 lvm
sr0 11:0 1 4.2G 0 rom
2.4格式化
[root@wjl ~]# mkfs.xfs /dev/xunihua01/lv1
meta-data=/dev/xunihua01/lv1 isize=512 agcount=4, agsize=1310720 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=5242880, 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
#查看uuid
[root@wjl ~]# blkid /dev/xunihua01/lv1
/dev/xunihua01/lv1: UUID="5fe5c1e6-b5de-401f-8cbb-af06c582a193" TYPE="xfs"
2.5进入/etc/fatab添加
UUID="5fe5c1e6-b5de-401f-8cbb-af06c582a193" /lvm/lv1 xfs defaults 0 0
2.6创建挂载的文件夹
[root@wjl ~]# mkdir -p /lvm/lv1
2.7挂载并查看
[root@wjl ~]# mount -a
[root@wjl ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 39G 6.9G 32G 18% /
devtmpfs 899M 0 899M 0% /dev
tmpfs 911M 0 911M 0% /dev/shm
tmpfs 911M 9.6M 902M 2% /run
tmpfs 911M 0 911M 0% /sys/fs/cgroup
/dev/sda1 1014M 142M 873M 14% /boot
/dev/mapper/centos-home 19G 33M 19G 1% /home
tmpfs 183M 0 183M 0% /run/user/0
/dev/mapper/xunihua01-lv1 20G 33M 20G 1% /lvm/lv1
2.8给lv1在线扩容
[root@wjl ~]# lvextend -L +10G /dev/xunihua01/lv1
Size of logical volume xunihua01/lv1 changed from 20.00 GiB (5120 extents) to 30.00 GiB (7680 extents).
Logical volume xunihua01/lv1 successfully resized.
[root@wjl ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
home centos -wi-ao---- <18.70g
root centos -wi-ao---- <38.30g
swap centos -wi-ao---- 2.00g
lv1 xunihua01 -wi-ao---- 30.00g
#实际使用也需要扩容
[root@wjl ~]# xfs_growfs /dev/xunihua01/lv1
meta-data=/dev/mapper/xunihua01-lv1 isize=512 agcount=4, agsize=1310720 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=5242880, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 5242880 to 7864320
[root@wjl ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 39G 6.9G 32G 18% /
devtmpfs 899M 0 899M 0% /dev
tmpfs 911M 0 911M 0% /dev/shm
tmpfs 911M 9.6M 902M 2% /run
tmpfs 911M 0 911M 0% /sys/fs/cgroup
/dev/sda1 1014M 142M 873M 14% /boot
/dev/mapper/centos-home 19G 33M 19G 1% /home
tmpfs 183M 0 183M 0% /run/user/0
/dev/mapper/xunihua01-lv1 30G 33M 30G 1% /lvm/lv1
#给ext4格式的硬盘
[root@wjl ~]# lvcreate -L 15G -n lv2 xunihua01
Logical volume "lv2" created.
[root@wjl ~]# mkfs.ext4 /dev/xunihua01/lv2
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
983040 inodes, 3932160 blocks
196608 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2151677952
120 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
[root@wjl ~]# blkid /dev/xunihua01/lv2
/dev/xunihua01/lv2: UUID="283db36c-6719-41cd-8d3d-49e85bc8ba52" TYPE="ext4"
[root@wjl ~]# vi /etc/fstab
[root@wjl ~]# mkdir -p /lvm/lv2
[root@wjl ~]# mount -a
[root@wjl ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 39G 6.9G 32G 18% /
devtmpfs 899M 0 899M 0% /dev
tmpfs 911M 0 911M 0% /dev/shm
tmpfs 911M 9.6M 902M 2% /run
tmpfs 911M 0 911M 0% /sys/fs/cgroup
/dev/sda1 1014M 142M 873M 14% /boot
/dev/mapper/centos-home 19G 33M 19G 1% /home
tmpfs 183M 0 183M 0% /run/user/0
/dev/mapper/xunihua01-lv1 30G 33M 30G 1% /lvm/lv1
/dev/mapper/xunihua01-lv2 15G 41M 14G 1% /lvm/lv2
[root@wjl ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
home centos -wi-ao---- <18.70g
root centos -wi-ao---- <38.30g
swap centos -wi-ao---- 2.00g
lv1 xunihua01 -wi-ao---- 30.00g
lv2 xunihua01 -wi-ao---- 15.00g
[root@wjl ~]# lvextend -L +10G /dev/xunihua01/lv2
Size of logical volume xunihua01/lv2 changed from 15.00 GiB (3840 extents) to 25.00 GiB (6400 extents).
Logical volume xunihua01/lv2 successfully resized.
[root@wjl ~]# resize2fs /dev/xunihua01/lv2
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/xunihua01/lv2 is mounted on /lvm/lv2; on-line resizing required
old_desc_blocks = 2, new_desc_blocks = 4
The filesystem on /dev/xunihua01/lv2 is now 6553600 blocks long.
[root@wjl ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 39G 6.9G 32G 18% /
devtmpfs 899M 0 899M 0% /dev
tmpfs 911M 0 911M 0% /dev/shm
tmpfs 911M 9.6M 902M 2% /run
tmpfs 911M 0 911M 0% /sys/fs/cgroup
/dev/sda1 1014M 142M 873M 14% /boot
/dev/mapper/centos-home 19G 33M 19G 1% /home
tmpfs 183M 0 183M 0% /run/user/0
/dev/mapper/xunihua01-lv1 30G 33M 30G 1% /lvm/lv1
/dev/mapper/xunihua01-lv2 25G 44M 24G 1% /lvm/lv2
xfs的扩容命令是:xfs_growfs
ext4的扩容命令是:resize2fs
3.用分区创建
3.1创建分区
[root@wjl ~]# fisdk /dev/sdc
-bash: fisdk: command not found
[root@wjl ~]# fdisk /dev/sdc
Welcome to fdisk (util-linux 2.23.2).
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
Building a new DOS disklabel with disk identifier 0xdd881772.
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
Partition number (1-4, default 1):
First sector (2048-251658239, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-251658239, default 251658239): +10G
Partition 1 of type Linux and of size 10 GiB is set
Command (m for help): n
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
Select (default p): p
Partition number (2-4, default 2):
First sector (20973568-251658239, default 20973568):
Using default value 20973568
Last sector, +sectors or +size{K,M,G} (20973568-251658239, default 251658239): +10G
Partition 2 of type Linux and of size 10 GiB is set
Command (m for help): p
Disk /dev/sdc: 128.8 GB, 128849018880 bytes, 251658240 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
Disk label type: dos
Disk identifier: 0xdd881772
Device Boot Start End Blocks Id System
/dev/sdc1 2048 20973567 10485760 83 Linux
/dev/sdc2 20973568 41945087 10485760 83 Linux
Command (m for help): n
Partition type:
p primary (2 primary, 0 extended, 2 free)
e extended
Select (default p): e
Partition number (3,4, default 3):
First sector (41945088-251658239, default 41945088): +80G
Last sector, +sectors or +size{K,M,G} (167772160-251658239, default 251658239):
Using default value 251658239
Partition 3 of type Extended and of size 40 GiB is set
Command (m for help): n
Partition type:
p primary (2 primary, 1 extended, 1 free)
l logical (numbered from 5)
Select (default p): l
Adding logical partition 5
First sector (167774208-251658239, default 167774208):
Using default value 167774208
Last sector, +sectors or +size{K,M,G} (167774208-251658239, default 251658239): +20G
Partition 5 of type Linux and of size 20 GiB is set
Command (m for help): p
Disk /dev/sdc: 128.8 GB, 128849018880 bytes, 251658240 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
Disk label type: dos
Disk identifier: 0xdd881772
Device Boot Start End Blocks Id System
/dev/sdc1 2048 20973567 10485760 83 Linux
/dev/sdc2 20973568 41945087 10485760 83 Linux
/dev/sdc3 167772160 251658239 41943040 5 Extended
/dev/sdc5 167774208 209717247 20971520 83 Linux
Command (m for help): n
Partition type:
p primary (2 primary, 1 extended, 1 free)
l logical (numbered from 5)
Select (default p): l
Adding logical partition 6
First sector (209719296-251658239, default 209719296):
Using default value 209719296
Last sector, +sectors or +size{K,M,G} (209719296-251658239, default 251658239): +30G
Value out of range.
Using default value 251658239
Partition 6 of type Linux and of size 20 GiB is set
Command (m for help): p
Disk /dev/sdc: 128.8 GB, 128849018880 bytes, 251658240 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
Disk label type: dos
Disk identifier: 0xdd881772
Device Boot Start End Blocks Id System
/dev/sdc1 2048 20973567 10485760 83 Linux
/dev/sdc2 20973568 41945087 10485760 83 Linux
/dev/sdc3 167772160 251658239 41943040 5 Extended
/dev/sdc5 167774208 209717247 20971520 83 Linux
/dev/sdc6 209719296 251658239 20969472 83 Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
3.2创建物理卷
[root@wjl ~]# pvcreate /dev/sdc5
Physical volume "/dev/sdc5" successfully created.
[root@wjl ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 centos lvm2 a-- <59.00g 4.00m
/dev/sdc5 lvm2 --- 20.00g 20.00g
3.3创建卷组
[root@wjl ~]# vgcreate xunihua02 /dev/sdc5
Volume group "xunihua02" successfully created
[root@wjl ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 centos lvm2 a-- <59.00g 4.00m
/dev/sdc5 xunihua02 lvm2 a-- <20.00g <20.00g
[root@wjl ~]# vgs
VG #PV #LV #SN Attr VSize VFree
centos 1 3 0 wz--n- <59.00g 4.00m
xunihua02 1 0 0 wz--n- <20.00g <20.00g
3.4给卷组扩容
[root@wjl ~]# pvcreate /dev/sdc6
Physical volume "/dev/sdc6" successfully created.
[root@wjl ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 centos lvm2 a-- <59.00g 4.00m
/dev/sdc5 xunihua02 lvm2 a-- <20.00g <20.00g
/dev/sdc6 lvm2 --- <20.00g <20.00g
[root@wjl ~]# vgs
VG #PV #LV #SN Attr VSize VFree
centos 1 3 0 wz--n- <59.00g 4.00m
xunihua02 1 0 0 wz--n- <20.00g <20.00g
[root@wjl ~]# vgextend xunihua02 /dev/sdc6
Volume group "xunihua02" successfully extended
[root@wjl ~]# vgs
VG #PV #LV #SN Attr VSize VFree
centos 1 3 0 wz--n- <59.00g 4.00m
xunihua02 2 0 0 wz--n- 39.99g 39.99g
4.搭建nfs服务
查看是否有软件包
[root@wjl ~]# rpm -qa |grep nfs-utils
nfs-utils-1.3.0-0.68.el7.2.x86_64
查看系统版本号
[root@wjl ~]# cat /etc/redhat-release
CentOS Linux release 7.5.1804 (Core)
安装nfs软件包
[root@bruce ~]# yum -y install nfs-utils
Loaded plugins: fastestmirror
base | 3.6 kB 00:00:00
docker-ce-stable | 3.5 kB 00:00:00
http://mirrors.cloud.aliyuncs.com/centos/7/extras/x86_64/repodata/repomd.xml: [Errno 14] curl#6 - "Could not resolve host: mirrors.cloud.aliyuncs.com; Name or service not known"
Trying other mirror.
http://mirrors.aliyuncs.com/centos/7/extras/x86_64/repodata/repomd.xml: [Errno 14] curl#7 - "Failed connect to mirrors.aliyuncs.com:80; Connection refused"
Trying other mirror.
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
updates/7/x86_64/primary_db | 20 MB 00:03:13
Determining fastest mirrors
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package nfs-utils.x86_64 1:1.3.0-0.68.el7.2 will be installed
--> Processing Dependency: libtirpc >= 0.2.4-0.7 for package: 1:nfs-utils-1.3.0-0.68.el7.2.x86_64
--> Processing Dependency: gssproxy >= 0.7.0-3 for package: 1:nfs-utils-1.3.0-0.68.el7.2.x86_64
--> Processing Dependency: rpcbind for package: 1:nfs-utils-1.3.0-0.68.el7.2.x86_64
--> Processing Dependency: quota for package: 1:nfs-utils-1.3.0-0.68.el7.2.x86_64
--> Processing Dependency: libnfsidmap for package: 1:nfs-utils-1.3.0-0.68.el7.2.x86_64
--> Processing Dependency: libevent for package: 1:nfs-utils-1.3.0-0.68.el7.2.x86_64
--> Processing Dependency: keyutils for package: 1:nfs-utils-1.3.0-0.68.el7.2.x86_64
--> Processing Dependency: libtirpc.so.1()(64bit) for package: 1:nfs-utils-1.3.0-0.68.el7.2.x86_64
--> Processing Dependency: libnfsidmap.so.0()(64bit) for package: 1:nfs-utils-1.3.0-0.68.el7.2.x86_64
--> Processing Dependency: libevent-2.0.so.5()(64bit) for package: 1:nfs-utils-1.3.0-0.68.el7.2.x86_64
--> Running transaction check
---> Package gssproxy.x86_64 0:0.7.0-30.el7_9 will be installed
--> Processing Dependency: libini_config >= 1.3.1-31 for package: gssproxy-0.7.0-30.el7_9.x86_64
--> Processing Dependency: krb5-libs >= 1.15 for package: gssproxy-0.7.0-30.el7_9.x86_64
--> Processing Dependency: libverto-module-base for package: gssproxy-0.7.0-30.el7_9.x86_64
--> Processing Dependency: libref_array.so.1(REF_ARRAY_0.1.1)(64bit) for package: gssproxy-0.7.0-30.el7_9.x86_64
--> Processing Dependency: libini_config.so.3(INI_CONFIG_1.2.0)(64bit) for package: gssproxy-0.7.0-30.el7_9.x86_64
--> Processing Dependency: libini_config.so.3(INI_CONFIG_1.1.0)(64bit) for package: gssproxy-0.7.0-30.el7_9.x86_64
--> Processing Dependency: libref_array.so.1()(64bit) for package: gssproxy-0.7.0-30.el7_9.x86_64
--> Processing Dependency: libini_config.so.3()(64bit) for package: gssproxy-0.7.0-30.el7_9.x86_64
--> Processing Dependency: libcollection.so.2()(64bit) for package: gssproxy-0.7.0-30.el7_9.x86_64
--> Processing Dependency: libbasicobjects.so.0()(64bit) for package: gssproxy-0.7.0-30.el7_9.x86_64
---> Package keyutils.x86_64 0:1.5.8-3.el7 will be installed
---> Package libevent.x86_64 0:2.0.21-4.el7 will be installed
---> Package libnfsidmap.x86_64 0:0.25-19.el7 will be installed
---> Package libtirpc.x86_64 0:0.2.4-0.16.el7 will be installed
---> Package quota.x86_64 1:4.01-19.el7 will be installed
--> Processing Dependency: quota-nls = 1:4.01-19.el7 for package: 1:quota-4.01-19.el7.x86_64
--> Processing Dependency: tcp_wrappers for package: 1:quota-4.01-19.el7.x86_64
---> Package rpcbind.x86_64 0:0.2.0-49.el7 will be installed
--> Running transaction check
---> Package krb5-libs.x86_64 0:1.13.2-10.el7 will be updated
---> Package krb5-libs.x86_64 0:1.15.1-55.el7_9 will be an update
---> Package libbasicobjects.x86_64 0:0.1.1-32.el7 will be installed
---> Package libcollection.x86_64 0:0.7.0-32.el7 will be installed
---> Package libini_config.x86_64 0:1.3.1-32.el7 will be installed
--> Processing Dependency: libpath_utils.so.1(PATH_UTILS_0.2.1)(64bit) for package: libini_config-1.3.1-32.el7.x86_64
--> Processing Dependency: libpath_utils.so.1()(64bit) for package: libini_config-1.3.1-32.el7.x86_64
---> Package libref_array.x86_64 0:0.1.5-32.el7 will be installed
---> Package libverto-libevent.x86_64 0:0.2.5-4.el7 will be installed
---> Package quota-nls.noarch 1:4.01-19.el7 will be installed
---> Package tcp_wrappers.x86_64 0:7.6-77.el7 will be installed
--> Running transaction check
---> Package libpath_utils.x86_64 0:0.2.1-32.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
==========================================================================================
Package Arch Version Repository Size
==========================================================================================
Installing:
nfs-utils x86_64 1:1.3.0-0.68.el7.2 updates 413 k
Installing for dependencies:
gssproxy x86_64 0.7.0-30.el7_9 updates 111 k
keyutils x86_64 1.5.8-3.el7 base 54 k
libbasicobjects x86_64 0.1.1-32.el7 base 26 k
libcollection x86_64 0.7.0-32.el7 base 42 k
libevent x86_64 2.0.21-4.el7 base 214 k
libini_config x86_64 1.3.1-32.el7 base 64 k
libnfsidmap x86_64 0.25-19.el7 base 50 k
libpath_utils x86_64 0.2.1-32.el7 base 28 k
libref_array x86_64 0.1.5-32.el7 base 27 k
libtirpc x86_64 0.2.4-0.16.el7 base 89 k
libverto-libevent x86_64 0.2.5-4.el7 base 8.9 k
quota x86_64 1:4.01-19.el7 base 179 k
quota-nls noarch 1:4.01-19.el7 base 90 k
rpcbind x86_64 0.2.0-49.el7 base 60 k
tcp_wrappers x86_64 7.6-77.el7 base 78 k
Updating for dependencies:
krb5-libs x86_64 1.15.1-55.el7_9 updates 810 k
Transaction Summary
==========================================================================================
Install 1 Package (+15 Dependent packages)
Upgrade ( 1 Dependent package)
Total download size: 2.3 M
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
(1/17): libbasicobjects-0.1.1-32.el7.x86_64.rpm | 26 kB 00:00:00
(2/17): keyutils-1.5.8-3.el7.x86_64.rpm | 54 kB 00:00:00
(3/17): libcollection-0.7.0-32.el7.x86_64.rpm | 42 kB 00:00:00
(4/17): gssproxy-0.7.0-30.el7_9.x86_64.rpm | 111 kB 00:00:01
(5/17): libini_config-1.3.1-32.el7.x86_64.rpm | 64 kB 00:00:00
(6/17): libevent-2.0.21-4.el7.x86_64.rpm | 214 kB 00:00:01
(7/17): libnfsidmap-0.25-19.el7.x86_64.rpm | 50 kB 00:00:00
(8/17): libref_array-0.1.5-32.el7.x86_64.rpm | 27 kB 00:00:00
(9/17): libpath_utils-0.2.1-32.el7.x86_64.rpm | 28 kB 00:00:00
(10/17): libverto-libevent-0.2.5-4.el7.x86_64.rpm | 8.9 kB 00:00:00
(11/17): libtirpc-0.2.4-0.16.el7.x86_64.rpm | 89 kB 00:00:00
(12/17): quota-4.01-19.el7.x86_64.rpm | 179 kB 00:00:01
(13/17): quota-nls-4.01-19.el7.noarch.rpm | 90 kB 00:00:00
(14/17): rpcbind-0.2.0-49.el7.x86_64.rpm | 60 kB 00:00:00
(15/17): tcp_wrappers-7.6-77.el7.x86_64.rpm | 78 kB 00:00:00
(16/17): nfs-utils-1.3.0-0.68.el7.2.x86_64.rpm | 413 kB 00:00:04
(17/17): krb5-libs-1.15.1-55.el7_9.x86_64.rpm | 810 kB 00:00:08
------------------------------------------------------------------------------------------
Total 285 kB/s | 2.3 MB 00:00:08
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Updating : krb5-libs-1.15.1-55.el7_9.x86_64 1/18
Installing : libtirpc-0.2.4-0.16.el7.x86_64 2/18
Installing : rpcbind-0.2.0-49.el7.x86_64 3/18
Installing : libbasicobjects-0.1.1-32.el7.x86_64 4/18
Installing : libref_array-0.1.5-32.el7.x86_64 5/18
Installing : libcollection-0.7.0-32.el7.x86_64 6/18
Installing : libevent-2.0.21-4.el7.x86_64 7/18
Installing : libverto-libevent-0.2.5-4.el7.x86_64 8/18
Installing : 1:quota-nls-4.01-19.el7.noarch 9/18
Installing : tcp_wrappers-7.6-77.el7.x86_64 10/18
Installing : 1:quota-4.01-19.el7.x86_64 11/18
Installing : keyutils-1.5.8-3.el7.x86_64 12/18
Installing : libnfsidmap-0.25-19.el7.x86_64 13/18
Installing : libpath_utils-0.2.1-32.el7.x86_64 14/18
Installing : libini_config-1.3.1-32.el7.x86_64 15/18
Installing : gssproxy-0.7.0-30.el7_9.x86_64 16/18
Installing : 1:nfs-utils-1.3.0-0.68.el7.2.x86_64 17/18
Cleanup : krb5-libs-1.13.2-10.el7.x86_64 18/18
Verifying : libtirpc-0.2.4-0.16.el7.x86_64 1/18
Verifying : gssproxy-0.7.0-30.el7_9.x86_64 2/18
Verifying : 1:quota-4.01-19.el7.x86_64 3/18
Verifying : libpath_utils-0.2.1-32.el7.x86_64 4/18
Verifying : libnfsidmap-0.25-19.el7.x86_64 5/18
Verifying : krb5-libs-1.15.1-55.el7_9.x86_64 6/18
Verifying : libevent-2.0.21-4.el7.x86_64 7/18
Verifying : keyutils-1.5.8-3.el7.x86_64 8/18
Verifying : libverto-libevent-0.2.5-4.el7.x86_64 9/18
Verifying : tcp_wrappers-7.6-77.el7.x86_64 10/18
Verifying : libcollection-0.7.0-32.el7.x86_64 11/18
Verifying : 1:quota-nls-4.01-19.el7.noarch 12/18
Verifying : libref_array-0.1.5-32.el7.x86_64 13/18
Verifying : libbasicobjects-0.1.1-32.el7.x86_64 14/18
Verifying : 1:nfs-utils-1.3.0-0.68.el7.2.x86_64 15/18
Verifying : libini_config-1.3.1-32.el7.x86_64 16/18
Verifying : rpcbind-0.2.0-49.el7.x86_64 17/18
Verifying : krb5-libs-1.13.2-10.el7.x86_64 18/18
Installed:
nfs-utils.x86_64 1:1.3.0-0.68.el7.2
Dependency Installed:
gssproxy.x86_64 0:0.7.0-30.el7_9 keyutils.x86_64 0:1.5.8-3.el7
libbasicobjects.x86_64 0:0.1.1-32.el7 libcollection.x86_64 0:0.7.0-32.el7
libevent.x86_64 0:2.0.21-4.el7 libini_config.x86_64 0:1.3.1-32.el7
libnfsidmap.x86_64 0:0.25-19.el7 libpath_utils.x86_64 0:0.2.1-32.el7
libref_array.x86_64 0:0.1.5-32.el7 libtirpc.x86_64 0:0.2.4-0.16.el7
libverto-libevent.x86_64 0:0.2.5-4.el7 quota.x86_64 1:4.01-19.el7
quota-nls.noarch 1:4.01-19.el7 rpcbind.x86_64 0:0.2.0-49.el7
tcp_wrappers.x86_64 0:7.6-77.el7
Dependency Updated:
krb5-libs.x86_64 0:1.15.1-55.el7_9
Complete!
查看nfs的守护进程是否启动
[root@wjl ~]# systemctl status rpcbind
● rpcbind.service - RPC bind service
Loaded: loaded (/usr/lib/systemd/system/rpcbind.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2023-03-23 14:55:58 CST; 27min ago
Process: 742 ExecStart=/sbin/rpcbind -w $RPCBIND_ARGS (code=exited, status=0/SUCCESS)
Main PID: 748 (rpcbind)
Tasks: 1
CGroup: /system.slice/rpcbind.service
└─748 /sbin/rpcbind -w
Mar 23 14:55:58 wjl systemd[1]: Starting RPC bind service...
Mar 23 14:55:58 wjl systemd[1]: Started RPC bind service.
查看nfs-server进程是否启动
[root@wjl ~]# systemctl status nfs-server
● nfs-server.service - NFS server and services
Loaded: loaded (/usr/lib/systemd/system/nfs-server.service; disabled; vendor preset: disabled)
Active: inactive (dead)
#设置开机自启和启动该服务
[root@wjl ~]# systemctl enable --now nfs-server
Created symlink from /etc/systemd/system/multi-user.target.wants/nfs-server.service to /usr/lib/systemd/system/nfs-server.service.
[root@wjl ~]# systemctl status nfs-server
● nfs-server.service - NFS server and services
Loaded: loaded (/usr/lib/systemd/system/nfs-server.service; enabled; vendor preset: disabled)
Active: active (exited) since Thu 2023-03-23 15:24:33 CST; 1min 27s ago
Process: 1963 ExecStartPost=/bin/sh -c if systemctl -q is-active gssproxy; then systemctl reload gssproxy ; fi (code=exited, status=0/SUCCESS)
Process: 1946 ExecStart=/usr/sbin/rpc.nfsd $RPCNFSDARGS (code=exited, status=0/SUCCESS)
Process: 1944 ExecStartPre=/usr/sbin/exportfs -r (code=exited, status=0/SUCCESS)
Main PID: 1946 (code=exited, status=0/SUCCESS)
Tasks: 0
CGroup: /system.slice/nfs-server.service
Mar 23 15:24:33 wjl systemd[1]: Starting NFS server and services...
Mar 23 15:24:33 wjl systemd[1]: Started NFS server and services.
查看防火墙是否关闭
[root@wjl ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
Active: inactive (dead)
Docs: man:firewalld(1)
客户机连接服务器
[root@bruce ~]# showmount -e 192.168.88.128
Export list for 192.168.88.128:
创建共享文件目录
[root@wjl ~]# mkdir /nfs
设置只能192.168.88.0/24的网段访问
[root@wjl ~]# vi /etc/exports
[root@wjl ~]# cat /etc/exports
/nfs 192.168.88.*(r)
重启服务
[root@wjl ~]# systemctl restart nfs-server
在客户机上连接查看
[root@bruce ~]# showmount -e 192.168.88.128
Export list for 192.168.88.128:
/nfs 192.168.88.0/24
在客户机上新建文件
[root@bruce ~]# mkdir /124
将nfs挂载到124上并查看
[root@bruce ~]# mount -t nfs 192.168.88.128:/nfs /124
[root@bruce ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 28G 8.7G 19G 32% /
devtmpfs 983M 0 983M 0% /dev
tmpfs 993M 0 993M 0% /dev/shm
tmpfs 993M 8.7M 985M 1% /run
tmpfs 993M 0 993M 0% /sys/fs/cgroup
/dev/sda1 497M 108M 390M 22% /boot
tmpfs 199M 0 199M 0% /run/user/0
192.168.88.128:/nfs 39G 6.9G 32G 18% /124
查看124文件夹
[root@bruce 124]# ls
123.txt
只读无法修改
进入/etc/fstab中添加
192.168.88.128:/nfs /124 nfs defaults,_netdev 0 0
赋予客户机在/nfs中读的权限
[root@bruce /]# setfacl -m u:nfsnobody:r /nfs
[root@bruce /]# getfacl /nfs
getfacl: Removing leading '/' from absolute path names
# file: nfs
# owner: root
# group: root
user::rwx
user:nfsnobody:r--
group::r-x
mask::r-x
other::r-x
标签:逻辑,x86,00,技术,第八章,64,nfs,root,el7
From: https://www.cnblogs.com/shuangmu668/p/17251123.html