[My Linux, I call the shots! ] Commonly shared storage --NFS service configuration application and actual combat

Contents:
(a) set up a firewall on NFS
(b) to set permissions on NFS
(c) of the NFS-based kerberos


(A) the firewall settings on NFS
NFS (Network File System) that is a network file system, FreeBSD is a supported file system, which allows sharing of resources between computers on the network. In the application of the NFS, the NFS client's local application can transparently read and write files located on a remote NFS server, just like access local files.
NFS the following advantages:
1. save local storage space, the common data stored on an NFS server and can be accessed through the network, then the local terminal itself can be used to reduce storage space.
2. The user is not required on every machine in the network are built Home directory, Home directory can be placed on the NFS server and can be accessed using the network.
3. The number of storage devices such as floppy disks, CDROM and the ZIP (a high-density storage disks and disk drives) and so can be used in other machines on the network. This may reduce the number of removable media devices across the network.
Suppose we have a directory on the server / xx needs to be shared out, we are using nfs service shared out, because nfs service uses port 2049, so the firewall will need to open port 2049 to go out. Meanwhile nfs service is based rpc (remote procedure call) calling service, rpc service is a service on port 111, when the nfs service will be restarted registered rpc service here, so if rpc service does not start properly, then there is no way nfs service normal access to that we also need to open port 111 at the firewall. In the nfs system we encounter multiple clients to mount, in order to avoid multiple users to simultaneously mount a problem, we need to mount a lock to manage this problem, so we need to start mountd service and firewall open the corresponding port.
[My Linux, I call the shots!  ] Commonly shared storage --NFS service configuration application and actual combat
(1.1) will host first in vms001 nfs service, rpc-bind service, mountd service is turned on and writing to the persistent state in the firewall.
[My Linux, I call the shots!  ] Commonly shared storage --NFS service configuration application and actual combat
(1.2) We use systemctl list-unit-files you can view all of the services currently active, you can see rpcbind.service service has been launched, and a static state.
[My Linux, I call the shots!  ] Commonly shared storage --NFS service configuration application and actual combat


