安装配置NFS
服务器 web01
192.168.178.124
1.安装nfs-utils和rpcbind
[root@web01 ~]# yum install -y nfs-utils rpcbind
2.环境配置
##NFS也是C/S模式,在Server机器上创建用于NFS文件共享的文件夹,且设置好权限
[root@web01 ~]# mkdir /nfsShare
[root@web01 ~]# chmod -Rf 777 /nfsShare/
3.开启rpcbind和nfs-server服务
##要注意的是rpcbind服务即使停止, 111端口也不会挂掉,因为还有rpcbind.socket服务
[root@web01 ~]# systemctl restart rpcbind
[root@web01 ~]# systemctl restart nfs-server
4.配置NFS服务端的过程
4.1 确保RPC服务启动了
[root@web01 ~]# systemctl restart rpcbind
4.2 创建需要共享的目录,以及资料,并且授权
[root@web01 ~]# mkdir -p /nfs_data
[root@web01 ~]# touch /nfs_data/好嗨哦.txt
4.3 修改文件夹的属主、属组
[root@web01 ~]# chown -R nfsnobody.nfsnobody /nfs_data/
4.4 配置NFS服务端配置文件,写入如下挂载参数
[root@web01 ~]# vim /etc/exports /nfs_data *(insecure,rw,sync)
4.5 重新加载nfs服务
[root@web01 ~]# systemctl reload nfs
4.6 查看NFS服务挂载情况
[root@web01 ~]# showmount -e
Export list for web01: /nfs_data *
4.7 查看NFS服务端挂载默认的参数,如下大多数参数都是默认的
[root@web01 ~]# cat /var/lib/nfs/etab
/nfs_data *(rw,sync,wdelay,hide,nocrossmnt,insecure,root_squash,no_all_squash,no_subtree_check,secure_locks,acl,no_pnfs,anonuid=65534,anongid=65534,sec=sys,rw,insecure,root_squash,no_all_squash)
8.把自己本地机器当做客户端做一个简单挂载测试
[root@web01 ~]# mount -t nfs 192.168.178.124:/nfs_data/ /mnt
[root@web01 ~]# ls /mnt/
好嗨哦.txt
9.检查挂载情况
[root@web01 ~]# df -h |tail -1
192.168.178.124:/nfs_data 20G 1.8G 18G 10% /mnt [root@web01 ~]# mount |tail -1
192.168.178.124:/nfs_data on /mnt type nfs4 (rw,relatime,vers=4.1,rsize=262144,wsize=262144,namlen=255,hard,proto=tcp,timeo=600,retrans=2,sec=sys,clientaddr=192.168.178.124,local_lock=none,addr=192.168.178.124)
配置NFS客户端
##在另一台Linux机器上连接nfs服务端
服务器 web01
192.168.178.124
客户端 web02
192.168.178.125
1.安装nfs的命令套件
[root@web02 ~]# yum install nfs-utils rpcbind -y
2.确保rpcbind服务正常
[root@web02 ~]# systemctl status rpcbind
3.以nfs协议挂载
[root@web02 ~]# mount -t nfs 192.168.178.124:/nfs_data /mnt
4.进入挂载目录,检查远程NFS服务端的文件夹资料
[root@web02 ~]# cd /mnt
[root@web02 mnt]# ls
好嗨哦.txt
5.开机自动挂载,将挂载命令写入到/etc/fstab文件
[root@web02 mnt]# tail -1 /etc/fstab
192.168.178.124:/nfs_data /mnt nfs defaults 0 0