Difference between revisions of "NFS server inside container"
(→warnings) |
|||
(42 intermediate revisions by 24 users not shown) | |||
Line 1: | Line 1: | ||
There are two ways to setup NFS server on common [[HN]]: | There are two ways to setup NFS server on common [[HN]]: | ||
use a user-space NFS server daemon or use an in-kernel implementation | use a user-space NFS server daemon or use an in-kernel implementation | ||
− | of NFS server. | + | of NFS server. |
− | + | ||
+ | {{Note|for information about NFS client inside container, see [[NFS]].}} | ||
== Kernel NFS server == | == Kernel NFS server == | ||
− | + | ||
− | + | Kernel-space NFS server is supported by latest RHEL5 and RHEL6 based kernels and since vzctl-3.0.24. | |
− | + | ||
− | + | NB! Currently only NFSv3 is supported - no NFSv4 support yet. | |
− | + | ||
− | + | === Prerequisites === | |
− | + | In order to run an NFS server inside a container, make sure: | |
+ | * '''nfsd kernel module is loaded on host system before starting a container''' | ||
+ | * '''nfsd feature for a container is turned on''' (<code>vzctl set $CTID --feature nfsd:on --save</code>) | ||
+ | |||
+ | === Setup === | ||
+ | * Make sure that rpcbind service is started before nfs service: | ||
+ | : <code>chkconfig rpcbind on && service rpcbind start</code> | ||
+ | * Disable NFSv4 and nfsd module loading warnings in /etc/sysconfig/nfs by uncommenting the following lines: | ||
+ | MOUNTD_NFS_V3="yes" | ||
+ | RPCNFSDARGS="-N 4" | ||
+ | NFSD_MODULE="noload" | ||
+ | * Start NFS service: | ||
+ | : <code>chkconfig nfs on && service nfs start</code> | ||
+ | |||
+ | === Troubleshooting === | ||
+ | |||
+ | Make sure that: | ||
+ | # you have enabled nfsd feature for your container | ||
+ | # nfsd kernel module is loaded before you started the container | ||
+ | |||
+ | ==== rpcbind ==== | ||
+ | |||
+ | If you see this: | ||
+ | <pre> | ||
+ | # service nfs start | ||
+ | ... | ||
+ | Starting NFS services: [ OK ] | ||
+ | Starting NFS quotas: Cannot register service: RPC: Unable to receive; errno = Connection refused | ||
+ | rpc.rquotad: unable to register (RQUOTAPROG, RQUOTAVERS, udp). | ||
+ | </pre> | ||
+ | |||
+ | It means you haven't started rpcbind service. Solution: | ||
+ | <pre>chkconfig rpcbind on && service rpcbind start</pre> | ||
+ | |||
+ | ==== nfsd module ==== | ||
+ | If you see this: | ||
+ | <pre> | ||
+ | # service nfs start | ||
+ | .... | ||
+ | Starting NFS daemon: rpc.nfsd: Unable to access /proc/fs/nfsd errno 2 (No such file or directory). | ||
+ | Please try, as root, 'mount -t nfsd nfsd /proc/fs/nfsd' and then restart rpc.nfsd to correct the problem | ||
+ | [FAILED] | ||
+ | # mount -t nfsd nfsd /proc/fs/nfsd | ||
+ | mount: unknown filesystem type 'nfsd' | ||
+ | </pre> | ||
+ | |||
+ | It means you haven't loaded nfsd kernel module on host before starting container. | ||
+ | |||
+ | ==== warnings ==== | ||
+ | |||
+ | If you see this: | ||
+ | <pre> | ||
+ | # /etc/init.d/nfs start | ||
+ | FATAL: Module nfsd not found. | ||
+ | FATAL: Error running install command for nfsd | ||
+ | ... | ||
+ | </pre> | ||
+ | |||
+ | It is actually harmless, you don't need to do anything. In case you want this to go away, uncomment (or add) the line | ||
+ | |||
+ | NFSD_MODULE="noload" | ||
+ | |||
+ | in <code>/etc/sysconfig/nfs</code> file. | ||
== User-space NFS server == | == User-space NFS server == | ||
− | Advantage of user-space | + | Advantage of user-space NFS server is that it does not require kernel support. |
− | Also if it crashes | + | Also if it crashes — there is no crash of the system: just one process dies, not the kernel! |
− | The disadvantage of user-space NFS server is its | + | The disadvantage of user-space NFS server is its productivity: no one can be faster than in-kernel implementation. |
One well-known implementation of NFS server is "The LINUX User-Space NFS Server" by Olaf Kirch. | One well-known implementation of NFS server is "The LINUX User-Space NFS Server" by Olaf Kirch. | ||
− | Some Linux distributions contain this package: Debian Sarge (nfs-user-server), | + | Some Linux distributions contain this package: Debian Sarge (<code>nfs-user-server</code>), OpenSUSE 10.0 (<code>nfs-server</code>). |
− | For other | + | For other distributions you can download sources (for example from Debian repository) and compile it. |
− | There is a small trick you have to know about | + | There is a small trick you have to know about running <code>mountd</code> and <code>nfsd</code> (these two daemons and <code>portmap</code> constitute a user-space server). You should run them with the <code>-r</code> option: |
− | user-space server). You should run them with -r option: | ||
<pre> | <pre> | ||
# portmap | # portmap | ||
Line 28: | Line 90: | ||
# rpc.nfsd -r | # rpc.nfsd -r | ||
</pre> | </pre> | ||
− | The reason is that these daemons check major number of device | + | The reason is that these daemons check the major number of the device where the directory to export resides. |
− | If major equals 0 then daemons | + | If major equals 0 then daemons assume that it is NFS and don't want to re-export it. Symptoms are |
− | that | + | that clients will always get a "permission denied" error. Simfs (the file system on which container is located) |
− | is | + | is associated with so called unnamed device, in which major equals 0. So, to prevent daemons from checking for |
− | + | re-exporting — just use this <code>-r</code> option. | |
+ | |||
+ | “The LINUX User-Space NFS Server” by Olaf Kirch implements NFSv2. It means that only files with sizes less | ||
+ | than 2GB are processed. If you intend to use such big files then you should use another user-space NFS server | ||
+ | implementation: [http://unfs3.sourceforge.net/ unfs3]. It implements v3 of NFS protocol standard. | ||
+ | |||
+ | Please note that the user-space NFS server does not provide locking, or at least I couldn't get locking to work - [[User:Elronxenu|Elronxenu]] 19:49, 15 November 2007 (EST) | ||
+ | |||
+ | === On Debian Lenny === | ||
+ | |||
+ | The current stable debian version 5.0 (lenny) provides two packages for user space nfs support: <code>nfs-user-server</code> and <code>unfs3</code>. Here i describe my experiences with them --[[User:Strimo|Strimo]] 17:47, 16 February 2009 (UTC) | ||
+ | |||
+ | It seems that also the unfs3 package has been removed from the debian repositories. --[[Special:Contributions/95.21.175.189|95.21.175.189]] 23:39, 30 July 2011 (UTC) | ||
+ | |||
+ | ==== nfs-user-server ==== | ||
+ | |||
+ | IMPORTANT : read http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=515957 , nfs-user-server was removed | ||
+ | |||
+ | <pre> | ||
+ | aptitude install nfs-user-server | ||
+ | </pre> | ||
+ | |||
+ | First i used nfs-user-server package since i didn't know unfs3. After installing i always got the '''permission denied''' error when i tried to mount any exported path until i found this article. So i patched the /etc/init.d/nfs-user-server file to include the <code>-r</code> parameter by adding <code>-- -r</code> to the <code>start-stop-daemon</code> line responsible for starting <code>rpc.mountd</code> and <code>rpc.nfsd</code>: | ||
+ | |||
+ | <pre> | ||
+ | start-stop-daemon --start --oknodo --quiet --exec /usr/sbin/rpc.nfsd -- -r | ||
+ | start-stop-daemon --start --oknodo --quiet --exec /usr/sbin/rpc.mountd -- -r | ||
+ | </pre> | ||
+ | |||
+ | After the modification and a nfs server restart (<code>/etc/init.d/nfs-user-server restart</code>) i was able to mount a nfs share. At first the nfs server seems to work fine but anytime i want to edit any text file (using nano or mcedit) i got strange errors on writing to the file and i never solved the problem nor detected why this happens. So i switched to unfs3 ... | ||
+ | |||
+ | <b>Note</b>: nfsmount from busybox not works with nfs-user-server in Debian Lenny, it write message "rpc failed: 2" when I try boot from nfs server. unfs3 works fine. | ||
+ | Such problem into Ubuntu: https://bugs.launchpad.net/ubuntu/+source/nfs-user-server/+bug/189593 | ||
+ | |||
+ | ==== unfs3 ==== | ||
+ | |||
+ | <pre> | ||
+ | aptitude install unfs3 | ||
+ | </pre> | ||
+ | |||
+ | Works fine until now. Note that both unfs3 and nfs-user-server do not support file locking! | ||
+ | NOTE: I tested on centos 5.6 using unfs3 and I had to run the /etc/init.d/nfs service and see it work before I could use unfs. also use exports -a before using sudo /usr/sbin/unfsd -T -e /etc/exports | ||
+ | |||
+ | === On CentOS 5 === | ||
− | + | If you are running RedHat/CentOS, you can [http://dag.wieers.com/rpm/packages/unfs3/ get unfs3 from the DAG repository] | |
− | |||
− | |||
+ | == External links == | ||
+ | * [http://nfs.sourceforge.net/ Linux NFS Overview, FAQ and HOWTO Documents] | ||
+ | * [http://www.tldp.org/LDP/nag/nag.html The Network Administrators' Guide by Olaf Kirch] | ||
+ | * [http://unfs3.sourceforge.net/ unfs3 homepage] | ||
+ | * [http://packages.qa.debian.org/n/nfs-user-server.html Overview of nfs-user-server source package] | ||
[[Category: HOWTO]] | [[Category: HOWTO]] | ||
[[Category: Networking]] | [[Category: Networking]] |
Latest revision as of 18:01, 4 August 2021
There are two ways to setup NFS server on common HN: use a user-space NFS server daemon or use an in-kernel implementation of NFS server.
Note: for information about NFS client inside container, see NFS. |
Contents
Kernel NFS server[edit]
Kernel-space NFS server is supported by latest RHEL5 and RHEL6 based kernels and since vzctl-3.0.24.
NB! Currently only NFSv3 is supported - no NFSv4 support yet.
Prerequisites[edit]
In order to run an NFS server inside a container, make sure:
- nfsd kernel module is loaded on host system before starting a container
- nfsd feature for a container is turned on (
vzctl set $CTID --feature nfsd:on --save
)
Setup[edit]
- Make sure that rpcbind service is started before nfs service:
chkconfig rpcbind on && service rpcbind start
- Disable NFSv4 and nfsd module loading warnings in /etc/sysconfig/nfs by uncommenting the following lines:
MOUNTD_NFS_V3="yes" RPCNFSDARGS="-N 4" NFSD_MODULE="noload"
- Start NFS service:
chkconfig nfs on && service nfs start
Troubleshooting[edit]
Make sure that:
- you have enabled nfsd feature for your container
- nfsd kernel module is loaded before you started the container
rpcbind[edit]
If you see this:
# service nfs start ... Starting NFS services: [ OK ] Starting NFS quotas: Cannot register service: RPC: Unable to receive; errno = Connection refused rpc.rquotad: unable to register (RQUOTAPROG, RQUOTAVERS, udp).
It means you haven't started rpcbind service. Solution:
chkconfig rpcbind on && service rpcbind start
nfsd module[edit]
If you see this:
# service nfs start .... Starting NFS daemon: rpc.nfsd: Unable to access /proc/fs/nfsd errno 2 (No such file or directory). Please try, as root, 'mount -t nfsd nfsd /proc/fs/nfsd' and then restart rpc.nfsd to correct the problem [FAILED] # mount -t nfsd nfsd /proc/fs/nfsd mount: unknown filesystem type 'nfsd'
It means you haven't loaded nfsd kernel module on host before starting container.
warnings[edit]
If you see this:
# /etc/init.d/nfs start FATAL: Module nfsd not found. FATAL: Error running install command for nfsd ...
It is actually harmless, you don't need to do anything. In case you want this to go away, uncomment (or add) the line
NFSD_MODULE="noload"
in /etc/sysconfig/nfs
file.
User-space NFS server[edit]
Advantage of user-space NFS server is that it does not require kernel support. Also if it crashes — there is no crash of the system: just one process dies, not the kernel! The disadvantage of user-space NFS server is its productivity: no one can be faster than in-kernel implementation.
One well-known implementation of NFS server is "The LINUX User-Space NFS Server" by Olaf Kirch.
Some Linux distributions contain this package: Debian Sarge (nfs-user-server
), OpenSUSE 10.0 (nfs-server
).
For other distributions you can download sources (for example from Debian repository) and compile it.
There is a small trick you have to know about running mountd
and nfsd
(these two daemons and portmap
constitute a user-space server). You should run them with the -r
option:
# portmap # rpc.mountd -r # rpc.nfsd -r
The reason is that these daemons check the major number of the device where the directory to export resides.
If major equals 0 then daemons assume that it is NFS and don't want to re-export it. Symptoms are
that clients will always get a "permission denied" error. Simfs (the file system on which container is located)
is associated with so called unnamed device, in which major equals 0. So, to prevent daemons from checking for
re-exporting — just use this -r
option.
“The LINUX User-Space NFS Server” by Olaf Kirch implements NFSv2. It means that only files with sizes less than 2GB are processed. If you intend to use such big files then you should use another user-space NFS server implementation: unfs3. It implements v3 of NFS protocol standard.
Please note that the user-space NFS server does not provide locking, or at least I couldn't get locking to work - Elronxenu 19:49, 15 November 2007 (EST)
On Debian Lenny[edit]
The current stable debian version 5.0 (lenny) provides two packages for user space nfs support: nfs-user-server
and unfs3
. Here i describe my experiences with them --Strimo 17:47, 16 February 2009 (UTC)
It seems that also the unfs3 package has been removed from the debian repositories. --95.21.175.189 23:39, 30 July 2011 (UTC)
nfs-user-server[edit]
IMPORTANT : read http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=515957 , nfs-user-server was removed
aptitude install nfs-user-server
First i used nfs-user-server package since i didn't know unfs3. After installing i always got the permission denied error when i tried to mount any exported path until i found this article. So i patched the /etc/init.d/nfs-user-server file to include the -r
parameter by adding -- -r
to the start-stop-daemon
line responsible for starting rpc.mountd
and rpc.nfsd
:
start-stop-daemon --start --oknodo --quiet --exec /usr/sbin/rpc.nfsd -- -r start-stop-daemon --start --oknodo --quiet --exec /usr/sbin/rpc.mountd -- -r
After the modification and a nfs server restart (/etc/init.d/nfs-user-server restart
) i was able to mount a nfs share. At first the nfs server seems to work fine but anytime i want to edit any text file (using nano or mcedit) i got strange errors on writing to the file and i never solved the problem nor detected why this happens. So i switched to unfs3 ...
Note: nfsmount from busybox not works with nfs-user-server in Debian Lenny, it write message "rpc failed: 2" when I try boot from nfs server. unfs3 works fine. Such problem into Ubuntu: https://bugs.launchpad.net/ubuntu/+source/nfs-user-server/+bug/189593
unfs3[edit]
aptitude install unfs3
Works fine until now. Note that both unfs3 and nfs-user-server do not support file locking! NOTE: I tested on centos 5.6 using unfs3 and I had to run the /etc/init.d/nfs service and see it work before I could use unfs. also use exports -a before using sudo /usr/sbin/unfsd -T -e /etc/exports
On CentOS 5[edit]
If you are running RedHat/CentOS, you can get unfs3 from the DAG repository