欢迎访问 生活随笔!

生活随笔

当前位置: 首页 >

【CentOS】NFS服务器的安装与配置

发布时间:2025/3/15 39 豆豆
生活随笔 收集整理的这篇文章主要介绍了 【CentOS】NFS服务器的安装与配置 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

一、系统环境

[root@C58-NFS-Client mnt]# cat /etc/redhat-release CentOS release 5.8 (Final) [root@C58-NFS-Client mnt]# uname -r 2.6.18-308.el5 [root@C58-NFS-Client mnt]# uname -m x86_64[root@C58-NFS-Client mnt]# iptables -F #暂时关闭Linux系统防火墙

二、NFS服务器端配置

1、检查nfs与rpc(CentOS5.8中的包名称:portmap)是否在系统中安装(默认是已经安装的了)

[root@C58-NFS-Server data]# rpm -qa nfs* portmap nfs-utils-1.0.9-60.el5 portmap-4.0-65.2.2.1 nfs-utils-lib-1.0.8-7.9.el5#如果未安装,可以执行以下命令进行安装 [root@C58-NFS-Client mnt]# yum install nfs-utils protmap

2、启动rpc服务与nfs服务,并将服务启动项加入到/etc/rc.local中,让其开机自启动

[root@C58-NFS-Server data]# /etc/init.d/portmap start #启动rpc服务 Starting portmap: [ OK ] [root@C58-NFS-Server data]# /etc/init.d/portmap status #检查rpc服务的启动状态 portmap (pid 25567) is running... [root@C58-NFS-Server data]# /etc/init.d/nfs start #启动nfs服务 [root@C58-NFS-Server data]# /etc/init.d/nfs status #检查nfs服务的启动状态 rpc.mountd (pid 25445) is running... nfsd (pid 25442 25441 25440 25439 25438 25437 25436 25435) is running... rpc.rquotad (pid 25416) is running... [root@C58-NFS-Server data]# rpcinfo -p localhost #检测nfs是否向rpc服务注册成功 program vers proto port 100000 2 tcp 111 portmapper 100000 2 udp 111 portmapper 100024 1 udp 946 status 100024 1 tcp 949 status 100011 1 udp 1001 rquotad 100011 2 udp 1001 rquotad 100011 1 tcp 1004 rquotad 100011 2 tcp 1004 rquotad 100003 2 udp 2049 nfs 100003 3 udp 2049 nfs 100003 4 udp 2049 nfs 100021 1 udp 41616 nlockmgr 100021 3 udp 41616 nlockmgr 100021 4 udp 41616 nlockmgr 100003 2 tcp 2049 nfs 100003 3 tcp 2049 nfs 100003 4 tcp 2049 nfs 100021 1 tcp 41579 nlockmgr 100021 3 tcp 41579 nlockmgr 100021 4 tcp 41579 nlockmgr 100005 1 udp 605 mountd 100005 1 tcp 608 mountd 100005 2 udp 605 mountd 100005 2 tcp 608 mountd 100005 3 udp 605 mountd 100005 3 tcp 608 mountd#将rpc与nfs的服务启动项加入到/etc/rc.local中,让其开机自启动[root@C58-NFS-Server data]# echo "#NFS Configure by nowsun" >> /etc/rc.local [root@C58-NFS-Server data]# echo "/etc/init.d/portmap start" >> /etc/rc.local [root@C58-NFS-Server data]# echo "/etc/init.d/nfs start" >> /etc/rc.local [root@C58-NFS-Server data]# cat /etc/rc.local #!/bin/sh # # This script will be executed *after* all the other init scripts. # You can put your own initialization stuff in here if you don't # want to do the full Sys V style init stuff.touch /var/lock/subsys/local #NFS Configure by nowsun /etc/init.d/portmap start /etc/init.d/nfs start

三、配置nfs的配置文件(/etc/exports)

