linux 创建NFS服务

来源:互联网 发布:多宝视弱视训练软件 编辑:程序博客网 时间:2024/05/22 14:10
一、环境介绍
 
  NFS服务器:CentOS6.5 192.168.0.10
  NFS客户端:CentOS6.5 192.168.0.11
 
二、服务器端安装配置
 
1、先用rpm -qa命令查看所需安装包(nfs-utils、rpcbind)是否已经安装:


1.[root@local /]# rpm -qa | grep "rpcbind"
                  rpcbind-0.2.0-11.el6.x86_64
2.[root@local /]# rpm -qa | grep "nfs"
                  nfs-utils-1.2.3-39.el6.x86_64
                   nfs4-acl-tools-0.3.3-6.el6.x86_64
                   nfs-utils-lib-1.1.5-6.el6.x86_64
2、如查询结果如上,说明服务器自身已经安装了NFS,如果没有安装,则用yum命令来安装:
1.[root@local /]# yum -y install nfs-utils rpcbind
3、创建共享目录:
1.[root@local /]# mkdir /sharestore
4、NFS共享文件路径配置:
编辑/etc/exports添加下面一行,添加后保存退出。
1.[root@local /]# vi /etc/exports
2./sharestore     *(rw,sync,no_root_squash)
5、启动NFS服务(先启动rpcbind,再启动nfs;如果服务器自身已经安装过NFS,那就用restart重启两个服务):
1.[root@local /]# service rpcbind restart
  Starting rpcbind:                                          [  OK  ]
2.[root@local /]# service nfs restart
Starting NFS services:                                     [  OK  ]
Starting NFS quotas:                                       [  OK  ]
Starting NFS mountd:                                       [  OK  ]
Stopping RPC idmapd:                                       [  OK  ]
Starting RPC idmapd:                                       [  OK  ]
Starting NFS daemon:                                       [  OK  ]
[root@local /]#


Note:这里一定要先输入service portmap restart(fedora 10以上为service rpcbind restart)再输入
service nfs restart,因为只有端口开了再开启nfs服务才可以找到端口。




6、设置NFS服务开机自启动:
1.[root@local /]# chkconfig rpcbind on
2.[root@local /]# chkconfig nfs on




三、客户端挂载配置
 
1、创建一个挂载点:
1.[root@localhost ~]# mkdir /mnt/store


2、查看NFS服务器上的共享:
1.[root@localhost /]# showmount -e 192.168.0.10
Export list for 192.168.0.10:
/sharestore *
3、挂载:
1.[root@localhost ~]# mount -t nfs -o nolock 192.168.0.10:/sharestore /mnt/store
例如:mount -t nfs -o nolock 192.168.168.52:/mnt/share /home/miko
如果服务端反复挂载不上,请检查防火墙状态,关闭防火墙

4、查看已挂载共享:
1. [root@localhost ~]# mount 
/dev/mapper/VolGroup-lv_root on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw)
/dev/sda1 on /boot type ext4 (rw)
/dev/mapper/VolGroup-lv_home on /home type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
nfsd on /proc/fs/nfsd type nfsd (rw)
192.168.0.10:/mailstore1/ on /mailstore_new type nfs (rw,vers=4,addr=192.168.0.10,clientaddr=192.


windwos挂载linux主机NFS
启动windos NFS客户端服务:
1. 打开控制面板->程序->打开或关闭windows功能->NFS客户端
勾选NFS客户端,即开启windows NFS客户端服务.
2.win+R->cmd
mount 192.168.1.10:/home/用户/share X:
成功挂载,打开我的点脑,你即可在你网络位置看到 X:盘了
解释: 
mount,是指令
192.168.1.10你的linux主机IP
/home/share你的共享目录
X:你挂载的网络文件盘--注意,可能会与你的其他盘冲突,你可以随意更改
3.取消挂载:
直接在 我的电脑 里面鼠标点击取消映射网络驱动器 X:
或者: win+R->cmd
输入: umount X:
(umount -a 取消所有网络驱动器)


当我们在做NFS开发板下挂载时,经常会出现mount: RPC: Unable to receive; errno = Connection refused的错误,连接被拒绝了,到底是什么原因呢?
这个问题分两方面来解决:
一、当开发板、虚拟机和系统主机可以互相ping通时,如果此时挂载出现这样的错误,可以总结如下:
1、看看nfs服务和portmap(fedora 10以上为rpcbind)端口有没有开,可以用:
service nfs restart和service portmap restart(fedora 10以上为service rpcbind restart)重启看看,
注意,这里一定要先输入service portmap restart(fedora 10以上为service rpcbind restart)再输入
service nfs restart,因为只有端口开了再开启nfs服务才可以找到端口。
2、看看/etc/hosts.allow和/etc/hosts.deny文件,有没有把自己所在的ip拒绝在外,此时deny的文件权利比较
大,即使allow允许了也不一定行。
二、当开发板、虚拟机和系统主机不可以互相ping通时,我们才把这问题解决才去考虑挂载的问题。这一问题
又可以分好多种,首先我们一些基本的要点先说下:
1 、用网线将PC和开发板用网线连接起来
2、 PC的的和开发板的IP地址要重新设置,要在同一网段,这样他们才能组成局域网,才能互相通信,别一味的按照手册上讲的搞个192.168.1.6就完了,要看看自己电脑的IP。
3、关闭电脑的杀毒和安全软件,同时确保系统主机和虚拟机的防火墙都关闭。
4、 PC上面设置IP是在Internet协议属性里面选 使用下面的IP地址,然后自行设置。开发板上设置IP地址并不需要重新烧写文件系统,只需要在SecureCRT里面进行操作就行了,先修改/etc/net.conf文件中的内容,然后执行以下net_set命令即可
http://blog.sina.com.cn/s/blog_740ccd040100zfnx.html
http://www.centoscn.com/CentosSecurity/SoftSecurity/2015/0408/5118.html
http://blog.chinaunix.net/uid-8038341-id-179288.html




CentOS 关闭防火墙
1) 永久性生效,重启后不会复原


开启: chkconfig iptables on


关闭: chkconfig iptables off


2) 即时生效,重启后复原


开启: service iptables start


关闭: service iptables stop


查询TCP连接情况:


 netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'


查询端口占用情况:


 netstat   -anp   |   grep  portno(例如:netstat –apn | grep 80)
0 0