设为首页 收藏本站
查看: 8938|回复: 1

[经验分享] RHEL7上配置NFS服务

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2015-6-9 08:18:37 | 显示全部楼层 |阅读模式
1.课程目标

    了解什么是NFS及其功能;
    掌握NFS的配置;
    掌握NFS的验证;
    能够单独熟练、灵活运用NFS。

2.NFS概述
NFS(Network Files System),网络文件系统是1980年由SUN发展出来在UNIX&Linux系统间实现磁盘文件共享的一种方法。它是一种文件系统协议:支持应用程序在客户端通过网络存取位于服务器磁盘中的数据。NFS的基本原则是让不同的客户端及服务器通过一组RPCs共享相同的文件系统,它独立于操作系统,允许不同硬件及操作系统的系统共同进行文件的共享。

虽然NFS可以在网络中进行文件共享,但NFS在设计时并没有提供数据传输的功能。需要借助RPC(Remote Procedure Calls,远程过程调用)。RPC定义了一种进程间通过网络进行交互通信的机制,它允许客户端进程通过网络向远程服务进程请求服务,而不需要了解服务器底层的通信协议详细信息。

当一个RPC连接建立开始阶段,客户端建立过程调用,将调用参数发送到远程服务器进程,并等待相应。请求到达时,服务器通过客户端请求的服务,调用指定的程序。并将结果返回客户端。当RPC调用结束,客户端程序将继续进行下一步的通信操作。

NFS依赖RPC与外部通信,为保证NFS服务正常工作,其需要在RPC注册相应的服务端口信息,这样客户端向服务器的RPC提交访问某个服务的请求时,服务器才能够正确作出相应。

注册NFS服务时,需要先开启RPC,才能保证NFS注册成功。并且如果RPC服务重新启动,其保存的信息将丢失,需重新启动NFS服务以注册端口信息,否则客户端将无法访问NFS服务器。

3.NFS主配置文件介绍
NFS的主配置文件路径为:/etc/exports。默认为空,需要手动添加配置参数。

主配置文件书写格式:
共享目录     [客户端(参数)]

说明:

    共享目录:域共享目录的实际路径(要使用绝对路径);
    客户端:定义客户端匹配时可以使用FQDN、IP地址、网段、DNS区域。客户端匹配条件表示方法如下:

NFS客户端匹配
客户端指定方法
   
示例
   
满足示例的客户端
IP指定单一主机
   


   
客户端IP地址为(192.168.1.1)
指定网段
   


   
客户端所在网段为192.168.1.0/24



域名单一主机
   
Nfs.example.com
   
客户端FQDN为nfs.example.com
域名指定范围
   
*.example.com
   
客户端FQDN的DNS后缀为example.com
所有主机
   
*
   
任何访问NFS服务器的客户端

    参数:对满足客户端匹配条件的客户端进行相关配置。可用参数如下(其中匿名用户指的是nfsnobody):

NFS参数
参数
   
说明
ro
   
设置共享为只读,缺省选项
rw
   
设置共享为读写
root_squash
   
当源计算机(NFS客户端)当前用户是root时,将被映射为目标计算机(NFS服务器)的匿名用户
no_root_squash
   
当源计算机(NFS客户端)当前用户是root时,将被映射为目标计算机(NFS服务器)的root用户
all_squash
   
将所有用户映射为目标计算机(NFS服务器)的匿名用户,NFS缺省选项
anonuid
   
设置匿名用户的UID
anongid
   
设置匿名用户的GID
sync
   
保持数据同步,同时将数据写入内存和硬盘,缺省选项
async
   
先将数据保存在内存,然后写入硬盘,效率更高,但可能造成数据丢失
secure
   
NFS客户端必须使用NFS保留端口(1024以下的端口),缺省选项
insecure
   
允许NFS客户端不使用保留端口(1024以下的端口)
wdelay
   
如果NFS服务器怀疑有另一个相关的写请求正在处理或马上就要达到,NFS服务器将延迟提交写请求到磁盘,这就允许使用一个操作提交多个写请求到磁盘,可以改善性能,缺省选项
nowdelay
   
设置了async时该选项无效,NFS服务器将每次写操作写入磁盘

