Linux安装NFS
一、系统环境
系统平台:CentOS release 6.5(Final)
NFS Server IP:
防火墙已关闭 /iptables: Firewall is not running.
SELINUX=disabled
检查防火墙状态
chkconfig iptables --list
关闭防火墙(需要重启)
chkconfig iptables off
查看setenforce状态
setenforce --list
关闭setenforce(需要重启)
vi /etc/selinux/config
将SELINUX=enforcing 改成SELINUX=disabled
查看已安装的nfs-utils 和rpcbind(在CentOS 6.3当中,portmap服务由rpcbind负责)
rpm -qa|grep nfs-utils
rpm -qa|grep rpcbind
挂载新磁盘
查看磁盘情况
fdisk –l
分区新磁盘
fdisk /dev/sdb
格式化磁盘
mkfs -t ext3 -c /dev/sdb1
挂载目录到新磁盘
mount /dev/sdb1 /dev2/gxcc
查看当前挂载的分区和大小
df –l
查看目录占用详情(赋予权限)
du -shx *
chmod 755 /dev2/gxcc
chown –R root:root /dev2/gxcc
自动挂载分区
vi /etc/fstab
/dev/sdb1 /dev2/gxcc ext3 defaults 1 2
nfs服务器的配置
编辑exports
vi /etc/exports
/dev2/gxcc *(rw,sync,no_root_squash)
/dev3/gx 192.168.9.210(rw,sync,no_root_squash)
#/var/ftp *(rw,no_root_squash)
说明:/var/ftp 为共享的目录位置; *(rw,no_root_squash) *为任意IP都可以访问 rw为可进行读写访问 no_root_squash 为拥有这个目录所有者的权限。
重启nfs服务
service nfs restart
查看nfs启动状态
chkconfig --list nfs
开启nfs
chkconfig nfs on
查询nfs的共享状态
showmount –e
显示已经与客户端连接状态
showmount -a
nfs客户端的配置
查询nfs服务器的共享状态
showmount -e NFS服务器IP
mount -t nfs -o rw 192.168.9.209:/dev2/gxcc /gxcc
mount -t nfs -o rw 192.168.9.209:/dev3/gx /wxl
测试创建文件夹,文件
mkdir wxl
touch 20170315
自动挂载
vi /etc/fstab
192.168.9.209:/dev2/gxcc /gxccc nfs defaults 0 0
192.168.9.209:/dev3/gx /wxl nfs defaults 0 0
安装rpc服务
rpm -qa|grep rpcbind
rpm -e --nodeps rpcbind-0.2.0-11.el6.x86_64
rpm -ivh rpcbind-0.2.0-12.el6.x86_64.rpm
#----------------------------centos7 设置步骤-----------------------------
nfs挂载:
客户端服务器端安装nfs:
yum install -y nfs-utils
服务器端操作:
启动nfs和rpcbind:
systemctl start nfs & systemctl enable nfs systemctl start rpcbind & systemctl enable rpcbind
创建需要共享的目录(例如):
mkdir /home/mnt/question/
设置nfs共享目录权限:
vim /etc/exports
添加(红色ip为nfs服务端ip),:wq保存退出
/home/mnt/question 192.168.1.30/24(rw,sync)
此处rw表示可读写,sync表示文件同时写入硬盘和内存
设置权限
chmod -R 777 /home/mnt/question
重启nfs服务
systemctl restart nfs & systemctl restart rpcbind
客户端操作:
创建需要挂载nfs的目录(例如):
mkdir /home/attachments
添加挂载目录:
mount -t nfs 192.168.1.30:/home/mnt/question /home/attachments/
测试是否挂载成功:
客户端操作:
cd /home/attachments mkdir test
服务器端操作:
cd /home/mnt/question
ls查看能看到test文件夹证明挂载成功
如果挂载不成功的话请关闭nfs服务器的防火墙
firewall-cmd --state systemctl stop firewalld systemctl disable firewalld
开机自启动nfs:
因为在centos7中/etc/rc.d/rc.local的权限被降低了,所以需要赋予其可执行权
chmod +x /etc/rc.d/rc.local
编写自启动脚本
红色所代表的ip是platform所在机器对应的ip
vim /usr/local/sbin/nfsboot.sh
往脚本填写一下内容:
#! /bin/bash ## This is nfs自启动 shell script. ## Writen by Luyouzhi 2020-04-03. date mount -t nfs 192.168.1.30:/home/mnt/question /home/attachments/ echo "nfs自启动 success!!"
赋予脚本可执行权限
chmod +x /usr/local/sbin/nfsboot.sh
打开/etc/rc.d/rc.local文件,在末尾增加如下内容
/usr/local/sbin/nfsboot.sh
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了