如何安装 nfslock 守护进程

如何安装 nfslock 守护进程

我想学习一下我在网上浏览的NFS锁定机制。使用nfslockd或者 rpc.lockd我们可以做到。但在 Debian 中没有软件包。请任何人帮助我我们是否应该在 Debian 中这样做。

答案1

旧版本的 NFS (v2/v3) 可以在没有锁的情况下使用。为了支持锁,服务器上与 nfsd 一起使用了单独的锁定守护进程。

对于 NFSv4(您已经标记了问题),锁定是协议的必需部分,并且 v4 服务不使用单独的锁定守护进程。

如果您有 nfsv4 挂载,您应该能够像锁定本地文件系统上的文件一样锁定文件。

感谢您的评论,我想将文件锁定在服务器本身中,如果一个客户端使用文件,则另一个客户端在第一个客户端发布之前无法访问。我想避免这种类型的竞争条件。

Unix 使用咨询锁定,在客户端而不是文件系统强制执行(Windows 倾向于这样做)。这意味着您的所有客户端都需要参与锁定。

如果您的客户在访问文件之前请求锁定,那么一切都会好起来的。只有在其他客户端释放锁且其他客户端获得锁后。 fcntl本地和 NFS 文件系统通常都支持调用。

看一眼UNIX 中的文件锁定在维基百科上了解一些背景。

答案2

NFS 锁是 NFS 进程的一部分。你不安装它。另外,这并不像你想的那样起作用。如果您使用此功能,则 MUTEX 锁将不会传递到所有服务器。我见过的唯一能做到这一点的软件是 VERITAS。

答案3

我无法具体告诉您 debian,但这是我/etc/sysconfig/nfs来自 SLES 11.4 的文件(我认为它使用的是 NFS v3)。

#    # Path:        Network/File systems/NFS server
#    # Description:     number of threads for kernel nfs server
#    # Type:        integer
#    # Default:     4
#    # ServiceRestart:  nfsserver
#
# the kernel nfs-server supports multiple server threads
#
USE_KERNEL_NFSD_NUMBER="4"

#    # Path:        Network/File systems/NFS server
#    # Description:     use fixed port number for mountd
#    # Type:        integer
#    # Default:     ""
#    # ServiceRestart:  nfsserver
#
#  Only set this if you want to start mountd on a fixed
#  port instead of the port assigned by rpc. Only for use
#  to export nfs-filesystems through firewalls.
#
MOUNTD_PORT=" xxx  "   set to port opened in firewall!

#    # Path:                Network/File systems/NFS server
#    # Description:         GSS security for NFS
#    # Type:                yesno
#    # Default:             yes
#    # ServiceRestart:      nfs nfsserver
#
# Enable RPCSEC_GSS security for NFS (yes/no)
#
NFS_SECURITY_GSS="no"

#    # Path:                Network/File systems/NFS server
#    # Description:         NFSv4 protocol support
#    # Type:                yesno
#    # Default:             yes
#    # ServiceRestart:      nfs nfsserver
#
# Enable NFSv4 support (yes/no)
#
NFS4_SUPPORT="no"

#    # Path:                Network/File systems/NFS server
#    # Description:         NFSv4 server minor version
#    # Type:                integer
#    # Default:             0
#    # ServiceRestart:      nfsserver
#
# Select NFSv4 minor version for server to support (0, 1).
# If '1' is selected, both NFSv4.0 and NFSv4.1 will be supported.
NFS4_SERVER_MINOR_VERSION="0"

#    # Path:                Network/File systems/NFS server
#    # Description:         Network Status Monitor options
#    # Type:                string
#    # Default:             ""
#
# If a fixed port should be used to send reboot notification
# messages to other systems, that port should be given
# here as "-p portnumber".
#
SM_NOTIFY_OPTIONS="-p xxxxx"    set to port opened in firewall

#    # Path:                Network/File systems/NFS server
#    # Description:         Always start NFS services
#    # Type:                yesno
#    # Default:             no
#    # ServiceRestart       nfs
#
# Always start NFS services (gssd, idmapd), not only if
# there are nfs mounts in /etc/fstab.  This is likely to be
# needed if you use an automounter for NFS.
#
NFS_START_SERVICES=""

#    # Path:                Network/File systems/NFS server
#    # Description:         Port rpc.statd should listen on
#    # Type:                integer
#    # Default:             ""
#    # ServiceRestart:      nfsserver
#
# Statd will normally choose a random port to listen on and
# SuSE-Firewall is able to detect which port and allow for it.
# If you have another firewall, you may want to set a fixed
# port number which can then be opened in that firewall.
#
STATD_PORT="xxxxx"     set to port opened in firewall

#    # Path:                Network/File systems/NFS server
#    # Description:         Hostname used by rpc.statd
#    # Type:                string
#    # Default:             ""
#    # ServiceRestart:      nfsserver
#
# statd will normally use the system hostname in status
# monitoring conversations with other hosts.  If a different
# host name should be used, as can be useful with fail-over
# configurations, that name should be given here.
#
STATD_HOSTNAME=""

