NFS文件系统服务
一、NFS概述
NFS是一种基于TCP/IP传输的网络文件系统协议,最初由SUN公司开发。
通过NFS协议,客户机可以像访问本地目录一样访问远程服务器中的共享资源。
NFS得到了如NAS等网络存储的设备极好支持。也是LVS共享存储的首选。
二、NFS网络共享存储搭建
1、搭建环境
| 系统类型 | IP地址 | 主机名 | 所需软件 | 
| Centos 7.4 1708 64bi | 192.168.100.101 | nfs | nfs nfs-utils、rpcbind | 
| Centos 7.4 1708 64bi | 192.168.100.102 | client | nfs-utisl、rpcbind、autofs | 
2、搭建步骤
- 服务端安装nfs-utils、rcpbind软件包;
- 服务端设置共享目录;
- 服务器端启动nfs服务程序;
- 客户端安装NFS客户端程序;
- 客户机普通mount方式挂载使用nfs共享;
- 服务端验证存储目录是否成功存储文件:
- 客户端以autofs自动挂载方式进行挂载;
3、服务端安装nfs-utils、rcpbind软件包
##rpcbind软件包提供RPC(远程系统调用)机制支持,nfs软件包提供共享服务
[root@nfs ~]# yum -y install nfs-utils rpcbind 
##设置为开机启动
[root@nfs ~]# for i in rpcbind nfs;do systemctl enable $i; done 服务端设置共享目录
[root@nfs ~]# mkdir /opt/wwwroot
[root@nfs ~]# chmod 777 /opt/wwwroot  				##设置权限
[root@nfs ~]# vi /etc/exports								##nfs配置共享位置的配置文件,新建
/opt/wwwroot	192.168.100.0/24(rw,sync,no_root_squash)
注解:
文件格式:目录 主机(权限)
权限:rw读写  ro只读  sync同步写入  no_root_squash表示客户机以root身份访问时,赋予其本地root权限,默认是root_squash,表示以nfsnobody用户降权使用服务器端启动nfs服务程序
[root@nfs ~]# systemctl start rpcbind				##先启动rpcbind服务,在启动nfs服务
[root@nfs ~]# kill -HUP `cat /run/gssproxy.pid`		##不然启动nfs失败
[root@nfs ~]# systemctl start nfs 查看nfs服务
[root@nfs ~]# netstat -utpln |grep rpc
tcp        0      0 0.0.0.0:20048           0.0.0.0:*               LISTEN      16708/rpc.mountd    
tcp        0      0 0.0.0.0:41884           0.0.0.0:*               LISTEN      16632/rpc.statd     
udp        0      0 0.0.0.0:20048           0.0.0.0:*                           16708/rpc.mountd    
udp        0      0 0.0.0.0:111             0.0.0.0:*                           16611/rpcbind       
udp        0      0 0.0.0.0:670             0.0.0.0:*                           16611/rpcbind       
udp        0      0 127.0.0.1:703           0.0.0.0:*                           16632/rpc.statd     
udp        0      0 0.0.0.0:53500           0.0.0.0:*                           16632/rpc.statd  查看本机共享目录
[root@nfs ~]# showmount -e 192.168.100.101					##查看本机共享的目录
Export list for 192.168.100.101:
/opt/wwwroot 192.168.100.0/244、客户端安装NFS客户端程序;
[root@client ~]# yum -y install nfs-utils rpcbind
[root@client ~]# systemctl start rpcbind
[root@client ~]# kill -HUP `cat /run/gssproxy.pid`				##不然启动nfs失败
[root@client ~]# systemctl start nfs
[root@client ~]# systemctl enable nfs
[root@client ~]# systemctl enable rpcbind
[root@client ~]# showmount -e 192.168.100.101
Export list for 192.168.100.101:
/opt/wwwroot 192.168.100.0/24
[root@client ~]# echo 3 >/proc/sys/vm/drop_caches  	##清除系统的缓存客户机普通mount方式挂载使用nfs共享
[root@client ~]# mkdir /benet
[root@client ~]# mount 192.168.100.101:/opt/wwwroot /benet/
[root@client ~]# mount |grep nfs
192.168.100.101:/opt/wwwroot on /benet type nfs4 (rw,relatime,vers=4.1,rsize=131072,wsize=131072,namlen=255,hard,proto=tcp,port=0,timeo=600,retrans=2,sec=sys,clientaddr=192.168.100.102,local_lock=none,addr=192.168.100.101) 
[root@client ~]# vi /etc/fstab
192.168.100.250:/opt/wwwroot /var/www/html nfs defaults,_netdev 0 0
:wq
注:_netdev表示设备需要网络
[root@client ~]# mount -a
[root@client ~]# touch /benet/1.file
[root@client ~]# ls /benet/
1.file服务端验证存储目录是否成功存储文件:
[root@nfs ~]# ls /opt/wwwroot/
1.file客户端autofs自动挂载方式挂在使用nfs共享
[root@client ~]# umount /benet/
删除/etc/fstab文件中最末尾的挂载一行;
[root@client ~]# tail -1 /etc/fstab 
/dev/mapper/centos_lwh-swap swap          swap    defaults        0 0
[root@client ~]# yum -y install autofs
[root@client ~]# vi /etc/auto.master		##最后一行添加
/benet  /etc/auto.share --timeout=60
注解:/etc/auto.master文件格式
/benet  		/etc/auto.share		 --timeout=60
挂载点目录的第一层       加载第二个autofs的配置文	挂载超时时间
[root@client ~]# vi /etc/auto.share	##创建的文件
a      -fstype=nfs     192.168.100.101:/opt/wwwroot
注解:/etc/auto.share文件格式
a      					 -fstype=nfs    	 192.168.100.101:/opt/wwwroot
挂载点目录的第二层	文件系统格式	挂载的源位置
[root@client ~]# systemctl restart rpcbind
[root@client ~]# kill -HUP `cat /run/gssproxy.pid`
[root@client ~]# systemctl restart nfs
[root@client ~]# systemctl start autofs		##启动autofs,加载挂载关系
[root@client ~]# systemctl enable autofs
[root@client ~]# mount |grep nfs |grep 192.168.100.101
[root@client ~]# ls /benet/
[root@client ~]# ls /benet/a
1.file
[root@client ~]# mount |grep nfs |grep 192.168.100.101
192.168.100.101:/opt/wwwroot on /benet/a type nfs4 (rw,relatime,vers=4.1,rsize=131072,wsize=131072,namlen=255,hard,proto=tcp,port=0,timeo=600,retrans=2,sec=sys,clientaddr=192.168.100.102,local_lock=none,addr192.168.100.101)声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
       
       
                





