2.8 KiB
2.8 KiB
本文作者:丁辉
Linux部署NFS存储
节点 | IP |
---|---|
NFS | 192.168.1.10 |
-
部署 Nfs 程序
-
Centos部署
yum install nfs-utils rpcbind -y
-
Ubuntu部署
apt install nfs-kernel-server -y
客户端部署
apt install nfs-common -y
正常情况下安装nfs-kernel-server
会自动安装客户端
-
-
创建共享目录
mkdir /data chmod -R 777 /data
-
添加配置文件
echo "/data 192.168.1.0/24(rw,sync,insecure,no_subtree_check,no_root_squash)" >> /etc/exports
允许所有(不建议在生产使用)
echo "/data *(rw,sync,insecure,no_subtree_check,no_root_squash)" >> /etc/exports
-
启动 Nfs
systemctl start rpcbind systemctl start nfs-server systemctl enable rpcbind systemctl enable nfs-server
-
查看
showmount -e 127.0.0.1
其它节点挂载 Nfs 存储到本地
NFS 节点开放端口
NFS服务端口(Mountd)
iptables -A INPUT -p tcp --dport 2049 -j ACCEPT iptables -A INPUT -p udp --dport 2049 -j ACCEPT
Portmapper(端口映射程序)
iptables -A INPUT -p tcp --dport 111 -j ACCEPT iptables -A INPUT -p udp --dport 111 -j ACCEPT
-
手动挂载
mount.nfs 192.168.1.10:/data /data
-
开机自动挂载
echo "192.168.1.10:/data /data nfs defaults 0 0" >> /etc/fstab
Nfs 参数解释
参考 man 文档配置参数
man exports
参数解释
参数 | 解释 |
---|---|
rw | 允许客户端对共享的文件系统进行读写操作。 |
sync | 所有对共享文件系统的写操作都会同步到存储设备上。 |
insecure | 允许不安全的客户端访问共享的文件系统。 |
no_subtree_check | 禁止对子目录进行共享级别的访问控制检查。 |
no_root_squash | 不对远程 root 用户进行权限限制,允许其以 root 身份访问共享。 |
Exportfs参数解释
修改 exportfs 后重新加载配置
exportfs -arv
参数解释
选项 | 解释 |
---|---|
-a | 导出或取消导出 /etc/exports 文件中列出的所有文件系统。 |
-r | 刷新 /etc/exports 文件并重新加载 NFS 导出。 |
-v | 输出详细的日志信息,包括正在进行的操作和任何错误消息。 |