ubuntu实现nfs开机自动挂载
(2013-03-13 13:00:13)
标签:
it |
现在node1(client)要挂载node2(server)的某个目录(如/home/lee)
/home/lee
node1(insecure,rw,sync,no_root_squash)
Machine Name
Formats
NFS clients may be specified in a number of
ways:
single host
You may specify a host either
by an abbreviated name recognized be the resolver, the
fully qualified domain name, an IPv4 address, or
an IPv6 address. IPv6 addresses must
not be
inside square brackets in /etc/exports lest they
be confused with character-
class wildcard matches.
IP networks
You can also export directories to all hosts on
an IP (sub-) network simultaneously.
This is done
by specifying an IP address and netmask pair as
address/netmask where
the netmask can be specified in
dotted-decimal format,
or as a
contiguous mask
length. For
example, either `/255.255.252.0' or `/22'
appended to the network base
IPv4 address results in identical subnetworks
with 10 bits of host. IPv6
addresses
must use a
contiguous mask length and must
not be inside square brackets to avoid
confusion with character-class wildcards.
Wildcard characters generally do not
work
on IP addresses, though they may work by
accident when reverse DNS lookups fail.
wildcards
Machine names
may contain the wildcard characters * and ?, or
may contain character
class lists within [square brackets].
This can be used to make the exports file
more
compact; for
instance, *.cs.foo.edu matches all hosts in the
domain cs.foo.edu. As
these characters also match the dots in a domain
name, the given pattern will
also
match all hosts within any subdomain of
cs.foo.edu.
netgroups
NIS netgroups may be given as @group.
Only the host part of each netgroup members
is
consider in checking for membership.
Empty host parts or those containing
a single
dash (-) are ignored.
anonymous
This is specified by a single * character (not
to be confused with the wildcard entry
above) and will match all clients.
If a client matches more than one of the
specifications above, then the first match from the
above list order takes
precedence - regardless of the order they appear on the export
line.
However, if a client matches more than one of the
same type of specification (e.g. two net‐
groups), then
the first
match from the order they appear on the export
line takes prece‐
dence.
sudo exportfs -rv ; sudo
/etc/init.d/nfs-kernel-server restart
sudo mount -t nfs -o nolock,tcp
node2(server的名字):/home/lee /mnt/
sudo mount -t nfs -o
nolock,tcp node2(server的名字):/home/lee /mnt/
1.在node2安装nfs-kernel-server:sudo
apt-get install nfs-kernel-server
2.在node1安装nfs-common:sudo apt-get
isntall nfs-common(nfs-kernel-server已经包含这个包)
3.在node2上编辑/etc/exports,主要用来设置服务器的共享目录以及权限,如
node1:node1的名字(如IP,可以man 5
exports指出:
)
insecure/secure:secure为默认值,要求网络端口小于IPPORT_RESERVED(1024),如果存在端口映射之后,端口号大于1024时,不添加insecure字段值就会报mount.nfs:
access denied by server while mounting...的错误
4.刷新配置与开启nfs
5.在node1上挂载node2的/home/lee目录到/mnt下
6.为了能够在开启自动挂载 可以将上述命令:
写入到/etc/rc.local
ps:在/etc/fstab下写入网络挂载的信息,经测试没能开机自动挂载。不过执行sudo mount -a
倒是能够挂载成功。
部分内容来自: