Third experiment --NFS server configuration

                Third experiment --NFS server configuration

 

Basic experiment information

Experiment name: NFS Server Configuration (3 hours)

 

Experiment time: date

Experimental Location: 606 Laboratory work letter

 

The same group of students:

 

Purpose:

    1. Understand the basic principles of the NFS Service
    2. Master configuration and debugging methods NFS server
    3. Master NFS troubleshooting tips

 

Experimental requirements

 

1, a simple text description, key position shots supplement, NFS configuration file related commands, marked notes.

2, the experimental process, any error, debugging process described in detail.

3, after the completion of the experiment, the experimental results demonstrate the spot.

Experimental procedure described

First, the project needs

A group (Technical Department) to develop a project, all project files are stored in a shared NFS server directories (/ home / project). Claim:

⚫ Technology each member in a shared directory / home / project files belong to the new Technology Group, the owner remains unchanged.

Each member of the files ⚫ Technology can create for other users (root user except) read and write operations, but each user can only delete your files, you can not delete other files created by the user.

Second, simple plan

⚫ permission shared directory / home / project settings: Specify the owning group, to set a mandatory anti-bit and delete bit directory.

⚫ NFS server-side user: zhangsan, lisi belong jishubu group, client users: zhangsan, lisi belong jishubu group, and the NFS server id, group id consistent. (Subscriber Identity overlapping)

⚫ other user settings (except root) of: no_all_squash: shared directory users and groups remain unchanged. Defaults.

⚫ root user settings, use the default values ​​of security, namely: root_squash

root_squash: Log in NFS host using a shared directory if the user is root, then the user's permissions will be compressed into an anonymous user, the UID and GID normally it will become identity nobody (nfsnobody) system account. Defaults.

Third, the server with reference to step

⚫ mounting nfs-utils

⚫ start rpcbind, nfs

⚫ inquiries about the various processes of NFS is functioning correctly:

rpcinfo -p |grep nfs; rpcinfo -p |grep mountd

⚫ add user groups, users,

⚫ 创建共享目录/home/project

⚫ 修改NFS配置文件

Vim /etc/exports

⚫ 重启NFS,或者exportfs –r (重新发布所配置的的共享目录)

⚫ 关闭防火墙、SELinux

⚫ 客户端设置、测试

四、NFS服务器端配置过程

1、安装软件包

  1. yum install -y nfs-utils

2、启动服务

  1. [root@@NFS ~]# systemctl restart rpcbind
  2. [root@@NFS ~]# systemctl restart nfs //修改配置文件后必须重启服务
  3. [root@l@NFS ~]# systemctl enable rpcbind //开启启动
  4. [root@@NFS ~]# systemctl enable nfs //开启启动

3、查询一下NFS 的各个进程是否在正常运行

  1. [root@@NFS ~]# rpcinfo -p |grep nfs
  2. [root@@NFS ~]# rpcinfo -p |grep mountd

// -p(probe,探测)列出所有在host 用portmap 注册的RPC 程序,如果没有指定host,就查找本机上的RPC 程序。

4、添加用户组、用户

  1. [root@@NFS ~]# groupadd jishubu
  2. [root@@NFS ~]# useradd -s /sbin/login -u 1001 -G jishubu zhangsan
  3. [root@@NFS ~]# useradd -s /sbin/login -u 1002 -G jishubu lisi

5、创建共享目录/home/project

  1. [root@@NFS ~]# mkdir /home/project 2
  2. [root@@NFS ~]# chgrp -R jishubu /home/project2
  3. [root@@NFS ~]# chmod 3770 -R /home/project2
  4. [root@@NFS ~]# ll -d /home/project 2
  5. [root@@NFS ~]# cd /home/project 2
  6. [root@@NFS ~]# mkdir laoda //测试
  7. [root@@NFS ~]# touch laoda.t //测试

6、编辑/etc/exports 内容

  1. [root@NFS ~]# vim /etc/exports
  2. /home/project 192.168.40.0/24(rw)

