服务器和客户端都有一下操作
groupadd nginx
useradd -r -g nginx nginx -s /sbin/nologin
id nginx 查看nginx的id
yum install nfs nfs-utils portmap rpcbind -y
关闭iptables
service iptables stop
chkconfig iptables off
vi /etc/selinux/config
把SELINUX=enforcing 修改为disabled
如果你需要运行iptables,请自己百度如何设置规则
首先是服务器端 119.29.92.249
我使用的是nginx做为图片服务器应用,yum install nginx
yum install nginx
网站文件存放默认目录
/usr/share/nginx/html
网站默认站点配置
/etc/nginx/conf.d/default.conf
自定义Nginx站点配置文件存放目录
/etc/nginx/conf.d/
Nginx全局配置
/etc/nginx/nginx.conf
chkconfig nginx on
开机启动
chkconfig --list
这个是单独的图片服务器,使用图片服务器的ip或者url就可以访问
如果是只是nfs图片服务器,挂载虚拟目录的话,就不要装nginx
这个是客户端
vi /etc/exports
mount -t nfs 119.29.92.249:/usr/share/nginx/html /usr/local/nginx/html/upload
保存退出
usr/share/nginx/html #NFS共享目录
119.29.92.249#允许这个网段内的IP地址访问共享目录
rw #读取写入权限
sync #数据实时同步
no_subtree_check #不检查目录权限,提高数据读取效率
anonuid=501 #501代表nginx用户 打开cat /etc/passwd 查找nginx对应的id
anongid=501 #501代表nginx组 打开cat /etc/group 查找nginx对应的id
chkconfig 查看启动服务器项
请注意现在版本的portmap现在改成 portreserve
chkconfig nfs on
chkconfig nfslock on
chkconfig portreserve on
chkconfig rpcbind on
service rpcbind restart
service nfslock restart
service portreserve restart
service nfs restart
请注意rpcbind 要先于nfs不然会出问题
上面服务器和客户端都要操作
下面是客户端 IP 119.29.10.94
吧
yum install nfs nfs-utils portmap rpcbind -y
上面绿色的 开启开机启动
showmount -e 119.29.92.249
Export list for 119.29.92.249:
/usr/share/nginx/html 119.29.10.94
如果看不到就是有问题的
mount -t nfs 119.29.92.249:/usr/share/nginx/html /usr/local/nginx/html/upload
df 查看客户端是不是挂载上了
在服务器上看挂载上了没有 showmount -a
cd /usr/local/nginx/html/upload
cat /var/lib/nfs/etab 查看挂载的客户端
/usr/share/nginx/html 119.29.10.94(rw,sync,wdelay,hide,nocrossmnt,secure,root_squash,no_all_squash,no_subtree_check,secure_locks,acl,anonuid=501,anongid=501)
卸载挂载点
umount /usr/local/nginx/html/upload
开机启动挂载
vi /etc/fstab
119.29.92.249:/usr/share/nginx/html /usr/local/nginx/html/upload nfs defaults 0 0
请注意,我使用的外网ip方便测试,上架服务器的时候,首先用内网ip,ping,
一定要使用内网IP做为nfs传输,因为外网网速很有限,内网使用的千兆网线,在叫路由器或者交换机上,raid整列raid5,网络传输稳定也有30-60M上下,外网就不知道了
vi /etc/sysconfig/nfs nfs配置文件
RQUOTAD_PORT=875 #取消前面的注释
LOCKD_TCPPORT=32803 #取消前面的注释
LOCKD_UDPPORT=32769 #取消前面的注释
MOUNTD_PORT=892 #取消前面的注释
STATD_PORT=1001 #取消前面的注释,端口修改为1001
STATD_OUTGOING_PORT=1004 #取消前面的注释,端口修改为1004