(二)关于NFS权限的设置
(2.1)一般nfs服务的配置文件是在/etc/exports文件或者/etc/exports.d/*.exports文件中配置的,且文件的格式如下所示。
[My Linux, I call the shots!  ] Commonly shared storage --NFS service configuration application and actual combat
(2.2)我们在vms001主机上创建一个/data目录,并将/data目录共享出去。
[My Linux, I call the shots!  ] Commonly shared storage --NFS service configuration application and actual combat
[My Linux, I call the shots!  ] Commonly shared storage --NFS service configuration application and actual combat
(2.3)接着创建一个/data目录,并且将exports文件中的设置生效。
[My Linux, I call the shots!  ] Commonly shared storage --NFS service configuration application and actual combat
(2.4)接着在vms002客户端主机上测试vms001主机提供的nfs服务是否正常。在vms002主机上创建一个/nfsdata目录,并将/nfsdata目录挂载到vms001主机共享的data目录下。
[My Linux, I call the shots!  ] Commonly shared storage --NFS service configuration application and actual combat
(2.5)此时我们在vms002主机上尝试使用root身份创建一个文件aaa.txt,发现系统提示权限不够。这是由于在vms001主机上/var/lib/nfs/etab文件中定义了root_squash参数,即压缩root用户的权限,使root用户的权限同anonuid=65534一致。
[My Linux, I call the shots!  ] Commonly shared storage --NFS service configuration application and actual combat
[My Linux, I call the shots!  ] Commonly shared storage --NFS service configuration application and actual combat
(2.6)由于vms001主机上的/data目录的other权限是不可写的,所以给/data目录的o加上w的权限。
[My Linux, I call the shots!  ] Commonly shared storage --NFS service configuration application and actual combat
[My Linux, I call the shots!  ] Commonly shared storage --NFS service configuration application and actual combat
(2.7)如果我们想要以root的身份写入信息,并且不压缩root的权限,则可以在/etc/exports文件中进行设置。
[My Linux, I call the shots!  ] Commonly shared storage --NFS service configuration application and actual combat
[My Linux, I call the shots!  ] Commonly shared storage --NFS service configuration application and actual combat
[My Linux, I call the shots!  ] Commonly shared storage --NFS service configuration application and actual combat
(2.8)此时从vms002主机上向/nfsdata目录中写文件,发现可以正常的写入文件,并且是以root身份写入的。
[My Linux, I call the shots!  ] Commonly shared storage --NFS service configuration application and actual combat
(2.9)由于在/var/lib/nfs/etab文件中默认设置的参数是no_all_squash,如果需要对所有用户都启用压缩权限,则可以在/etc/exports文件中设置all_squash即可。
[My Linux, I call the shots!  ] Commonly shared storage --NFS service configuration application and actual combat
(2.10)设置192.168.26.102主机可读可写,且掩码为32;设置192.168.26.0网段中的主机都只有只读的权限。
[My Linux, I call the shots!  ] Commonly shared storage --NFS service configuration application and actual combat
[My Linux, I call the shots!  ] Commonly shared storage --NFS service configuration application and actual combat
(2.11)在vms002主机的/nfsdata目录下创建一个test102host.txt文件,发现可以正常的创建出对应的文件。
[My Linux, I call the shots!  ] Commonly shared storage --NFS service configuration application and actual combat
(2.12)接着我们在一台IP地址为192.168.26.200的主机上测试,进入到/nfsdata目录后,尝试创建test200host.txt文件,发现并不能创建成功。
[My Linux, I call the shots!  ] Commonly shared storage --NFS service configuration application and actual combat
[My Linux, I call the shots!  ] Commonly shared storage --NFS service configuration application and actual combat
[My Linux, I call the shots!  ] Commonly shared storage --NFS service configuration application and actual combat
(2.13)在vms002主机上将IP地址重新修改为102后,此时就可以正常的创建文件了。
[My Linux, I call the shots!  ] Commonly shared storage --NFS service configuration application and actual combat


(三)基于kerberos的NFS
Kerberos是一种网络认证协议,其设计目标是通过密钥系统为客户机/服务器应用程序提供强大的认证服务。该认证过程的实现不依赖于主机操作系统的认证,无需基于主机地址的信任,不要求网络上所有主机的物理安全,并假定网络上传送的数据包可以被任意地读取、修改和插入数据。在以上情况下,Kerberos作为一种可信任的第三方认证服务,是通过传统的密码技术执行认证服务的。Kerberos又指麻省理工学院为这个协议开发的一套计算机网络安全系统。系统设计上采用客户端/服务器结构与DES加密技术,并且能够进行相互认证,即客户端和服务器端均可对对方进行身份认证。可以用于防止窃听,防止replay破坏、保护数据完整性等场合,是一种应用对称密钥体系进行密钥管理的系统。Kerberos的扩展产品也使公开密钥方法进行认证。
麻省理工研发了kerberos协议来保护ProjectAthena提供的网络服务器。这个协议以希腊神话中的人物kerberos命名,他在希腊神话中是Hades的一条凶猛的三头保卫神犬。
在我们的环境中有一个kerberos服务器,这个服务器我们称之为KDC即密钥分发中心。在我们的环境中有很多的主体,包括机器、service、user、group。现在我们有一台服务器server,还有一个客户端client,如果我们需要基于kerberos来进行保护时,此时KDC会为每一个主体分配一个ticket,很多的信息都是保存在/etc/krb5.keytab文件中的,客户端和服务器都有自己独立的keytab文件。当客户端访问服务器的时候,客户端会出示自己的ticket,此时服务器会使用自己的ticket票据对客户端的ticket合法性做验证,这就是我们整个kerberos的工作流程。在我们的kerberos环境里对时间同步的要求是非常高的,所有机器的时间必须要保持一致,所以我们通过配置NTP服务器可以实现需求。
[My Linux, I call the shots!  ] Commonly shared storage --NFS service configuration application and actual combat
(3.1)我们在vms001主机上使用install.sh脚本创建对应的三台KVM虚拟机,其中host.img(192.168.122.10)对应就是kerberos服务器,system1.img(192.168.122.100)对应的是nfs服务器,system2.img(192.168.122.200)对应的是普通的客户端。
[My Linux, I call the shots!  ] Commonly shared storage --NFS service configuration application and actual combat
[My Linux, I call the shots!  ] Commonly shared storage --NFS service configuration application and actual combat
(3.2)接着从vms001主机上登录到system1主机和system2主机上。
[My Linux, I call the shots!  ] Commonly shared storage --NFS service configuration application and actual combat
[My Linux, I call the shots!  ] Commonly shared storage --NFS service configuration application and actual combat
(3.3)此时host主机除了是一台kerberos服务器外,还是一台LDAP域服务器。
[My Linux, I call the shots!  ] Commonly shared storage --NFS service configuration application and actual combat
(3.4)首先我们在system1主机上创建普通的nfs服务器,并将防火墙相关的端口打开。
[My Linux, I call the shots!  ] Commonly shared storage --NFS service configuration application and actual combat
[My Linux, I call the shots!  ] Commonly shared storage --NFS service configuration application and actual combat
[My Linux, I call the shots!  ] Commonly shared storage --NFS service configuration application and actual combat
[My Linux, I call the shots!  ] Commonly shared storage --NFS service configuration application and actual combat
(3.5)将system2主机上的/aa目录挂载到system1主机上由nfs共享的/aa目录上,是可以正常的实现挂载的。
[My Linux, I call the shots!  ] Commonly shared storage --NFS service configuration application and actual combat
(3.6) We then use to build kerberos nfs server-based services. We need to have to apply for download ticket to host host on host system1 and system2 host.
[My Linux, I call the shots!  ] Commonly shared storage --NFS service configuration application and actual combat
[My Linux, I call the shots!  ] Commonly shared storage --NFS service configuration application and actual combat
(3.7) we create a kerberos-based directory services / kerberosDir on host system1, and edit / etc / exports file.
[My Linux, I call the shots!  ] Commonly shared storage --NFS service configuration application and actual combat
[My Linux, I call the shots!  ] Commonly shared storage --NFS service configuration application and actual combat
(3.8) Since SELinux is turned on, it is then modified context information / kerberosDir of.
[My Linux, I call the shots!  ] Commonly shared storage --NFS service configuration application and actual combat
(3.9) is then provided / etc / sysconfig / nfs nfs4 enforce file version.
[My Linux, I call the shots!  ] Commonly shared storage --NFS service configuration application and actual combat
(3.10) Set / kerberosDir directory on system1 is the main host for the ldapuser1 user and service nfs-server and nfs-secure-server restart the service.
[My Linux, I call the shots!  ] Commonly shared storage --NFS service configuration application and actual combat
[My Linux, I call the shots!  ] Commonly shared storage --NFS service configuration application and actual combat
(3.11) followed by / etc / fstab file on the host computer for editing system2, / aa directory directly linked to the host computer system1 shared / aa directory to the host system2. But on the system2 host / kerberosDir directory to mount on system1 host / kerberosDir directory, attention to the need to write long hostname mounted, and coupled with v4.2 and sec = krb5p parameters.
[My Linux, I call the shots!  ] Commonly shared storage --NFS service configuration application and actual combat
[My Linux, I call the shots!  ] Commonly shared storage --NFS service configuration application and actual combat
(3.12) this time found / kerberosDir directory has been created based on normal mount system2 host kerberos service to host system1 / kerberosDir the directory.
[My Linux, I call the shots!  ] Commonly shared storage --NFS service configuration application and actual combat

Guess you like

Origin blog.51cto.com/13613726/2437982