7、重启NFS,或者exportfs –r (重新发布所配置的的共享目录)

  1. [root@xhq project2]# systemctl start rpcbind
  2. [root@xhq project2]# systemctl start nfs
  3. [root@xhq project2]# systemctl enable nfs
  4. [root@xhq project2]# systemctl enable rpcbind

或者

  1. exportfs -arv

注意:如果出现这种情况

[root@xhq etc]# exportfs –v

exportfs: Invalid export syntax: –v

可以键入exportfs –a后再次输入exportfs –rv

 

8、关闭防火墙、SELinux

  1. [root@xhq /]# setenforce 0
  2. [root@xhq /]# systemctl disable firewalld

五、客户端配置

1、安装软件包yum install -y nfs-utils

  1. [root@client /]# yum install -y nfs-utils

2、在客户端查看NFS 服务器共享出来目录

  1. [root@client /]# showmount -e 192.168.2.131

3、挂载/home/project 目录到客户端/mnt/project 目录下

  1. [root@client ~]# mkdir /mnt/project2
  2. [root@client ~]# mount -t nfs 192.168.2.131:/home/project2  /mnt/project2
  3. [root@client ~]# df -hT //查看挂载是否成功

4、客户端创建用户(和服务器端的用户id,组id 保持一致)

  1. [root@cilent ~]# groupadd -g 1002 jishubu
  2. [root@cilent ~]# useradd -u 1001 -G jishubu zhangsan
  3. [root@cilent ~]# useradd -u 1003 -G jishubu lisi

后期修改:

 

说明:对于Linux系统而言,区分不同用户的唯一标识就是uid,至于用户名只是为了方便人类理解。所以在系统层面,无论是zhangsan用户还是lisi用户,只要他们的uid一样,就认为是同一个用户。但也正是因为这个原因,才会导致出现用户身份重叠的问题,对于NFS服务而言,这也是一个比较严重的安全隐患。

5、客户端测试

  1. [root@client ~]# su zhangsan
  2. [zhangsan@client root]$ cd /mnt/project
  3. [zhangsan@client project]$ mkdir zhangsan
  4. [zhangsan@client project]$ touch zhsan.t
  5. [zhangsan@client project]$ su lisi
  6. 密码:
  7. [lisi@client project]$ mkdir lisi
  8. [lisi@client project]$ touch lisi.t

 ​ 

注意:1.如果出现

可以在本地root用户下使用 passwd lisi 重新修改一次密码即可

⚫ 创建的文件及目录都属于jishubu 组。

⚫ 继续测试,lisi 可以修改zhangsan 的文件,但不能删除,与需求相符。

注意:如果可以删除 需要在服务端修改下共享目录的文件夹权限。

6、客户端切换到root 账户,测试发现:

⚫ 分析原因:root 用户的设置,使用默认安全的值,即:root_squash,用户的权限将被压缩成匿名用户,不属于jishubu 组,而/home/project 目录对其他用户没有执行的权限(即进入目录的权限)。

⚫ 修改NFS 服务器的配置文件:

添加:anongid=1000(技术部组的id),实验部分的标准配置如下图所示

注意:不要忘记rw后的“,”否则会报错

说明:anonuid/anongid:要和root_squash 以及all_squash 选项一同使用,用于指定使用NFS 的用户被限定后的uid 和gid,但前提是本机的/etc/passwd 中存在相应的uid 和gid。

7、永久挂载

[root@Client project]# vim /etc/fstab //编辑开启自动挂载文件

回答问题

1、RPC服务重新启动后,为何要重新启动NFS服务?

 

NFS是Network File System的缩写,即网络文件系统,一种使用于分散式文件协定,功能是通过网络让不同的机器、不同的操作系统能够共享个人数据。

NFS在文件传输过程中依赖于RPC协议(Remote Procedure Call,远程过程调用,是使客户端能够执行其他系统中程序的一种机制),NFS本身没有提供信息传输的协议和功能,可以认为它是使用RPC协议的一个程序。

NFS服务器、RPC、客户端三者交互的关系如下图:

 

 

 

 

 

 

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/jiufang/p/12484165.html