#配置10.0.0.0/24网段的所用服务器能进行/data目录的读写挂载,sync表示直接与硬盘同步 [root@C58-NFS-Server data]# echo "/data 10.0.0.0/24(rw,sync)" >> /etc/exports #重新加载exports文件,使其所配置的内容生效(无须重启rpc和nfs服务) [root@C58-NFS-Server data]# exportfs -rv exporting 10.0.0.0/24:/data#设置/data目录的属主、属组为nfsnobody(nfsnobody的默认使用的账户) [root@C58-NFS-Server data]# chown -R nfsnobody.nfsnobody /data [root@C58-NFS-Server data]# ll -ld /data drwxr-xr-x 2 nfsnobody nfsnobody 4096 Jan 16 22:59 /data#查看自己共享的目录服务 [root@C58-NFS-Server data]# showmount -e localhost Export list for localhost: /data 10.0.0.0/24

/etc/exports配置文件的说明:

[A:输出目录]      [B:客户端1 选项(访问权限,用户映射,其他)]        [C:客户端2 选项(访问权限,用户映射,其他)]


A:输出目录


输出目录是指NFS系统中需要共享给客户机使用的目录;


B: 客户端


指定ip地址的主机:192.168.0.200

指定子网中的所有主机:192.168.0.0/24 192.168.0.0/255.255.255.0

指定域名的主机:data.nowsun.net

指定域中的所有主机:*.nowsun.net

所有主机:*


C:选项


用来设置输出目录的访问权限、用户映射等。

 

NFS主要有3类选项:

访问权限选项:

设置输出目录只读:ro

设置输出目录读写:rw

用户映射选项:

all_squash:将远程访问的所有普通用户及所属组都映射为匿名用户或用户组(nfsnobody);

no_all_squash:与all_squash取反(默认设置);

root_squash:将root用户及所属组都映射为匿名用户或用户组(默认设置);

no_root_squash:与rootsquash取反; anonuid=xxx:将远程访问的所有用户都映射为匿名用户,并指定该用户为本地用户(UID=xxx);

anongid=xxx:将远程访问的所有用户组都映射为匿名用户组账户,并指定该匿名用户组账户为本地用户组账户(GID=xxx);

其他选项:

secure:限制客户端只能从小于1024的tcp/ip端口连接nfs服务器(默认设置);

insecure:允许客户端从大于1024的tcp/ip端口连接服务器;

sync:将数据同步写入内存缓冲区与磁盘中,效率低,但可以保证数据的一致性;

async:将数据先保存在内存缓冲区中,必要时才写入磁盘;

wdelay:检查是否有相关的写操作,如果有则将这些写操作一起执行,这样可以提高效率(默认设置);

no_wdelay:若有写操作则立即执行,应与sync配合使用;

subtree:若输出目录是一个子目录,则nfs服务器将检查其父目录的权限(默认设置);

no_subtree:即使输出目录是一个子目录,nfs服务器也不检查其父目录的权限,这样可以提高效率;

四、客户端配置

[root@C58-NFS-Client /]# showmount -e 10.0.0.9 Export list for 10.0.0.9: /data 10.0.0.0/24 [root@C58-NFS-Client /]# mount -t nfs 10.0.0.9:/data /mnt [root@C58-NFS-Client /]# df -hT Filesystem Type Size Used Avail Use% Mounted on /dev/sda3 ext3 5.2G 2.0G 2.9G 41% / /dev/sda1 ext2 190M 8.0M 173M 5% /boot tmpfs tmpfs 123M 0 123M 0% /dev/shm 10.0.0.9:/data nfs 5.2G 2.0G 2.9G 41% /mnt ===》已经挂载成功咯![root@C58-NFS-Client /]# cd /mnt/ [root@C58-NFS-Client mnt]# touch DataTest [root@C58-NFS-Client mnt]# ll total 4 -rw-r--r-- 1 nfsnobody nfsnobody 0 Jan 16 23:50 DataTest

以上步骤操作完,那NFS的安装与配置就算完成了!~

转载于:https://blog.51cto.com/nowsun/1427333

总结

以上是生活随笔为你收集整理的【CentOS】NFS服务器的安装与配置的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。