#    # Path:                Network/File systems/NFS server
#    # Description:     TCP Port that lockd should listen on
#    # Type:                integer
#    # Default:             ""
#    # ServiceRestart:      nfsserver
#
# Lockd will normally choose a random port to listen on and
# SuSE-Firewall is able to detect which port and allow for it.
# If you have another firewall, you may want to set a fixed
# port number which can then be opened in that firewall.
# lockd opens a UDP and a TCP port.  This setting only affect
# the TCP port.
#
LOCKD_TCPPORT="xxxxx"    set to port opened in firewall

#    # Path:                Network/File systems/NFS server
#    # Description:     UDP Port that lockd should listen on
#    # Type:                integer
#    # Default:             ""
#    # ServiceRestart:      nfsserver
#
# Lockd will normally choose a random port to listen on and
# SuSE-Firewall is able to detect which port and allow for it.
# If you have another firewall, you may want to set a fixed
# port number which can then be opened in that firewall.
# lockd opens a UDP and a TCP port.  This setting only affect
# the UDP port.
#
LOCKD_UDPPORT="xxxxx"   set to port opened in firewall

#    # Path:                Network/File systems/NFS server
#    # Description:         Lease time for NFSv4 leases
#    # Type:                integer
#    # Default:             ""
#
# Set the lease time for the NFSv4 server.  This allows new locks
# to be taken sooner after a server restart, so it is useful for
# servers which need to recover quickly after a failure, particularly
# in fail-over configurations.  Reducing the lease time can be a
# problem is some clients connect over high latency networks.
# The default is 90 seconds.  A number like 15 might be appropriate
# in a fail-over configuration with all clients on well connected
# low latency links.
NFSV4LEASETIME=""

#    # Path:                Network/File systems/NFS server
#    # Description:         Alternate mount point for rpc_pipefs filesystem
#    # Type:                string
#    # Default:             ""
#
# In a high-availabilty configuration it is possible that /var/lib/nfs
# is redirected so some shared storage and so it is not convenient to
# mount the rpc_pipefs filesystem at /var/lib/nfs/rpc_pipefs.  In that
# case an alternate mount point can be given here.
RPC_PIPEFS_DIR=""

#    # Path:                Network/File systems/NFS server
#    # Description:         Options for svcgssd
#    # Type:                string
#    # Default:             ""
#
# Normally svcgssd does not require any option.  However in a
# high-availabilty configuration it can be useful to pass "-n"
# to guide the choice of default credential.  To allow for that
# case or any other requiring options ot svcgssd, they can
# be specified here.
SVCGSSD_OPTIONS=""

#    # Path:                Network/File systems/NFS server
#    # Description:         Extra options for nfsd
#    # Type:                string
#    # Default:             ""
#
# This setting allows extra options to be specified for NFSD, such as
# -H <shared_hostname> in a high-availability configuration.
NFSD_OPTIONS=""

#    # Path:                Network/File systems/NFS server
#    # Description:         Extra options for gssd
#    # Type:                string
#    # Default:             ""
#
# Normally gssd does not require any options.  In some circumstances,
# -n, -l or other options might be useful. See "man 8 rpc.gssd" for
# details.  Those options can be set here.
GSSD_OPTIONS=""

#    # Path:                Network/File systems/NFS server
#    # Description:         Extra options for mountd
#    # Type:                string
#    # Default:             ""
#
# Normally mountd does not require any options.  In some circumstances,
# -n, -t, -g or other options might be useful. See "man 8 rpc.mountd" for
# details.  Those options can be set here.
# -p or -N should be set using MOUNTD_PORT or NFS4_SUPPORT rather than
# this option.
MOUNTD_OPTIONS=""

#    # Path:                Network/File systems/NFS server
#    # Description:         Avoid DNS lookups for kerberos principal
#    # Type:                yesno
#    # Default:             no
#    # ServiceRestart:      gssd
#
# Avoid DNS lookups when determining kerberos identity
# of NFS server (yes/no)
# "yes" is safest, but "no" might be needed to preserve
# correct behaviour at sites that don't use
# Fully Qualified Domain Names when mounting NFS Shares.
#
NFS_GSSD_AVOID_DNS="no"

“nfs lock daemon”应该是安装的 nfs 软件包所固有的,并且应该可以正常工作。对 NFS 的依赖是带有rpc.mountdrpc.statd的RPC rpc.lockd。因此,在正确安装 NFS(以及它所需的依赖项,例如 RPC 和 Portmap)后,只要您关闭防火墙或配置为lockd和指定静态端口,它就应该可以工作mountd。如果您不指定静态端口,则 NFS 将选择这些端口随机地每次启动时[在启动期间]。使用防火墙[通常默认情况下处于打开状态],您将永远无法解释这些随机选择的端口号,这将阻止锁定机制每次都无法工作。

请注意,我的信息不适用于 NFSv4。

相关内容