4.NFS服务配置
Redhat Linux中,NFS默认是已经安装的,所以在实验中,只需启动服务即可,不用再安装NFS服务。

4.1.服务的启动
查看服务状态
[iyunv@server30 ~]# systemctl status nfs-service.service
nfs-server.service - NFS Server
   Loaded: loaded (/usr/lib/systemd/system/nfs-server.service; disabled)
   Active: inactive (dead)
缺省没有启动,所以要先启动服务。
[iyunv@server30 ~]# systemctl enable nfs-server.service
//开启下次系统重启自动加载
ln -s '/usr/lib/systemd/system/nfs-server.service' '/etc/systemd/system/nfs.target.wants/nfs-server.service'
[iyunv@server30 ~]# systemctl  restart  nfs-server.service      
[iyunv@server30 ~]# systemctl status nfs
nfs-server.service - NFS Server
   Loaded: loaded (/usr/lib/systemd/system/nfs-server.service; enabled)
   Active: active (exited) since Mon 2015-05-18 13:47:51 CST; 4s ago
  Process: 2035 ExecStart=/usr/sbin/rpc.nfsd $RPCNFSDARGS $RPCNFSDCOUNT (code=exited, status=0/SUCCESS)
  Process: 2031 ExecStartPre=/usr/sbin/exportfs -r (code=exited, status=0/SUCCESS)
  Process: 2030 ExecStartPre=/usr/libexec/nfs-utils/scripts/nfs-server.preconfig (code=exited, status=0/SUCCESS)
