NFS安装
nfs程序主进程为nfs-utils,nfs通信依赖于rpcbind
使用rpm –qa |egrep “nfs-utils|rpcbind”查看程序是否安装。
程序安装
yum install nfs-utils -y
yum install rpcbind -y
程序使用端口
rpc使用端口111
nfs主端口2049
rpcbind信息使用rpcinfo -p localhost查看
程序的开机自启动
nfs的端口依赖于rpcbind,所以nfs需要在rpcbind之后进行启动。
两种方式:
方式1.chkconfig nfs on 与chkconfig rpcbind on。(使用这种方式需要注意服务启动脚本中启动顺序的编号。)
方式2.程序运行命令写入/etc/rc.local。
注:推荐使用方式2,更加灵活,并且可以添加注释。
NFS配置文件及格式
nfs的配置文件为/etc/exports
格式:
nfs共享目录 nfs地址(参数1、参数2……..)
地址可以使用网段、具体IP主机名
# sample /etc/exports file
/ master(rw) trusty(rw,no_root_squash)
/projects proj*.local.domain(rw)
/usr *.local.domain(ro) @trusted(rw)
/home/joe pc001(rw,all_squash,anonuid=150,anongid=100)
/pub *(ro,insecure,all_squash)
/srv/www -sync,rw server @trusted @external(ro)
/foo 2001:db8:9:e54::/64(rw) 192.0.2.0/24(rw)
/build buildhost[0-9].local.domain(rw)
使用 showmount -e localhost查看本机的挂载情况
使用rpcinfo –p localhost查看rpc的绑定信息
配置文件加载:
/etc/init.d/nfs reload
/usr/sbin/exportfs -r
客户端使用共享存储
mount –t nfs -o 参数1,参数2…… IP:/目录 挂载点
``
将挂载点的所属用户更改为nfsnobody
查看客户端默认的挂载参数
cat /var/lib/nfs/etab
查看挂载情况:
1. df –h
2. mount –l
3. cat /etc/mtab
服务器端属性
rw 读写
ro 只读
sync 内容同步写入磁盘
async 内容异步写入磁盘(不要用,会导致数据丢失)
no_root_squash root用户访问时拥有root权限(一般仅用于无盘系统)
root_squash root用户访问将权限压缩为nfsnobody
all_squash 所有用户访问,都会讲权限压缩为nfsnobody
anonuid,anongid:指定创建的文件的UID和GID。
总结:生产场景使用(rw,sync,all_squash)。
客户端属性
1.noexec :不能上传可执行的2进制文件
2.noatime:不更新文件的时间戳
3.nodiratime:不更新文件夹的时间戳
4.nosuid:不能上传有setuid位的文件
5.remount:对于已经挂载的文件系统重新挂载,主要用于属性更改的时候,例如从只读变更为读写时候。
常用参数-o noexec,noatime,nodiratmine,nosuid
8.nfs主要的配置文件
1./etc/exports(主配置文件)
2./usr/sbin/exportfs
3./var/lib/nfs/etab(服务端默认参数)
4./usr/sbin/showmount
5./proc/mount(客户端默认参数)
NFS排错
NFS排错思路:
首先确认NFS服务端配置和服务OK
showmount –e localhost
lsof -i:111
最好在服务端挂一下看下是否OK
mount –t nfs localhost:/data /mnt
检查NFS客户端showmount是否OK
no route to host:被防火墙阻挡
no such file or dir:服务端没有目录
permision deny:服务端文件系统权限
nfs内核优化
cat>>/etc/sysctl.conf<
net.core.wmem_default=8388608
net.core.rmem_default=8388608
net.core.wmem_max=16777216
net.core.rmem_max=16777216
EOF
sysctl -p(使内核修改参数生效)
nfs优缺点
优点:
简单,容易上手
nfs数据在文件系统之上,可以看到数据。
方便,部署简单、维护简单、可控,且满足使用需求
可靠
非常稳定。
缺点:
存在单点故障
在高并发的场合,NFS的效率性能有限(通过架构解决)。
基于IP主机名的的认证,安全性一般。
数据以明文的方式传输,数据完整性不作验证。
多台客户机连接一个nfs,连接维护麻烦。
硬盘的选择
1.sas盘与ssd盘,选择多块盘做raid0或raid10,尽量不用raid5(读快写慢),磁盘吞吐量大的时候做多块网卡绑定。