服务端:x.x.1.111
客户端:x.x.1.112
需要的安装包 链接:https://pan.baidu.com/s/1YZlt4Ub_4muYQ0HTuFvJtg 提取码:333q
1、nfs安装
//安装nfs
rpm -ivh *.rpm --force --nodeps
//创建共享文件夹
mkdir -p /home/xyp9x/share
2、nfs启动
systemctl enable rpcbind.service
systemctl enable nfs-server.service
systemctl start rpcbind.service
systemctl start nfs-server.service
3、nfs配置
1.编辑配置文件
vi /etc/exports
2.修改配置文件,增加下面这一行数据,指定的ip地址为客户端的地址
/home/xyp9x/share x.x.1.112(rw,insecure,no_root_squash,no_all_squash,sync)
括号中的参数含义:
ro 该主机对该共享目录有只读权限
rw 该主机对该共享目录有读写权限
root_squash 客户机用root用户访问该共享文件夹时,将root用户映射成匿名用户
no_root_squash 客户机用root访问该共享文件夹时,不映射root用户
all_squash 客户机上的任何用户访问该共享目录时都映射成匿名用户
anonuid 将客户机上的用户映射成指定的本地用户ID的用户
anongid 将客户机上的用户映射成属于指定的本地用户组ID
sync 资料同步写入到内存与硬盘中
async 资料会先暂存于内存中,而非直接写入硬盘
insecure 允许从这台机器过来的非授权访问
3.加载配置文件
exportfs -a
4.列出当前共享挂载路径
showmount -e
1、nfs安装
//安装nfs
rpm -ivh *.rpm --force --nodeps
//创建共享文件夹
mkdir -p /home/xyp9x/share
//修改目录所在者组
chown root:xyp9x /home/xyp9x/share
2、nfs启动
systemctl enable rpcbind.service
systemctl enable nfs-server.service
systemctl start rpcbind.service
systemctl start nfs-server.service
3、mount挂载
mount -t nfs -o nolock x.x.1.111:/home/xyp9x/share /home/xyp9x/share
4、永久挂载
vi /etc/init.d/mount.sh
添加:
#!/bin/bash
#chkconfig: 35 20 80
#description: Mount
/bin/mount -t nfs -o nolock x.x.1.111:/home/xyp9x/share /home/xyp9x/share
#增加脚本的可执行权限
chmod 755 /etc/init.d/mount.sh
#添加脚本到开机自动启动项目中。添加到chkconfig,开机自启动。
cd /etc/init.d
chkconfig --add mount.sh
chkconfig mount.sh on
#关闭开机启动
chkconfig mount.sh off
#从chkconfig管理中删除mount.sh
chkconfig --del mount.sh
#查看chkconfig管理
chkconfig --list mount.sh
备注:用以上方式挂载不同服务器的共享目录磁盘亲测可用。
备注:用常规方式修改/etc/fstab文件只适合有且仅有一台服务器进行挂载磁盘,不适合挂载多个其他服务器的共享目录磁盘,我和毛哥交流过,亲测不可用。
5、开机顺序
先启动x.x.1.111服务端,再启动x.x.1.112客户端
6、取消挂载
umount /home/xyp9x/share
7、可能出现的问题
bash-4.2$ bash: 权限不够
cp /etc/skel/.bashrc /home/user/
cp /etc/skel/.bash_profile /home/user/
chown -R user:user /home/user
Stale NFS file handle的解决方法
错误原因是客户端之前挂载的mnt目录在没有卸载的情况下,服务器侧把这个目录移除了,才会出现这样的错误提示。解决的办法就是在客户端umount一下,在重新挂载就好了。
umount /home/xyp9x/share
mount -t nfs -o nolock x.x.1.