黑猴子的家:三台服务节点,配置NFS

1、主机名映射

[[email protected] ~]# vim /etc/hosts
192.168.2.102  node1
192.168.2.103  node2
192.168.2.104  node3

2、查看系统版本(三台机器)

[[email protected] ~]# uname -r
3.10.0-514.el7.x86_64

3、查看系统内核版本(三台机器)

[[email protected] ~]# cat /etc/redhat-release 
CentOS Linux release 7.3.1611 (Core) 

4、查看系统是否是64位(三台机器)

[[email protected] ~]# uname -m
x86_64

5、检查软件是否安装(三台机器)

[[email protected] ~]# rpm -qa nfs-utils rpcbind

6、安装NFS所需软件(三台机器)

[[email protected] ~]# yum install -y nfs-utils rpcbind

7、启动rpcbind服务(三台机器)

[[email protected] ~]# systemctl start rpcbind

8、查看rpcbind服务(三台机器)

[[email protected] ~]# systemctl status rpcbind

9、查询rpcbind监听状态 (111是rpcbind的主端口) (三台机器)

[[email protected] ~]# lsof -i :111

10、查询rpcbind服务启动状态 (同lsof查询端口效果一样) (三台机器)

[[email protected] ~]# netstat -lntup |grep rpcbind

11、设置rpcbind开机自动启动 (三台机器)

[[email protected] ~]# systemctl enable rpcbind

12、检查rpcbind自启动情况(三台机器)

[[email protected] ~]# systemctl list-unit-files | grep rpcbind

13、启动NFS服务(服务端)

[[email protected] ~]# systemctl start nfs

14、查看NFS服务(服务端)

[[email protected] ~]# systemctl status nfs

15、设置NFS开机自动启动 (服务端)

[[email protected] ~]# systemctl enable nfs

16、检查NFS自启动情况(服务端)

[[email protected] ~]# systemctl list-unit-files | grep nfs
尖叫提示:必须先启动rpcbind,再启动nfs,这样才能让NFS在rpcbind上注册成功
生产环境一般
echo  'systemctl start rpcbind ' >> /etc/rc.local
echo  'systemctl start nfs ' >> /etc/rc.local
控制启动顺序

17、查看NFS服务项rpc服务器注册的端口信息(服务端)

[[email protected] ~]# rpcinfo -p localhost

18、配置NFS服务端(服务端)

[[email protected] ~]# vim /etc/exports
/opt/software/data/ 192.168.2.0/24(insecure,rw,async,no_root_squash)
尖叫提示:/etc/exports 是NFS程序的配置文件,默认为空
配置格式:
NFS共享目录 NFS客户端地址1(参数1,参数2,参数3......) 客户端地址2(参数1,参数2,参数3......)
NFS共享目录 NFS客户端地址(参数1,参数2,参数3......) 
![image.png](https://upload-images.jianshu.io/upload_images/9193428-92a5712bb3b5e711.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
我们在此共享给 192.168.2.0/24所有主机

19、查看 例子和参数详情(服务端)

[[email protected] ~]# man exports

20、配置完成exports后平滑重启NFS服务(服务端)

[[email protected] ~]# exportfs -r
尖叫提示:同“systemctl restart nfs”命令

21、查看本机挂载情况(服务端)

[[email protected] ~]# showmount -e 127.0.0.1
尖叫提示:必须先启动rpcbinc 再启动nfs才会显示正确

22、在本机测试挂载(服务端)

[[email protected] ~]# mount -t nfs 192.168.2.103:/opt/software/data /mnt 

23、查看磁盘使用情况(服务端)

[[email protected] ~]# df -h

24、在本机卸载挂载(服务端)

[[email protected] ~]# umount /mnt 

25、创建挂载目录(客户端)

[[email protected] ~]# mkdir -p /opt/software/data

26、给挂载目录赋予权限(三台机器)

[[email protected] ~]# cd /opt/software/
[[email protected] ~]# chmod 777 data/

27、客户端挂载服务端(客户端)

[[email protected] ~]# mount -t nfs 192.168.2.104:/opt/software/data /opt/software/data

28、查看磁盘使用情况(客户端)

[[email protected] ~]# df -h
[[email protected] ~]# mount
[[email protected] ~]# cat /proc/mounts

29、给客户端配置挂载(/opt/software/data)目录添加操作权限(服务端)

[[email protected] software]# grep 65534 /etc/passwd
nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
[[email protected] software]# chown -R nfsnobody /data

30、查看配置的详细信息(服务端)

[[email protected] software]# cat /var/lib/nfs/etab

31、启动挂载

[[email protected] ~]# echo 'mount -t nfs 192.168.2.104:/opt/software/data /opt/software/data' >> /etc/rc.local
尖叫提示我们需要把挂载命令放在rc.local里面,我们不要把挂载命令放在fstab,因为fstab比网络先启动,会出现挂载不上网络NFS。

32、如果是WINDOWS客户端,我们需要在程序和功能里面启用 NFS客户端

黑猴子的家:三台服务节点,配置NFS
image.png