nfs服务

NFS -------Network File System 网络文件系统

功能:unix/linux和linux之间文件共享
优点:是局域网共享中速度最快的
缺点:不支持跨平台

什么是网络文件系统?
网络文件系统是一种将远程主机上的目录经过网络挂载到客户端本地系统的一种机制。

环境:
server 192.168.1.252 test1.uplook.com
client 192.168.1.251 client.uplook.com

一、查看软件包是否安装

rpm -qa | grep nfs
nfs-utils-1.3.0-0.33.el7.x86_64 主程序包
rpm -qa | grep rpcbind
rpcbind-0.2.0-38.el7.x86_64 提供rpc协议 用来通信

#yum install nfs-utils rpcbind -y

服务器端:

二、服务端配置要共享的资源

例:服务器共享/test目录,将/dev/sdb1分区挂载在此目录
[root@test1 ~]# parted /dev/sdb mklabel gpt
[root@test1 ~]# parted /dev/sdb mkpart primary 1 3G
[root@test1 ~]# ll /dev/sd
sda sda1 sda2 sdb sdb1
[root@test1 ~]# mkfs.xfs /dev/sdb1
[root@test1 ~]# mkdir /test
[root@test1 ~]# vim /etc/fstab
/dev/sdb1 /test xfs defaults 0 0
[root@test1 ~]# mount -a
[root@test1 ~]# cd /test
[root@test1 test]# echo “nfs test” > test.txt

三、配置共享/test目录
1)配置以只读方式共享
[root@test1 ~]# vim /etc/exports
# man 5 exports
共享资源   共享给谁(共享的属性)
/test  192.168.1.251(ro)
四、重启服务
[root@test1 ~]# systemctl restart nfs-server
[root@test1 ~]# systemctl reload nfs-server   #修改配置文件重新读取  当nfs服务已经启动,可能客户端正在使用,不适合用restart 
[root@test1 ~]# systemctl start rpcbind   
五、查看共享资源
[root@test1 ~]# showmount -e 192.168.1.252
Export list for 192.168.1.252:
/test 192.168.1.251

客户端:

六、查看共享资源
[root@client ~]# showmount -e 192.168.1.252
Export list for 192.168.1.252:
/test 192.168.1.251
七、挂载
语法:mount.nfs 服务器地址:服务器共享的目录  本地的挂载点
[root@client ~]# mount.nfs 192.168.1.252:/test /opt
[root@client ~]# vim /etc/fstab
192.168.1.252:/test  /opt  nfs defaults  0 0
八、查看是否挂载

[root@client ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/mapper/cl-root 17G 3.5G 14G 21% /
devtmpfs 473M 0 473M 0% /dev
tmpfs 489M 144K 489M 1% /dev/shm
tmpfs 489M 7.0M 482M 2% /run
tmpfs 489M 0 489M 0% /sys/fs/cgroup
/dev/sda1 1014M 155M 860M 16% /boot
tmpfs 98M 16K 98M 1% /run/user/0
/dev/sr0 4.1G 4.1G 0 100% /run/media/root/CentOS 7 x86_64
192.168.1.252:/test 2.8G 33M 2.8G 2% /opt

九、测试

[root@client ~]# cd /opt
[root@client opt]# ls
[root@client opt]# mkdir a
mkdir: 无法创建目录"a": 只读文件系统
[root@client opt]# cat test.txt
nfs test

配置/etc/exports

#vim /etc/exports
共享资源 共享给谁(共享的属性)

man 5 exports

共享资源:服务器的目录 
共享给谁:多个主机 之间有空格隔开
    192.168.1.251 某台主机
    192.168.1.0/24 
    192.168.1.0/255.255.255.0
    today.uplook.com 主机名
    *.uplook.com  匹配uplook.com的所有主机
    *       表示任意

共享的属性:文件系统的属性
    ro             只读
    rw            可读写
    async       异步
    sync         同步
    secure      小于1024端口连接
    insecure   大于1024端口连接
    root_squash          把客户端使用root操作的文件的uid和gid映射为匿名用户(nfsnobody)
    no_root_squash    不映射,以管理员root身份操作
    all_squash      把所有用户创建文件的uid和gid都映射为匿名用户 (nfsnobody)

nfs服务器需要安装yum install -y rpcbind nfs-utils这两个软件
客户端需要安装yum install nfs-utils

在服务器上创建分区并且挂载
vim /etc/exports进入配置文件设置
/mnt/sdb2 192.168.10.104(rw,sync,no_root_squash) 192.168.10.1(ro,sync,no_root_squash)
设置格式大概如上
设置好之后开启服务:
systemctl start rpcbind
systemctl start nfs
然后到客户端
showmount -e 192.168.1.252查看共享资源
mount.nfs 192.168.1.252:/test /opt进行挂载
如果有需求就写入开机挂载

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值