原文:https://www.cnblogs.com/burro/p/10444087.html
目标:在服务器A上访问服务器B上指定的文件系统
服务器B配置步骤:
1、编辑/etc/exports
格式:共享目录 指定共享对象(共享参数)
例: /data/nfs 192.168.1.240(rw,sync)
将 /data/nfs 目录 共享给192.168.1.240 ,客户端权限rw
其中共享对象可以用通配符,比如 * 代表所有地址。
配置参数:
rw: 读写
ro :只读
sync:将数据同步写入内存缓冲区与磁盘中,效率低,但可以保证数据的一致性;
async:是大数据时使用,是先写到缓存区,必要时再写到磁盘里。
all_squash:所有访问用户都映射为匿名用户或用户组;
no_all_squash(默认):访问用户先与本机用户匹配,匹配失败后再映射为匿名用户或用户组;
2、查看是否安装rpcbind 和 nfs
rpm -qa |grep nfs
rpm -qa |grep rpcbind
3、使用yum -y install nfs-utils rpcbind命令进行安装 nfs 和 rpcbind
4、关闭防火墙
5、启动服务,一定要先启动rpc再启动nfs
nfs需要向rpc注册,rpc一旦重启,所以注册的文件都丢失,其他向注册的服务都需要重启
启动rpc服务:
systemctl start rpcbind.service
启动nfs服务:
systemctl start nfs.service
查询nfs挂载,showmount -e 192.168.1.240 后面可以接ip来查看。
[root@localhost data]# showmount -eExport list for localhost:/data/nfs 192.168.1.240NFS服务开启后,查看共享目录参数
[root@localhost data]# cat /var/lib/nfs/etab/data/nfs 192.168.1.240(rw,sync,wdelay,hide,nocrossmnt,secure,root_squash,no_all_squash,no_subtree_check,secure_locks,acl,anonuid=65534,anongid=65534,sec=sys,rw,root_squash,no_all_squash)让nfs服务开机启动
[root@localhost ~]# chkconfig rpcbind on[root@localhost ~]# chkconfig nfs on[root@localhost ~]# chkconfig --list rpcbindrpcbind 0:off 1:off 2:on 3:on 4:on 5:on 6:off[root@localhost ~]# chkconfig --list nfsnfs 0:off 1:off 2:on 3:on 4:on 5:on 6:off服务器A配置步骤:
1、查看是否安装rpcbind 和 nfs
2、使用yum -y install nfs-utils rpcbind命令进行安装 nfs 和 rpcbind
3、启动rpcbind,nfs可以不启动
4、客户端挂载nfs共享目录
mount -t nfs4 192.168.1.240:/data/nfs /nfs #挂载服务器B的/data/nfs 目录到服务器A的 /nfs
5、查看磁盘
|
1
2
3
4
5
6
7
8
|
[root@centos68 ~]# df -hFilesystem Size Used Avail Use% Mounted on/dev/sda2 9.5G 2.0G 7.1G 22% /tmpfs 491M 0 491M 0% /dev/shm/dev/sda1 190M 33M 147M 19% /boot/dev/sdb1 4.8G 11M 4.6G 1% /data192.168.1.240:/data/nfs 2.9G 2.7G 126M 96% /nfs # nfs挂载信息 |
注:一般不将nfs挂载信息写入fstab,因为nfs依赖于rpc服务,rpc服务启动晚于fstab时会出错。可以将挂载信息写入 /etc/rc.local
vim /etc/rc.local
mount -t nfs 192.168.1.240:/data/nfs /data/nfs