Loading... # Centos7多服务器挂载同一文件系统 ## 服务器端配置 ### 安装nfs ``` rpm -qa |grep nfs yum install nfs-utils ``` ### 修改配置 编辑或新建配置文件,添加要共享的客户端地址 vi /etc/exports ``` /opt/share 192.168.50.18(rw,no_root_squash) /opt/share 192.168.50.19(rw,no_root_squash) ``` ### NFS共享的常用参数 ``` 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_squash root用户具有根目录的完全管理访问权限 anonuid=xxx 指定NFS服务器/etc/passwd文件中匿名用户的UID anongid=xxx 指定NFS服务器/etc/passwd文件中匿名用户的GID ``` ### 配置防火墙 可以简单粗暴的停用防火墙 ``` systemctl stop iptables ``` 也可以配置防火墙规则 启动NFS会开启如下端口: - portmapper 端口:111 udp/tcp - nfs/nfs_acl 端口:2049 udp/tcp - mountd 端口:"32768--65535" udp/tcp - nlockmgr 端口:"32768--65535" udp/tcp **查看NFS启动后的端口** ``` rpcinfo -p localhost ``` **设置固定端口** vi /etc/sysconfig/nfs 在最后添加 ``` RQUOTAD_PORT=4001 LOCKD_TCPPORT=4002 LOCKD_UDPPORT=4002 MOUNTD_PORT=4003 STATD_PORT=4004 ``` **重启服务** ``` systemctl restart rpcbind systemctl restart nfs ``` **还需在/etc/modprobe.d/lockd.conf中添加以下设置**: ``` options lockd nlm_tcpport=4002 options lockd nlm_udpport=4002 ``` **重新加载NFS配置和服务** ``` systemctl restart nfs-config systemctl restart nfs-idmap systemctl restart nfs-lock systemctl restart nfs-server ``` **设置防火墙** vi /etc/sysconfig/iptables ``` -A INPUT -p tcp -m tcp --dport 111 -j ACCEPT -A INPUT -p udp -m udp --dport 111 -j ACCEPT -A INPUT -p tcp -m tcp --dport 2049 -j ACCEPT -A INPUT -p udp -m udp --dport 2049 -j ACCEPT -A INPUT -p tcp -m tcp --dport 4001:4004 -j ACCEPT -A INPUT -p udp -m udp --dport 4001:4004 -j ACCEPT ``` **重启防火墙** ``` systemctl restart iptables ``` ### 服务启动 ``` systemctl enable nfs # 开机启用 systemctl start nfs ``` ## 客户端配置 ### 安装启动nfs ``` yum install nfs-utils rpcbind systemctl enable nfs systemctl start nfs ``` ### 将服务端的硬盘挂载到本地 ``` mount -t nfs 192.168.50.17:/opt/share /opt/share ``` Last modification:June 27th, 2020 at 11:36 pm © 允许规范转载
平淡中见真章,质朴处显功力。