nfs详解从0-1

NFS工作流程

服务端:
1、启动RPC服务
2、开启111端口
客户端:
1、建立tcp网络
2、建立远程挂载
3、实现数据远程输出存储

NFS部署流程

1、安装NFS和RPC
服务端:

[root@nfs01 ~]#yum install -y nfs-utils rpcbind

客户端:

[root@nfs01 ~]#yum install -y nfs-utils

2、编写NFS服务配置文件

[root@nfs01 ~]#vim /etc/exports
/data   172.16.1.0/24(rw,sync)

(1)、/data代表设置数据存储的目录
(2)、172.16.1.0/24代表网络的白名单
(3)、()里面的代表配置存储目录的权限信息,存储目录的一些功能

3、创建共享目录

[root@nfs01 ~]#mkdir /data		#要与配置文件里的名称对应

4、改变属主和属组

[root@nfs01 ~]#chown nfsnobody.nfsnobody /data

5、启动服务程序
ps:先启动rpc,再启动nfs

systemctl start rpcbind.service
systemctl enable rpcbind.service
systemctl start nfs
systemctl enable nfs

6、客户端
(1)、安装nfs服务

[root@web01 ~]yum install -y nfs-utils

(2)、挂载共享目录

[root@web01 ~]mount -t nfs 172.16.1.31:/data /mnt
[root@web01 ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
devtmpfs                 475M     0  475M   0% /dev
tmpfs                    487M     0  487M   0% /dev/shm
tmpfs                    487M  7.8M  479M   2% /run
tmpfs                    487M     0  487M   0% /sys/fs/cgroup
/dev/mapper/centos-root   17G  1.8G   16G  11% /
/dev/sda1               1014M  168M  847M  17% /boot
172.16.1.31:/data         17G  1.8G   16G  11% /mnt
tmpfs                     98M     0   98M   0% /run/user/0

NFS工作原理

服务端:

启动RPC
启动NFS
NFS的一些信息向RPC进行注册
RPC端口111

客户端:

建立tcp连接
执行挂载命令
实现数据远程输出存储

NFS服务端详细配置说明

1、实现多个网段主机可以进行挂载

[root@nfs01 ~]#vim /etc/exports
/data   172.16.1.0/24(rw,sync) 10.0.0.0/24(rw,sync)

/data   172.16.1.0/24(rw,sync)
/data	10.0.0.0/24(rw,sync)

NFS配置参数权限

rw --存储目录是否有读写权限
ro --存储目录是否有只读权限
sync --同步方式存储数据
async --同步方式存储数据
no_root_squash --不要将root用户身份进行转换
root_squash --将root用户身份进行转换
all_squash --将所有用户身份都进行转换
no_all_squash --不要将普通用户身份进行转换

演示squash参数操作:
1、all_squash

[root@nfs01 ~]#vim /etc/exports
/data   172.16.1.0/24(rw,sync,all_squash)
[kyrie@web01 mnt]$ touch kyrie_data.txt
[kyrie@web01 mnt]$ ll
-rw-rw-r-- 1 nobody nobody 0 Jul 12 11:32 kyrie_data.txt

ps:将所有用户都转换为nobody

2、no_all_squash

[root@nfs01 ~]#vim /etc/exports
/data   172.16.1.0/24(rw,sync,no_all_squash)
[kyrie@web01 mnt]$ touch kyrie_01_data.txt
touch: cannot touch ‘kyrie_01_data.txt’: Permission denied

ps:当不转换用户身份时,属主和属组还是nobody,普通用户无法操作。
3、root_squash

[root@nfs01 ~]#vim /etc/exports
/data   172.16.1.0/24(rw,sync,root_squash)
[root@web01 mnt]# touch root_data.txt
[root@web01 mnt]# ll
total 0
-rw-rw-r-- 1 nobody nobody 0 Jul 12 11:32 kyrie_data.txt

ps:将root用户转换为nobody
4、no_root_squash

[root@nfs01 ~]#vim /etc/exports
/data   172.16.1.0/24(rw,sync,no_root_squash)
[root@web01 mnt]# touch root_01_data.txt
[root@web01 mnt]# ll
total 0
-rw-r--r-- 1 root   root   0 Jul 12 11:41 root_01_data.txt

ps:不把root用户创建的文件转换为nobody用户

NFS实战操作

如何配置nfs?普通用户也不能删文件?只能指定的用户可以删除?

修改默认的匿名用户,默认为nobody用户,如要指定只能web服务器传输文件到nfs服务器。

环境准备:
/data 172.16.1.0/24(rw,sync,anonuid=1001,anongid=1001,root_squash,no_all_squash)

[root@web01 mnt]# id www
uid=1001(www) gid=1001(www) groups=1001(www)
[root@nfs01 data]# id www
uid=1001(www) gid=1001(www) groups=1001(www)
[root@nfs01 ~]# ll /data -d
drwxr-xr-x 2 www www 73 Jul 12 11:41 /data

服务端root用户:

[root@web01 mnt]# touch web01_data.txt
[root@web01 mnt]# 
[root@web01 mnt]# ll
total 0
-rw-r--r-- 1 www  www  0 Jul 12 13:43 web01_data.txt

非root用户:

[root@web01 mnt]# su kyrie
[kyrie@web01 mnt]$ pwd
/mnt
[kyrie@web01 mnt]$ touch kyrie_data.txt
touch: cannot touch ‘kyrie_data.txt’: Permission denied

指定www用户:

[root@web01 mnt]# su www
[www@web01 mnt]$ pwd
/mnt
[www@web01 mnt]$ touch www1_data.txt
[www@web01 mnt]$ ll
total 0
-rw-rw-r-- 1 www  www  0 Jul 12 13:49 www1_data.txt

NFS服务问题

nfs服务器重启,挂载后创建数据比较慢,服务器重启方式不正确。
reload 与 restart
restart 重启服务,强制断开所有连接 。
reload 平滑重启,强制断开没有数据传输的连接。

如何实现自动挂载?
1、利用rc.local

echo "mount -t nfs 172.16.1.31:/data /mnt">>/etc/rc.local

2、利用/etc/fstab

172.16.1.31:/data       /mnt    nfs     defaults        0 0 

NFS服务挂载不上排查方法

服务端进行排查

1、检查nfs进程信息是否注册
rpcinfo -p localhost
一般是服务启动顺序不对,要先启动RPC再启动NFS。
2、检查存储目录是否可用

[root@nfs01 data]# cat /etc/exports
/data	172.16.1.0/24(rw,sync,anonuid=1001,anongid=1001,root_squash,no_all_squash)
[root@nfs01 data]# showmount -e 172.16.1.31
Export list for 172.16.1.31:
/data 172.16.1.0/24

3、在服务端进行挂载测试
是否能够在存储目录中创建或者删除数据

[root@nfs01 data]# mount -t nfs 172.16.1.31:/data /mnt
[root@nfs01 data]# 
[root@nfs01 data]# df -h
Filesystem               Size  Used Avail Use% Mounted on
devtmpfs                 475M     0  475M   0% /dev
tmpfs                    487M     0  487M   0% /dev/shm
tmpfs                    487M  7.7M  479M   2% /run
tmpfs                    487M     0  487M   0% /sys/fs/cgroup
/dev/mapper/centos-root   17G  1.8G   16G  11% /
/dev/sda1               1014M  168M  847M  17% /boot
tmpfs                     98M     0   98M   0% /run/user/0
172.16.1.31:/data         17G  1.8G   16G  11% /mnt

客户端进行排查

是否能够NFS服务端通信。

下篇文章:实时同步数据

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值