nfs

nfs

简介

nfs : 通过网络,让不同的机器、不同的操作系统可以共享彼此的文件

主程序端口:2049,其他程序默认使用小于1024的随机端口,配置参数可以指定使用大于1024的端口

rpc:远程过程调用,指定每个NFS功能所对应的port number,并且回报给客户端,让客户端可以连接到正确的port上

安装

yum -y install rpcbind nfs-utils

配置

# 主配置文件
cat /etc/exports
/mnt/rhd        b*(rw,no_subtree_check,insecure,root_squash,no_all_squash)
/mnt/rhd        192.168.1.10/32(rw,no_subtree_check,insecure,root_squash,no_all_squash)
/mnt/rhd        192*(rw,no_subtree_check,insecure,root_squash,no_all_squash)

# 挂载参数详解
ro                      只读访问 
rw                      读写访问 
sync                    所有数据在请求时写入共享 
async                   NFS在写入数据前可以相应请求 
secure                  NFS通过1024以下的安全TCP/IP端口发送 
insecure                NFS通过1024以上的端口发送 
wdelay                  如果多个用户要写入NFS目录,则归组写入(默认) 
no_wdelay               如果多个用户要写入NFS目录,则立即写入,当使用async时,无需此设置。 
hide                    在NFS共享目录中不共享其子目录 
no_hide                 共享NFS目录的子目录 
subtree_check           如果共享/usr/bin之类的子目录时,强制NFS检查父目录的权限(默认) 
no_subtree_check        和上面相对,不检查父目录权限 
all_squash              共享文件的UID和GID映射匿名用户anonymous,适合公用目录。 
no_all_squash           保留共享文件的UID和GID(默认) 
root_squash             root用户的所有请求映射成如anonymous用户一样的权限(默认) 
no_root_squas           root用户具有根目录的完全管理访问权限 
anonuid=xxx             指定NFS服务器/etc/passwd文件中匿名用户的UID 
anongid=xxx             指定NFS服务器/etc/passwd文件中匿名用户的GID  



# 端口配置文件
cat /etc/sysconfig/nfs

# 其他配置文件
cat /etc/idmapd.conf

启动

systemctl enable rpcbind --now 
systemctl enable nfs --now

防火墙

 # 端口根据需求修改
 for port in 111 662 892 2049 32803; do iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport $port -j ACCEPT; done 

客户端三种挂载

#  1 、手动挂载(临时挂载)
showmount -e nfs_server_IP
mount -t nfs nfs_server_IP:/mnt/rhd /mnt/rhd

# 2、fstab文件中挂载
1nfs_server_IP:/mnt/rhd/ 	 	/mnt/rhd     nfs hard,timeo=5,retrans=5,noac,intr,_netdev 0 0

# /etc/fstab文件挂载参数
常见参数如下:
auto: 系统自动挂载,fstab默认就是这个选项
defaults: rw, suid, dev, exec, auto, nouser, and async.
noauto 开机不自动挂载
nouser 只有超级用户可以挂载
ro 按只读权限挂载
rw 按可读可写权限挂载
user 任何用户都可以挂载


3、autofs(自动挂载)

yum -y intall autofs

cat /etc/auto.master
/share      /etc/auto.nfs

cat /etc/auto.nfs
/mnt         -rw,soft,intr                          1nfs_server_IP:/mnt/rhd1
posted @ 2024-07-30 10:25  itk  阅读(45)  评论(0)    收藏  举报