| 关键词: nbsp NFS udp tcp mountd root 2049 0.0 portmapper nlockmgr |
NFS服务器配置 NFS(Network File System),网络文件系统。其目的就是使不同机器,不同操作系统可以彼此共享数据文件。但是在Unix Like系统主机之间采用NFS服务器比SAMBA服务器快速和方便许多。NFS服务是RPC(Remote Procedure Call)服务的一种,要使用NFS服务首先要启动RPC(rpcbind)。 1.NFS服务所须要的软件。 RPC主程序: rpcbind rpcbind软件安装后即可运行RPC服务,该服务监听111端口,所有RPC服务比如NFS服务启动的随机端口都要想111端口进行注册(port mapping)。 NFS主程序: nfs-utils 该软件主要提供rpc.nfsd与rpc.mountd这两个NFS daemons与其他相关docments与说明文件、可执行文件等。 2.NFS的软件结构。 主要配置文件:/etc/exports NFS文件系统维护命令: /usr/sbin/exportfs 这个命令用于重新共享/etc/exports更新的目录资源,将NFS Server共享的目录卸载和重新共享等。 共享资源的日志文件:/var/lib/nfs/*tab 其中etab记录目录的完整的权限值,xtab记录连接到NFS Server的相关客户端的数据。 客户端查询服务器共享资源命令: /usr/sbin/showmount 该命令主要用在客户端,用以查看NFS Server共享出来的目录资源。 3.安装NFS服务器相关软件。 yum install rpcbind –y yum install nfs-utils –y 4.启动NFS服务器相关服务。 /etc/init.d/rpcbind start chkconfig rpcbind on /etc/init.d/nfs start chkconfig nfs on /etc/init.d/nfslock start 该服务为可选服务用以在多人单文件情况下保持文件的一致性。 chkconfig nfslock on 如果启动没有问题则观察启动的端口: [root@linux ~]# netstat -tulnp | grep -E '(rpc|nfs)' tcp 0 0 0.0.0.0:875 0.0.0.0:* LISTEN 4472/rpc.rquotad tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 4395/rpcbind tcp 0 0 0.0.0.0:47893 0.0.0.0:* LISTEN 4594/rpc.statd tcp 0 0 0.0.0.0:35871 0.0.0.0:* LISTEN 4488/rpc.mountd tcp 0 0 :::111 :::* LISTEN 4395/rpcbind tcp 0 0 :::52789 :::* LISTEN 4594/rpc.statd udp 0 0 0.0.0.0:875 0.0.0.0:* 4472/rpc.rquotad udp 0 0 0.0.0.0:111 0.0.0.0:* 4395/rpcbind udp 0 0 0.0.0.0:754 0.0.0.0:* 4395/rpcbind udp 0 0 0.0.0.0:38690 0.0.0.0:* 4594/rpc.statd udp 0 0 0.0.0.0:50226 0.0.0.0:* 4488/rpc.mountd udp 0 0 0.0.0.0:954 0.0.0.0:* 4594/rpc.statd udp 0 0 :::111 :::* 4395/rpcbind udp 0 0 :::754 :::* 4395/rpcbind udp 0 0 :::37546 :::* 4594/rpc.statd 使用rpcinfo命令查看本机RPC服务的注册情况。 [root@linux ~]# rpcinfo -p localhost program vers proto port service 100000 4 tcp 111 portmapper 100000 3 tcp 111 portmapper 100000 2 tcp 111 portmapper 100000 4 udp 111 portmapper 100000 3 udp 111 portmapper 100000 2 udp 111 portmapper 100011 1 udp 875 rquotad 100011 2 udp 875 rquotad 100011 1 tcp 875 rquotad 100011 2 tcp 875 rquotad 100003 2 tcp 2049 nfs 100003 3 tcp 2049 nfs 100003 4 tcp 2049 nfs 100227 2 tcp 2049 nfs_acl 100227 3 tcp 2049 nfs_acl 100003 2 udp 2049 nfs 100003 3 udp 2049 nfs 100003 4 udp 2049 nfs 100227 2 udp 2049 nfs_acl 100227 3 udp 2049 nfs_acl 100021 1 udp 46092 nlockmgr 100021 3 udp 46092 nlockmgr 100021 4 udp 46092 nlockmgr 100021 1 tcp 58577 nlockmgr 100021 3 tcp 58577 nlockmgr 100021 4 tcp 58577 nlockmgr 100005 1 udp 50226 mountd 100005 1 tcp 35871 mountd 100005 2 udp 50226 mountd 100005 2 tcp 35871 mountd 100005 3 udp 50226 mountd 100005 3 tcp 35871 mountd 100024 1 udp 38690 status 100024 1 tcp 47893 status 固定NFS服务相关端口 由于NFS服务会随机启用端口,这使得我们无法制定相关防火墙规则,所以要先固定相关端口。 vi /etc/sysconfig/nfs #RQUOTAD_PORT=875 #LOCKD_TCPPORT=32803 #LOCKD_UDPPORT=32769 #MOUNTD_PORT=892 找到以上四行,然后将“#”号去掉。 重启NFS服务。 [root@linux ~]# /etc/init.d/nfs restart 关闭 NFS mountd:[确定] 关闭 NFS 守护进程:[确定] 关闭 NFS quotas:[确定] 启动 NFS 服务: [确定] 关掉 NFS 配额:[确定] 启动 NFS 守护进程:[确定] 启动 NFS mountd:[确定] 再次查看本机nfs端口情况。 [root@linux ~]# rpcinfo -p localhost program vers proto port service 100000 4 tcp 111 portmapper 100000 3 tcp 111 portmapper 100000 2 tcp 111 portmapper 100000 4 udp 111 portmapper 100000 3 udp 111 portmapper 100000 2 udp 111 portmapper 100024 1 udp 38690 status 100024 1 tcp 47893 status 100011 1 udp 875 rquotad 100011 2 udp 875 rquotad 100011 1 tcp 875 rquotad 100011 2 tcp 875 rquotad 100003 2 tcp 2049 nfs 100003 3 tcp 2049 nfs 100003 4 tcp 2049 nfs 100227 2 tcp 2049 nfs_acl 100227 3 tcp 2049 nfs_acl 100003 2 udp 2049 nfs 100003 3 udp 2049 nfs 100003 4 udp 2049 nfs 100227 2 udp 2049 nfs_acl 100227 3 udp 2049 nfs_acl 100021 1 udp 32769 nlockmgr 100021 3 udp 32769 nlockmgr 100021 4 udp 32769 nlockmgr 100021 1 tcp 32803 nlockmgr 100021 3 tcp 32803 nlockmgr 100021 4 tcp 32803 nlockmgr 100005 1 udp 892 mountd 100005 1 tcp 892 mountd 100005 2 udp 892 mountd 100005 2 tcp 892 mountd 100005 3 udp 892 mountd 100005 3 tcp 892 mountd 编写防火墙规则。 [root@linux ~]# vi /etc/sysconfig/iptables -A INPUT -p tcp -m tcp --dport 111 -j ACCEPT -A INPUT -p udp -m udp --dport 111 -j ACCEPT -A INPUT -p tcp -m tcp --dport 2049 -j ACCEPT -A INPUT -p udp -m udp --dport 2049 -j ACCEPT -A INPUT -p tcp -m tcp --dport 875 -j ACCEPT -A INPUT -p udp -m udp --dport 875 -j ACCEPT -A INPUT -p tcp -m tcp --dport 892 -j ACCEPT -A INPUT -p udp -m udp --dport 892 -j ACCEPT -A INPUT -p udp -m udp --dport 32769 -j ACCEPT -A INPUT -p tcp -m tcp --dport 32803 -j ACCEPT [root@linux ~]# /etc/init.d/iptables restart iptables:清除防火墙规则:[确定] iptables:将链设置为政策 ACCEPT:filter [确定] iptables:正在卸载模块:[确定] iptables:应用防火墙规则:[确定] 编辑NFS配置文件。 建立/redhat目录, 仅允许tanhq.com域对该目录有读写权限且若登录用户为root则具有root权限, 其他用户仅有只读权限。 [root@linux ~]# mkdir -p /redhat [root@linux ~]# vi /etc/exports /redhat tanhq.com(rw,sync,no_root_squash) *(ro) [root@linux ~]# /etc/init.d/nfs restart 关闭 NFS mountd:[确定] 关闭 NFS 守护进程:[确定] 关闭 NFS quotas:[确定] 启动 NFS 服务: [确定] 关掉 NFS 配额:[确定] 启动 NFS 守护进程:[确定] 启动 NFS mountd:[确定] 在客户端测试。 首先客户端与服务器端都要安装并启动RPC服务。 [root@client ~]# yum install rpcbind –y [root@client ~]# /etc/init.d/rpcbind start Starting rpcbind: [ OK ] 使用rpcinfo查看是否可以连接到服务器的nfs服务。 [root@client ~]# rpcinfo -p 192.168.0.1 program vers proto port service 100000 4 tcp 111 portmapper 100000 3 tcp 111 portmapper 100000 2 tcp 111 portmapper 100000 4 udp 111 portmapper 100000 3 udp 111 portmapper 100000 2 udp 111 portmapper 100024 1 udp 38690 status 100024 1 tcp 47893 status 100011 1 udp 875 rquotad 100011 2 udp 875 rquotad 100011 1 tcp 875 rquotad 100011 2 tcp 875 rquotad 100003 2 tcp 2049 nfs 100003 3 tcp 2049 nfs 100003 4 tcp 2049 nfs 100227 2 tcp 2049 nfs_acl 100227 3 tcp 2049 nfs_acl 100003 2 udp 2049 nfs 100003 3 udp 2049 nfs 100003 4 udp 2049 nfs 100227 2 udp 2049 nfs_acl 100227 3 udp 2049 nfs_acl 100021 1 udp 32769 nlockmgr 100021 3 udp 32769 nlockmgr 100021 4 udp 32769 nlockmgr 100021 1 tcp 32803 nlockmgr 100021 3 tcp 32803 nlockmgr 100021 4 tcp 32803 nlockmgr 100005 1 udp 892 mountd 100005 1 tcp 892 mountd 100005 2 udp 892 mountd 100005 2 tcp 892 mountd 100005 3 udp 892 mountd 100005 3 tcp 892 mountd 连接正常。 查看挂载目录。nfslock功能客户端与服务器端都需同时启动才可使用。所以再客户端也要安装nfs-utils。 [root@client ~]# yum install nfs-utils -y [root@client ~]# /etc/init.d/nfs start Starting NFS services: [ OK ] Starting NFS quotas: [ OK ] Starting NFS daemon: [ OK ] Starting NFS mountd: [ OK ] Starting RPC idmapd: [ OK ] [root@client ~]# /etc/init.d/nfslock start Starting NFS statd: [ OK ] [root@client ~]# showmount -e 192.168.0.1 Export list for 192.168.0.1: /redhat (everyone) 在客户端挂载nfs服务器目录。 [root@client~]#mount –t nfs –o nosuid,noexec,nodev,rw,bg,soft,rsize=32768,wsize=32768 含义:取消suid功能,挂载分区仅为数据分区,没有执行二级制文件的权限,不保留设备文件的特殊功能,可读写,执行挂载时该挂载行为在后台进行,RPC在超时后重复呼叫,但非持续呼叫。读出和写入区块大小为32768(bytes)。 查看是否成功挂载: [root@client ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda2 8.6G 2.4G 5.8G 29% / tmpfs 244M 24K 244M 1% /dev/shm /dev/sda1 291M 30M 246M 11% /boot /dev/sr0 3.2G 3.2G 0 100% /media/RHEL_6.0 x86_64 Disc 1 192.168.0.1:/redhat 20G 5.8G 13G 31% /mnt/nfs autofs自动挂载 NFS服务器与客户端之间的网络连接可能会断线,任何一方脱机都会造成对方等待超时,NFS服务器上得资源可能不会经常使用,为了能够在有需要时才挂载NFS目录,就要使用autofs自动挂载。在客户端不是有NFS时,目录会被自动卸载。 先卸载之前的手动挂载。 umount -t nfs 192.168.0.1:/redhat 安装并启动autofs服务。 [root@client ~]# yum install autofs –y [root@client ~]# /etc/init.d/autofs start Loading autofs4: [ OK ] Starting automount: [ OK ] 配置autofs自动挂载 [root@client ~]# vi /etc/auto.master /nfsfile /etc/auto.nfs autofs会主动建立/nfsfile目录。如果事先建立该目录可能会出现问题。/etc/auto.nfs这个数据对应文件是不存在的,我们要自行建立,然后再这个文件中指定要挂载的服务器端目录。 [root@client ~]# vi /etc/auto.nfs redhat -rw,bg,soft,rsize=32768,wsize=32768 192.168.0.1:/redhat 重启autofs服务后,会建立/nfsfile/redhat目录。 [root@client ~]# /etc/init.d/autofs stop Stopping automount: [ OK ] [root@client ~]# /etc/init.d/autofs start Starting automount: [ OK ] /nfsfile目录已经被主动建立 [root@client ~]# ll -d /nfsfile drwxr-xr-x. 2 root root 0 Nov 17 12:46 /nfsfile 查看是否自动挂载。 [root@client ~]# cd /nfsfile/redhat [root@client redhat]# mount | grep addr 192.168.0.1:/redhat on /nfsfile/redhat type nfs (rw,soft,rsize=32768,wsize=32768,sloppy,vers=4,addr=192.168.0.1,clientaddr=192.168.0.2) [root@client redhat]# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda2 8.6G 2.4G 5.8G 29% / tmpfs 244M 24K 244M 1% /dev/shm /dev/sda1 291M 30M 246M 11% /boot /dev/sr0 3.2G 3.2G 0 100% /media/RHEL_6.0 x86_64 Disc 1 192.168.0.1:/redhat 20G 5.8G 13G 31% /nfsfile/redhat |
|
声明:文章版权归原作者所有 部分文章转自互联网 如有侵权请联系
[邮箱地址] 删除
|