NFS的部署
一、先配置yum源,配置本地yum源(两节点都配置)
[root@localhost ~]# mkdir /opt/cdrom
[root@localhost ~]# mount /dev/cdrom /opt/cdrom
mount: /dev/sr0 is write-protected, mounting read-only
[root@localhost ~]# mv /etc/yum.repos.d/C* /media/
[root@localhost ~]# vi /etc/yum.repos.d/local.repo
[centos]
name=centos
baseurl=file:///opt/cdrom
gpgcheck=0
enabled=1
~
~
~
~
~
~
"/etc/yum.repos.d/local.repo" [New] 5L, 68C written
[root@localhost ~]# yum clean all
Loaded plugins: fastestmirror
Cleaning repos: centos
Cleaning up everything
Cleaning up list of fastest mirrors
[root@localhost ~]# yum repolist
Loaded plugins: fastestmirror
centos | 3.6 kB 00:00:00
(1/2): centos/group_gz | 155 kB 00:00:00
(2/2): centos/primary_db | 2.8 MB 00:00:00
Determining fastest mirrors
repo id repo name status
centos centos 3,723
repolist: 3,723
显示内核信息
[root@localhost ~]# uname -a
Linux localhost.localdomain 3.10.0-327.el7.x86_64 #1 SMP Thu Nov 19 22:10:57 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
二、安装RPC和NFS(两节点都安装)
[root@localhost ~]# yum install nfs-utils rpcbind -y
三、查看NFS自带的用户是否在(两节点都需要)
[root@localhost ~]# id nfsnobody
uid=65534(nfsnobody) gid=65534(nfsnobody) groups=65534(nfsnobody)
四、启动服务(先启动RPC在启动NFS)
[root@localhost ~]# systemctl start rpcbind
[root@localhost ~]# systemctl enable !$
systemctl enable rpcbind
[root@localhost ~]# systemctl start nfs
五、关闭防火墙,selinux,iptable(两边都关)
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# systemctl disable firewalld
[root@localhost ~]# setenforce 0
[root@localhost ~]# iptables -F
[root@localhost ~]# iptables -X
[root@localhost ~]# iptables -Z
[root@localhost ~]# iptables-save
#Generated by iptables-save v1.4.21 on Fri Nov 6 19:48:43 2020
*filter
:INPUT ACCEPT [20:1320]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [11:1028]
COMMIT
# Completed on Fri Nov 6 19:48:43 2020
六、查看两边RPC端口
[root@localhost ~]# netstat -lntp |grep rpc
tcp 0 0 0.0.0.0:54186 0.0.0.0:* LISTEN 19063/rpc.statd
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 19019/rpcbind
tcp 0 0 0.0.0.0:20048 0.0.0.0:* LISTEN 19076/rpc.mountd
tcp6 0 0 :::111 :::* LISTEN 19019/rpcbind
tcp6 0 0 :::20048 :::* LISTEN 19076/rpc.mountd
tcp6 0 0 :::36862 :::* LISTEN 19063/rpc.statd
七、查看端口映射情况
[root@localhost ~]# rpcinfo -p localhost
program vers proto port service
100000 4 tcp 111 portmapper
100000 3 tcp 111 portmapper
100000 2 tcp 111 portmapper
100000 4 udp 111 portmapper
100000 3 udp 111 portmapper
100000 2 udp 111 portmapper
100024 1 udp 35267 status
100024 1 tcp 54186 status
100005 1 udp 20048 mountd
100005 1 tcp 20048 mountd
100005 2 udp 20048 mountd
100005 2 tcp 20048 mountd
100005 3 udp 20048 mountd
100005 3 tcp 20048 mountd
100003 3 tcp 2049 nfs
100003 4 tcp 2049 nfs
100227 3 tcp 2049 nfs_acl
100003 3 udp 2049 nfs
100003 4 udp 2049 nfs
100227 3 udp 2049 nfs_acl
100021 1 udp 36480 nlockmgr
100021 3 udp 36480 nlockmgr
100021 4 udp 36480 nlockmgr
100021 1 tcp 39218 nlockmgr
100021 3 tcp 39218 nlockmgr
100021 4 tcp 39218 nlockmgr
八、创建共享目录并更改共享目录的权限(在一个节点建立)
[root@localhost ~]# mkdir /data
[root@localhost ~]# chown -R nfsnobody:nfsnobody /data
[root@localhost ~]# chmod 755 -R /data
九、添加磁盘,分区,格式化磁盘
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 500M 0 part /boot
└─sda2 8:2 0 19.5G 0 part
├─centos-root 253:0 0 17.5G 0 lvm /
└─centos-swap 253:1 0 2G 0 lvm [SWAP]
sdb 8:16 0 20G 0 disk
sr0 11:0 1 4G 0 rom
[root@localhost ~]# fdisk /dev/sdb
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 0x6c847144.
Command (m for help): p
Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 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: 0x6c847144
Device Boot Start End Blocks Id System
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-41943039, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): +20G
Value out of range.
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): +10G
Partition 1 of type Linux and of size 10 GiB is set
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 500M 0 part /boot
└─sda2 8:2 0 19.5G 0 part
├─centos-root 253:0 0 17.5G 0 lvm /
└─centos-swap 253:1 0 2G 0 lvm [SWAP]
sdb 8:16 0 20G 0 disk
└─sdb1 8:17 0 10G 0 part
sr0 11:0 1 4G 0 rom
[root@localhost ~]# mkfs.ext4 /dev/sdb1
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
655360 inodes, 2621440 blocks
131072 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2151677952
80 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
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
[root@localhost ~]# blkid
/dev/sdb1: UUID="e15c3d16-d92a-4d23-878e-3ee1a733474d" TYPE="ext4"
/dev/sda1: UUID="8d3266cc-e707-4cdf-9ed9-49bad084f847" TYPE="xfs"
/dev/sda2: UUID="pSeDgj-pSa0-Y2iJ-hKi1-D6DP-v65o-cDbCo2" TYPE="LVM2_member"
/dev/sr0: UUID="2015-12-09-23-14-10-00" LABEL="CentOS 7 x86_64" TYPE="iso9660" PTTYPE="dos"
/dev/mapper/centos-root: UUID="494c2af2-a561-46e2-af0d-6dafef5eb8de" TYPE="xfs"
/dev/mapper/centos-swap: UUID="26c55b11-1cd2-4dce-bad3-1b171d4b54bb" TYPE="swap"
九、挂载磁盘
[root@localhost ~]# vi /etc/fstab
#
# /etc/fstab
# Created by anaconda on Fri Nov 6 16:06:58 2020
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/centos-root / xfs defaults 0 0
UUID=8d3266cc-e707-4cdf-9ed9-49bad084f847 /boot xfs defaults 0 0
/dev/mapper/centos-swap swap swap defaults 0 0
/dev/sdb1 /data ext4 defaults 0 0
~
~
~
~
~
"/etc/fstab" 12L, 507C written
[root@localhost ~]# mount -a
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 18G 931M 17G 6% /
devtmpfs 903M 0 903M 0% /dev
tmpfs 913M 0 913M 0% /dev/shm
tmpfs 913M 8.6M 904M 1% /run
tmpfs 913M 0 913M 0% /sys/fs/cgroup
/dev/sda1 497M 125M 373M 25% /boot
tmpfs 183M 0 183M 0% /run/user/0
/dev/sdb1 9.8G 37M 9.2G 1% /data
十、配置 nfs 共享目录
[root@localhost ~]# vi /etc/exports
/data 192.168.200.0/24(rw,no_root_squash,async)
~
~
~
~
~
~
~
~
~
~
"/etc/exports" 1L, 48C written
十一、生效配置与检验
[root@localhost ~]# exportfs -rv
exporting 192.168.200.0/24:/data
[root@localhost ~]# showmount -e localhost
clnt_create: RPC: Timed out
[root@localhost ~]# systemctl restart rpcbind
[root@localhost ~]# systemctl restart nfs
[root@localhost ~]# showmount -e localhost
Export list for localhost:
/data 192.168.200.0/24
查询可用端口
[root@localhost ~]# showmount -e 192.168.200.70
Export list for 192.168.200.70:
/data 192.168.200.0/24
十二、调试与检验成果
另一台虚拟机
[root@nfs-client ~]# mount -t nfs 192.168.200.70:/data /mnt
[root@nfs-client ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 18G 880M 17G 5% /
devtmpfs 903M 0 903M 0% /dev
tmpfs 913M 0 913M 0% /dev/shm
tmpfs 913M 8.6M 904M 1% /run
tmpfs 913M 0 913M 0% /sys/fs/cgroup
/dev/sda1 497M 125M 373M 25% /boot
tmpfs 183M 0 183M 0% /run/user/0
/dev/sr0 4.1G 4.1G 0 100% /opt/cdrom
192.168.200.70:/data 9.8G 37M 9.2G 1% /mnt
显示格式
[root@nfs-client ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/centos-root xfs 18G 880M 17G 5% /
devtmpfs devtmpfs 903M 0 903M 0% /dev
tmpfs tmpfs 913M 0 913M 0% /dev/shm
tmpfs tmpfs 913M 8.6M 904M 1% /run
tmpfs tmpfs 913M 0 913M 0% /sys/fs/cgroup
/dev/sda1 xfs 497M 125M 373M 25% /boot
tmpfs tmpfs 183M 0 183M 0% /run/user/0
/dev/sr0 iso9660 4.1G 4.1G 0 100% /opt/cdrom
192.168.200.70:/data nfs4 9.8G 37M 9.2G 1% /mnt