NFS服务搭建

服务端安装NFS服务步骤:
第一步:安装NFS和rpc。
[root@localhost ~]# yum install -y nfs-utils  #安装nfs服务
[root@localhost ~]# yum install -y rpcbind     #安装rpc服务

 

第二步:启动服务和设置开启启动:

注意:先启动rpc服务,再启动nfs服务
1 [root@localhost ~]# systemctl start rpcbind    #先启动rpc服务
2 [root@localhost ~]# systemctl enable rpcbind   #设置开机启动
3 [root@localhost ~]# systemctl start nfs  #启动nfs服务 
 
#配置防火墙放行
1 [root@localhost /]# firewall-cmd --permanent --add-service=nfs
2 success   
  [root@localhost /]# firewall-cmd  --reload 
3 success
 
第三步:配置共享文件目录
1 /etc/exports    #配置共享目录命令如下
2  共享目录  IP地址,可用*代替, (参数)
3  /public 192.168.245.0/24(ro) 只读
4  /protected 192.168.245.0/24(rw) 读写

 

配置文件说明:
 
参数
作用
ro
只读
rw
读写
root_squash
当NFS客户端以root管理员访问时,映射为NFS服务器的匿名用户
no_root_squash
当NFS客户端以root管理员访问时,映射为NFS服务器的root管理员
all_squash
无论NFS客户端使用什么账户访问,均映射为NFS服务器的匿名用户(常用)
参数:*(rw,all_squash,anonuid=500,anongid=500) 将客户端用户映射为系统uid为500的用户
sync
同时将数据写入到内存与硬盘中,保证不丢失数据
async
优先将数据保存到内存,然后再写入硬盘;这样效率更高,但可能会丢失数据
 
 
NFS客户端挂载配置:
1,使用showmount命令查看nfs服务器共享信息
1 [root@VM6 ~]# showmount -e 10.10.2.7
2 Export list for 10.10.2.7:
3 /mnt/nfs *
showmount命令的用法;
参数
作用
-e
显示NFS服务器的共享列表
-a
显示本机挂载的文件资源的情况NFS资源的情况
-v
显示版本号
 
2,挂载
[root@vm2 nfs]# mount -t nfs 10.1.1.5:/public /root/nfs/
 
 
自动挂载 /etc/fstab
10.1.1.5:/public  /mnt/public  nfs  defaults  0  0
[root@localhost ~]# mount -a #使文件/etc/fstab生效
 
posted @ 2020-11-26 17:13  局域网外  阅读(316)  评论(0编辑  收藏  举报