Debian下NFS的使用

本文介绍如何通过NFS在网络上的GNU/Linux或Unix系统间快速分享目录。内容包括服务器端配置步骤,如安装必要软件、设置权限及启动服务;客户端配置流程,如安装软件并挂载共享目录。

NFS 简介

如果你想分享一些档案给网络上的GNU/Linux或Unix系统,NFS就是最简单的方法。

速成:分享一个目录(资料夹)

这段是让初学者和不耐烦的人可以快速地使用NFS分享一个目录给网络上其他GNU/Linux或Unix系统。我们假设服务器nfsserver(IP地址为192.168.13.5)要分享目录/var/nfs192.168.13.0 - 192.168.13.255网络上所有计算机使用。

配置NFS服务器

第一步你当然是要在你的NFS服务器nfsserver安装需要的软件。

如果你是使用Debian或Ubuntu,你需要安装以下套件:

  • nfs-common
  • nfs-kernel-server
  • portmap

即是以变身成系统管理员root打:

apt-get install nfs-kernel-server

Fedora或Red Hat使用者请安装以下套件:

nfs-utils

portmap

接着就是告诉NFS服务器你打算分享那些档案和不同计算机有什么权限等,你需要把这些资料写在/etc/exports中。本例是要分享目录/var/nfs给192.168.13.0 - 192.168.13.255网络上所有计算机使用,所要请在/etc/exports加入以下一行:

/var/nfs 192.168.13.0/24(ro)

上面的例子是让192.168.13.0/24网络所有计算机只有阅读/var/nfs的权力。如果你想他们可以更改或删除/var/nfs中的档案,请用rw取代ro,如下:

/var/nfs 192.168.13.0/24(rw)

完成后就要启动NFS服务器,Debian或Ubuntu使用者请打:

/etc/init.d/portmap start /etc/init.d/nfs-common start /etc/init.d/nfs-kernel-server start


RedHat或Fedora使用者请打:

service portmap start service nfs start

启动后,你可以打"showmount -e"检查NFS服务器是否运作正常。

showmount -e

配置NFS客户端
接着是让你的其他计算机连接NFS服务器nfsserver分享出来的目录/var/nfs。同样每个NFS客户端都需要安装有关软件。
Debian或Ubuntu需要安装nfs-common和portmap。即是打:

apt-get install nfs-common

RedHat或Fedora使用者请安装portmap。
安装后请启动有关软件。

/etc/init.d/portmap start /etc/init.d/nfs-common start

你可以打"showmount -e 服务器地址"检查服务器的配置是否正常。

showmount -e 192.168.13.5

现在你可以用"mount -t nfs 服务器地址:目录 挂载点"连接有关目录

mount -t nfs 192.168.13.15:/var/nfs /mnt

日常操作
启动NFS服务器
NFS服务器需要以下列daemon:

portmap

nfsd 或 rpc.nfsd

mountd 或 rpc.mountd

重新加载更动过的配置

exportfs -ra


转自:http://blog.youkuaiyun.com/fg8181/article/details/2326371

### Debian 12 NFS Configuration and Usage #### Installing Necessary Packages To configure NFS on Debian 12, the installation of necessary packages is required. The `nfs-kernel-server` package must be installed to enable NFS server functionality[^1]. This can be done using apt: ```bash sudo apt update sudo apt install nfs-kernel-server ``` #### Configuring Exported Directories The directories that will be shared via NFS need to be specified in `/etc/exports`. Each line in this file represents a directory being exported along with its permissions and options. An example entry might look like this: ```plaintext /exported/directory client_ip(rw,sync,no_subtree_check) ``` This command exports `/exported/directory` to `client_ip`, allowing read-write access while enforcing synchronous writes and disabling subtree checking for performance benefits. #### Starting and Enabling Services After configuring the export list, apply changes by running: ```bash sudo systemctl restart nfs-kernel-server sudo systemctl enable nfs-kernel-server ``` These commands ensure the service starts automatically upon booting up the system. #### Client-Side Setup On the client side, mount points should match those defined within the server's `/etc/exports` configuration. Use the following command to manually mount an NFS share from the server: ```bash sudo mount -t nfs server_ip:/path/to/shared/dir /local/mountpoint ``` For permanent mounting across reboots, add entries into `/etc/fstab`. #### Security Considerations NFS operates over UDP or TCP without built-in security measures such as encryption. Therefore, it’s advisable to restrict network exposure through firewall rules limiting connections only between trusted hosts when deploying NFS setups.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值