zoukankan      html  css  js  c++  java
  • NFS网络文件系统共享存储

    NFS文件系统服务

    一、NFS概述;

    概述:NFS是一种基于TCP/IP传输的网络文件系统协议,最初由SUN公司开发。
    通过NFS协议,客户机可以像访问本地目录一样访问远程服务器中的共享资源。
    NFS得到了如NAS等网络存储的设备极好支持。也是LVS共享存储的首选。
    

    二、案例:搭建NFS网络共享存储;

    案例环境:
    系统类型 IP地址 主机名 所需软件

    Centos 7.4 1708 64bit 192.168.1.101 nfs nfs-utils、rpcbind
    Centos 7.4 1708 64bit 192.168.1.102 client nfs-utisl、rpcbind、aut

    案例步骤:

    • 服务端安装nfs-utils、rcpbind软件包;

    • 服务端设置共享目录;

    • 服务器端启动nfs服务程序;

    • 客户端安装NFS客户端程序;

    • 客户机普通mount方式挂载使用nfs共享;

    • 服务端验证存储目录是否成功存储文件:

    • 客户端以autofs自动挂载方式进行挂载;

    • 服务端安装nfs-utils、rcpbind软件包

    [root@nfs ~]# yum -y install nfs-utils rpcbind		##rpcbind软件包提供RPC(远程系统调用)机制支持,nfs软件包提供共享服务
    [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 
    [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.1.101					##查看本机共享的目录
    Export list for 192.168.1.101:
    /opt/wwwroot 192.168.100.0/24
    
    • 客户端安装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.1.101
    Export list for 192.168.1.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.1.101:/opt/wwwroot /benet/
    [root@client ~]# mount |grep nfs
    192.168.1.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.1.102,local_lock=none,addr=192.168.1.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.1.101:/opt/wwwroot
    注解:/etc/auto.share文件格式
    a      					 -fstype=nfs    	 192.168.1.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.1.101
    [root@client ~]# ls /benet/
    [root@client ~]# ls /benet/a
    1.file
    [root@client ~]# mount |grep nfs |grep 192.168.1.101
    192.168.1.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.1.102,local_lock=none,addr192.168.1.101)
    
  • 相关阅读:
    css的选择器
    javaScript 的变量使用
    关于外键约束
    javaScript中运算符
    css介绍和三种引入方式
    关于盒子模型
    类和类的六种关系
    DQL和DML更多操作
    javaScript的特点
    关于 让页面中的按钮 响应回车
  • 原文地址:https://www.cnblogs.com/fusheng11711/p/12204387.html
Copyright © 2011-2022 走看看