Main PID: 2035 (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/nfs-server.service

May 18 13:47:51 server30.example.com systemd[1]: Started NFS Server.

4.2.只读共享目录
例:将server30.example.com(172.16.30.130)上的/public目录通过nfs共享出去,让desktop30.example.com(172.16.30.30)能访问到,并且挂载到本地的public目录,只有可读权限。
----------------------------------------------------server端设置-----------------------------------------------
[iyunv@server30 ~]# mkdir /public
[iyunv@server30 ~]# ls  -ld  /public
drwxr-xr-x. 2 root root 6 May 18 14:07 /public/
//创建共享目录
[iyunv@server30 ~]# cd /public/
[iyunv@server30 public]# touch freeit.txt
[iyunv@server30 public]# ls
freeit.txt
//创建一个文件验证
[iyunv@server30 ~]# vim /etc/exports
/public         172.16.30.130/24(ro,sync)
[iyunv@server30 ~]# systemctl restart nfs-server.service
--------------------------------------------------服务端防火墙允许NFS-------------------------------------
[iyunv@server30 public]# firewall-cmd --list-all
public (default, active)
  interfaces: eno16777736
  sources:
  services: dhcpv6-client ssh
  ports:
  masquerade: no
  forward-ports:
  icmp-blocks:
  rich rules:
//默认不允许NFS*rpc-bind服务
[iyunv@server30 public]# firewall-cmd --add-service=nfs --permanent
success
[iyunv@server30 public]# firewall-cmd --add-service=rpc-bind  --permanent   
success
[iyunv@server30 public]# firewall-cmd --reload
success
[iyunv@server30 public]# firewall-cmd --list-all
public (default, active)
  interfaces: eno16777736
  sources:
  services: dhcpv6-client nfs rpc-bind ssh
  ports:
  masquerade: no
  forward-ports:
  icmp-blocks:
  rich rules:
------------------------------------------------客户端设置--------------------------------------------------------
[iyunv@desktop30 ~]# mkdir /public
[iyunv@desktop30 ~]# mount -t nfs 172.16.30.130:/public /public/
[iyunv@desktop30 ~]# df
Filesystem            1K-blocks    Used Available Use% Mounted on
/dev/mapper/rhel-root   5109760 3021156   2088604  60% /
devtmpfs                 496096       0    496096   0% /dev
tmpfs                    505404      80    505324   1% /dev/shm
tmpfs                    505404    7168    498236   2% /run
tmpfs                    505404       0    505404   0% /sys/fs/cgroup
/dev/sda1                201388  106036     95352  53% /boot
172.16.30.130:/public   5109760 3021440   2088320  60% /public
[iyunv@desktop30 ~]# cd /public/
[iyunv@desktop30 public]# ls
freeit.txt
[iyunv@desktop30 public]# touch gyh
touch: cannot touch ‘gyh’: Read-only file system
如上:ls查看可以看到内容,但是touch时提示只读权限,不能创建。

在配置NFS共享目录完成后,需要重新启动NFS服务,或者通过命令:exports –ar命令使配置生效。也可以通过查看/var/lib/nfs/etab文件显示NFS共享目录的所有参数(包括所有明确配置及未明确配置而使用缺省值的参数)。

查看/var/lib/nfs/etab文件
[iyunv@server30 ~]# cat /var/lib/nfs/etab
/public 172.16.30.0/24(ro,sync,wdelay,hide,nocrossmnt,secure,root_squash,no_all_squash,no_subtree_check,secure_locks,acl,anonuid=65534,anongid=65534,sec=sys,ro,secure,root_squash,no_all_squash)

4.3.可写共享目录
例:接着上个实验,本部分来研究对共享目录的写权限操作。现增加要求,desktop30挂载server30的/public目录后,可以创建文件或目录。具体操作如下:

首先,修改server30上的NFS配置,改ro为rw,让共享出去的文件对访问者可写
[iyunv@server30 ~]# vim /etc/exports
/public         172.16.30.30/24(rw,sync)

重启服务
[iyunv@server30 ~]# systemctl restart nfs-server.service

与Samba一样,共享出去的目录在配置文件中设置可写之外,服务器端的本地文件也要给其可写权限,否则即使配置文件中给了可写参数,客户端挂载之后仍然没有写权限,二者是缺一不可的,所以,下面的配置就是要给服务端的本地共享出去的文件写权限,为方便起见,直接给其777的权限
[iyunv@server30 ~]# chmod  777 /public
[iyunv@server30 ~]# ls -ld /public
drwxrwxrwx. 2 root root 23 May 18 14:12 /public

接下来客户端挂载验证
[iyunv@desktop30 ~]# mount -t nfs 172.16.30.130:/public /public/
[iyunv@desktop30 ~]# df
Filesystem            1K-blocks    Used Available Use% Mounted on
/dev/mapper/rhel-root   5109760 3021512   2088248  60% /
devtmpfs                 496096       0    496096   0% /dev
tmpfs                    505404      80    505324   1% /dev/shm
tmpfs                    505404    7168    498236   2% /run
tmpfs                    505404       0    505404   0% /sys/fs/cgroup
/dev/sda1                201388  106036     95352  53% /boot
172.16.30.130:/public   5109760 3021824   2087936  60% /public
[iyunv@desktop30 ~]# cd /public/
[iyunv@desktop30 public]# ls
freeit.txt
[iyunv@desktop30 public]# touch gyh.txt
[iyunv@desktop30 public]# ls
freeit.txt  gyh.txt
//创建成功,此时具有写权限。

4.4.用户访问权限
同为文件共享服务,NFS对访问用户的控制没有Samba的功能强大,但是基本也可满足日常工作对NFS的需要。NFS中,与访问用户的控制相关的参数主要有:root_squash、no_root_squash、all_squash、anonuid、anongid。下面看几个例子(本部分实验仍然用上部分的实验环境):

例1:查看客户端登录时服务器缺省映射为那个用户
[iyunv@desktop30 public]# ll
total 0
-rw-r--r--. 1 root      root      0 May 18 14:12 freeit.txt
-rw-r--r--. 1 nfsnobody nfsnobody 0 May 18 16:12 gyh.txt
如上:【可写共享目录】实验中创建的文件gyh.txt默认的用户和组为nfsnobody。此为缺省参数all_squash的作用,也就是说,不管客户端以什么身份登录到自己的系统,缺省都映射为nfsnobody。

例2:no_root_squash参数:客户端以本地root身份登录服务器时,也拥有root用户权限
[iyunv@server30 ~]# vim /etc/exports
/public         172.16.30.30/24(rw,no_root_squash,sync)
~                                                                 
[iyunv@server30 ~]# systemctl restart nfs-server.service
如上,客户端以本地root用户登录时,服务器在此参数的作用下把其映射为服务器端的root用户。

例3:anonuid&anongid参数:不论客户端以什么身份登录,缺省都映射为指定用户的UID和指定组的GID。
-------------------------------------------------服务器端设置----------------------------------------------
[iyunv@server30 ~]# id user1
uid=1001(user1) gid=1001(user1) groups=1001(user1)
[iyunv@server30 ~]# vim /etc/exports
/public         172.16.30.30/24(rw,anonuid=1001,anongid=1001,sync)
[iyunv@server30 ~]# systemctl restart nfs-server.service
-------------------------------------------------客户端验证------------------------------------------------
[iyunv@desktop30 public]# touch 456.txt
[iyunv@desktop30 public]# ll
total 0
-rw-r--r--. 1 root      root      0 May 18 17:08 123.txt
-rw-r--r--. 1      1001      1001 0 May 18 17:17 456.txt
-rw-r--r--. 1 root      root      0 May 18 14:12 freeit.txt
-rw-r--r--. 1 nfsnobody nfsnobody 0 May 18 16:12 gyh.txt

4.5.NFS的kerberos验证
本部分以题目的形式来实验。

题目:

    第一部分:主要为server端配置
    在Server30上配置NFS,以读写的方式共享/protected,能被example.com内用户访问;
    访问/protected需要通过kerberos安全加密,可以使用此链接密钥:http://ldap.example.com/pub/server30.keytea;
    目录/protected应该包含名为project拥有人为guest2001的子目录且用户guest2001能以读写方式访问/protected/project;


    第二部分:主要为客户端配置
    在desktop30上挂载来自于server30的nfs共享,/protected挂载在目录/mnt/nfssecure,并使用安全的方式,密钥链接为:http://ldap.example.com/pub/desktop30.keytab;
    挂载为启动时自动挂载;
    用户guest2001能在/mnt/nfssecure/project上创建文件。

第一部分:server端的配置

主配置文件添加共享资源
[iyunv@server30 ~]# vim /etc/exports
/public         172.16.30.30/24(rw,anonuid=1001,anongid=1001)
/protected      172.16.30.0/24(rw,sec=krb5p)
~                                                            
[iyunv@server30 ~]# mkdir /protected
//创建共享目录

配置kerberos验证,需要添加服务器到ldap域中,使用kerberos服务器验证。kerberos验证也需要安装几个工具,然后做添加到LDAP的操作。如下:
[iyunv@server30 ~]# yum -y install authconfig* sssd* krb5*
Loaded plugins: langpacks, product-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
base                                                     | 4.1 kB     00:00     
(1/2): base/group_gz                                       | 134 kB   00:00     
(2/2): base/primary_db                                     | 3.4 MB   00:00     
Package authconfig-6.2.8-8.el7.x86_64 already installed and latest version
Package sssd-client-1.11.2-65.el7.x86_64 already installed and latest version
Package krb5-libs-1.11.3-49.el7.x86_64 already installed and latest version
Resolving Dependencies
[iyunv@server30 ~]# authconfig-gtk
//此命令打开验证配置界面,如下:


wKiom1V1qfHRjx4aAAF41ozhNnA650.jpg
①选择[identity*authentication],进行身份验证配置
②选择【ldap】,加入到ldap域进行验证
③填写ldap的DN,
④填写ldap的路径,要以ldap开头,//后面为ldap服务器的主机名
⑤此处要勾选
⑥点击此处,弹出如下界面,填写证书的密钥链接,下载证书

wKioL1V1q8HjU80KAAGOx6xnPJs886.jpg
①填写链接:http://ldap.example.com/pub/EXAMPLE-CA.crt
②点击【ok】完成证书链设置
wKiom1V1qh_wxF-MAAGMcTAREDs248.jpg ①根据题目要求,这里要选择kerberos验证方式
②填写认证服务的kerberos Realm(域)
③此处的勾选要去掉,否则不能进行下一步操作
④填写认证服务的kerberos KDC
⑤填写认证服务的kerberos Admin Server
⑥点击【Apply】完成认证配置

NFS的版本有许多,Redhat Linux7中的NFS使用版本为4.2,kerberos验证为其特有的验证方式,所以要指明NFS版本,在/etc/sysconfig/nfs配置文件中添加:
[iyunv@server30 ~]# vim /etc/sysconfig/nfs
  1 #
  2 # Optinal options passed to rquotad
  3 RPCRQUOTADOPTS=""
  4 #
  5 # Optional arguments passed to in-kernel lockd
  6 #LOCKDARG=
  7 # TCP port rpc.lockd should listen on.
  8 #LOCKD_TCPPORT=32803
  9 # UDP port rpc.lockd should listen on.
10 #LOCKD_UDPPORT=32769
11 #
12 # Optional arguments passed to rpc.nfsd. See rpc.nfsd(8)
13 RPCNFSDARGS="-V 4.2"
14 # Number of nfs server processes to be started.
15 # The default is 8.
16 RPCNFSDCOUNT=8
17 # Set V4 grace period in seconds
18 #NFSD_V4_GRACE=90
19 #
20 # Optional arguments passed to rpc.mountd. See rpc.mountd(8)
21 RPCMOUNTDOPTS=""
22 #
23 # Optional arguments passed to rpc.statd. See rpc.statd(8)
24 STATDARG=""
25 #
26 # Optional arguments passed to rpc.idmapd. See rpc.idmapd(8)
27 RPCIDMAPDARGS=""
28 #
29 # Optional arguments passed to rpc.gssd. See rpc.gssd(8)
30 RPCGSSDARGS=""
31 # Enable usage of gssproxy. See gssproxy-mech(8).
32 GSS_USE_PROXY="no"
33 #
34 # Optional arguments passed to rpc.svcgssd. See rpc.svcgssd(8)
35 RPCSVCGSSDARGS=""
36 #
37 # Optional arguments passed to blkmapd. See blkmapd(8)
38 BLKMAPDARGS=""
如上:只需在第13行添加-V 4.2即可。

Kerberos验证,需要服务器和客户端的时间上不能有太大的差距,所以,为了保证时间准确,还要指定NTP服务器,如下:
[iyunv@server30 ~]# vim /etc/chrony.conf
  1 # Use public servers from the pool.ntp.org project.
  2 # Please consider joining the pool (http://www.pool.ntp.org/join.html).
  3 #server 0.rhel.pool.ntp.org iburst
  4 #server 1.rhel.pool.ntp.org iburst
  5 #server 2.rhel.pool.ntp.org iburst
  6 #server 3.rhel.pool.ntp.org iburst
  7 server ldap.example.com iburst
……

[iyunv@server30 ~]# systemctl restart chronyd.service
如上,将原有的第4、5、6行注释掉,然后添加第7行内容,指定NTP服务器。最后不要忘记重启chronyd.service服务。

下载用于kerberos验证的密钥
[iyunv@server30 ~]# wget -O /etc/krb5.keytab http://ldap.example.com/pub/server30.keytab
--2015-05-18 18:31:57--  http://ldap.example.com/pub/server30.keytab
Resolving ldap.example.com (ldap.example.com)... 172.16.30.254
Connecting to ldap.example.com (ldap.example.com)|172.16.30.254|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 3026 (3.0K)
Saving to: ‘/etc/krb5.keytab’

100%[======================================>] 3,026       --.-K/s   in 0s      

2015-05-18 18:31:57 (230 MB/s) - ‘/etc/krb5.keytab’ saved [3026/3026]

[iyunv@server30 ~]# ls /etc/krb5.keytab
/etc/krb5.keytab

根据题目要求,在共享资源下创建project目录,并设置guest2001为其拥有者
[iyunv@server30 ~]# mkdir /protected/project
[iyunv@server30 ~]# id guest2001
uid=2001(guest2001) gid=2001(guest2001) groups=2001(guest2001)
[iyunv@server30 ~]# chown guest2001 /protected/project/
[iyunv@server30 ~]# ll /protected/
total 0
drwxr-xr-x. 2 guest2001 root 6 May 18 18:34 project
注:guest2001是加入ldap域后获取的用户,默认本地没有。

最后,对于服务的重启,不仅要重启nfs服务,同时也要重启nfs的另外两个用于安全验证的服务,如下:
[iyunv@server30 ~]# systemctl enable  nfs-server.service nfs-secure-server.service  nfs-secure.service
ln -s '/usr/lib/systemd/system/nfs-secure-server.service' '/etc/systemd/system/nfs.target.wants/nfs-secure-server.service'
ln -s '/usr/lib/systemd/system/nfs-secure.service' '/etc/systemd/system/nfs.target.wants/nfs-secure.service'
[iyunv@server30 ~]# systemctl restart  nfs-server.service nfs-secure-server.service  nfs-secure.service      

[iyunv@server30 ~]# systemctl status  nfs-server.service nfs-secure-server.service  nfs-secure.service        
nfs-server.service - NFS Server
   Loaded: loaded (/usr/lib/systemd/system/nfs-server.service; enabled)
   Active: active (exited) since Mon 2015-05-18 18:43:23 CST; 14s ago
  Process: 5695 ExecStopPost=/usr/sbin/exportfs -f (code=exited, status=0/SUCCESS)
  Process: 5692 ExecStop=/usr/sbin/rpc.nfsd 0 (code=exited, status=0/SUCCESS)
  Process: 5705 ExecStart=/usr/sbin/rpc.nfsd $RPCNFSDARGS $RPCNFSDCOUNT (code=exited, status=0/SUCCESS)
  Process: 5703 ExecStartPre=/usr/sbin/exportfs -r (code=exited, status=0/SUCCESS)
  Process: 5701 ExecStartPre=/usr/libexec/nfs-utils/scripts/nfs-server.preconfig (code=exited, status=0/SUCCESS)
Main PID: 5705 (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/nfs-server.service

May 18 18:43:23 server30.example.com systemd[1]: Starting NFS Server...
May 18 18:43:23 server30.example.com systemd[1]: Started NFS Server.

nfs-secure-server.service - Secure NFS Server
   Loaded: loaded (/usr/lib/systemd/system/nfs-secure-server.service; enabled)
   Active: active (running) since Mon 2015-05-18 18:43:23 CST; 14s ago
  Process: 5723 ExecStart=/usr/sbin/rpc.svcgssd $RPCSVCGSSDARGS (code=exited, status=0/SUCCESS)
Main PID: 5725 (rpc.svcgssd)
   CGroup: /system.slice/nfs-secure-server.service
           └─5725 /usr/sbin/rpc.svcgssd

May 18 18:43:23 server30.example.com systemd[1]: Started Secure NFS Server.

nfs-secure.service - Secure NFS
   Loaded: loaded (/usr/lib/systemd/system/nfs-secure.service; enabled)
   Active: active (running) since Mon 2015-05-18 18:43:23 CST; 14s ago
  Process: 5691 ExecStart=/usr/sbin/rpc.gssd $RPCGSSDARGS (code=exited, status=0/SUCCESS)
Main PID: 5693 (rpc.gssd)
   CGroup: /system.slice/nfs-secure.service
           └─5693 /usr/sbin/rpc.gssd

第二部分:客户端配置

创建本地挂载目录/mnt/nfssecure
[iyunv@desktop30 ~]# mkdir /mnt/nfssecure
[iyunv@desktop30 ~]# ls /mnt/
nfssecure

要进行安全的挂载,也就是使用kerberos验证,所以,客户端同样也要加入到ldap域中,方式与服务器端一样,需要安装三个工具并打开验证配置界面。此处不再赘述。略过。

然后指定NTP服务器,同步时间
[iyunv@desktop30 ~]# vim /etc/chrony.conf

  1 # Use public servers from the pool.ntp.org project.
  2 # Please consider joining the pool (http://www.pool.ntp.org/join.html).
  3 #server 0.rhel.pool.ntp.org iburst
  4 #server 1.rhel.pool.ntp.org iburst
  5 #server 2.rhel.pool.ntp.org iburst
  6 #server 3.rhel.pool.ntp.org iburst
  7 server ldap.example.com iburst

[iyunv@desktop30 ~]# systemctl restart chronyd.service

下载密钥
[iyunv@desktop30 ~]# wget -O /etc/krb5.keytab http://ldap.example.com/pub/desktop30.keytab
--2015-05-18 18:50:00--  http://ldap.example.com/pub/desktop30.keytab
Resolving ldap.example.com (ldap.example.com)... 172.16.30.254
Connecting to ldap.example.com (ldap.example.com)|172.16.30.254|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 3026 (3.0K)
Saving to: ‘/etc/krb5.keytab’

100%[======================================>] 3,026       --.-K/s   in 0s      

2015-05-18 18:50:01 (263 MB/s) - ‘/etc/krb5.keytab’ saved [3026/3026]

[iyunv@desktop30 ~]# ls /etc/krb5.keytab
/etc/krb5.keytab

同样,客户端也需要启动nfs的安全验证服务
[iyunv@desktop30 ~]# systemctl enable nfs-secure.service nfs-secure-server.service
ln -s '/usr/lib/systemd/system/nfs-secure.service' '/etc/systemd/system/nfs.target.wants/nfs-secure.service'
ln -s '/usr/lib/systemd/system/nfs-secure-server.service' '/etc/systemd/system/nfs.target.wants/nfs-secure-server.service'
[iyunv@desktop30 ~]# systemctl restart nfs-secure.service nfs-secure-server.service

自动挂载配置
[iyunv@desktop30 ~]# vim /etc/fstab

#
# /etc/fstab
# Created by anaconda on Thu May  7 11:59:00 2015
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/rhel-root   /                       xfs     defaults        1 1
UUID=bb4bc6a9-f7da-423d-a332-401d21d8d781 /boot                   xfs     defaul
ts        1 2
/dev/mapper/rhel-swap   swap                    swap    defaults        0 0
172.16.30.130:/protected        /mnt/nfssecure  nfs     defaults,v4.2,sec=krb5p
0 0
~  
[iyunv@desktop30 ~]# mount -a
mount.nfs: access denied by server while mounting 172.16.30.130:/protected
//挂载失败               
为什么挂载失败呢?
因为共享资源那里给的是rw权限,但是共享资源本身目录/protected是没有w权限的,所以还要回服务器为共享资源目录本身添加权限
[iyunv@server30 ~]# ll -d /protected/
drwxr-xr-x. 3 root root 20 May 18 18:34 /protected/
[iyunv@server30 ~]# chmod 777 /protected/
[iyunv@server30 ~]# ll -d /protected/   
drwxrwxrwx. 3 root root 20 May 18 18:34 /protected/

客户端再次挂载
[iyunv@desktop30 ~]# mount -a
[iyunv@desktop30 ~]# df
Filesystem               1K-blocks    Used Available Use% Mounted on
/dev/mapper/rhel-root      5109760 3111836   1997924  61% /
devtmpfs                    496096       0    496096   0% /dev
tmpfs                       505404      80    505324   1% /dev/shm
tmpfs                       505404    7172    498232   2% /run
tmpfs                       505404       0    505404   0% /sys/fs/cgroup
/dev/sda1                   201388  106036     95352  53% /boot
172.16.30.130:/protected   5109760 3112064   1997696  61% /mnt/nfssecure
如上:挂载成功。

最后,验证用户guest2001是否能在/mnt/nfssecure/project下创建文件。
查看本地是否有此用户
[iyunv@desktop30 ~]# id guest2001
uid=2001(guest2001) gid=2001(guest2001) groups=2001(guest2001)
因为客户端加入了ldap域,所以获取到LDAP的用户。

连接guest2001用户验证
[iyunv@desktop30 ~]# ssh guest2001@localhost
The authenticity of host 'localhost (::1)' can't be established.
ECDSA key fingerprint is 36:09:b0:56:df:c7:b7:62:5d:66:ea:77:fa:34:64:f0.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'localhost' (ECDSA) to the list of known hosts.
guest2001@localhost's password:
Could not chdir to home directory /rhome/guest2001: No such file or directory
mkdir: cannot create directory ‘/rhome’: Permission denied
-bash-4.2$ cd /mnt/nfssecure/project/
-bash-4.2$ touch abc
-bash-4.2$ ls
Abc
//创建成功,证明有写权限。
注:

    连接guest2001时没有家目录,如果要让其有家目录,要使用autofs挂载此用户家目录到本地;
    验证guest2001具有写权限时,不能直接su到此用户,因为这样服务器会在缺省参数all_squash的作用下把其当成nfsnobody用户。


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-75272-1-1.html 上篇帖子: mac下 xampp+thinkphp的配置方案 下篇帖子: RHEL7上配置DNS服务

尚未签到

发表于 2015-10-16 16:19:19 | 显示全部楼层
kerberos验证这一步一定要做添加到ldap吗?不构建ldap可以吗?

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表