码迷,mamicode.com
首页 > 其他好文 > 详细

NFS服务基本配置

时间:2016-10-28 00:08:07      阅读:339      评论:0      收藏:0      [点我收藏+]

标签:配置文件   客户端.nfs.rpcbind.linux.   

一安装启动:

先检查有没有安装过NFS服务的包:rpm -aq nfs-utils rpcbind

没有的话就进行安装:yum install nfs-utils rpcbind -y

然后进入NFS的配置文件里写入需要共享的文件及其权限和共享客户端的范围:

[root@NFS-SERVER ~]# cat /etc/exports

/data/r_shared 192.168.20.0/24(ro,sync)

/data/w_shared 192.168.20.0/24(rw,sync)

然后先启动rpcbind,再启动nfs要先启动rpcbind服务再启动nfs服务否则倒过来的话会导致nfsbind学习不到nfs的共享。

/etc/init.d/rpcbind start

/etc/init.d/nfs start

也可以把这两条命令加入/etc/rc.local开机启动时自启动

[root@NFS-SERVER ~]# 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

>/etc/udev/rules.d/70-persistent-net.rules

/etc/init.d/rpcbind start

/etc/init.d/nfs start

chkconfig启动rpcbindnfs

chkconfig rpcbind on

chkconfig nfs on

chkconfig --list rpcbindnfs查看有没有启动

问题?要求rpcbind服务要先启动于nfs服务,现在两个都启动要怎么解决rpcbind先启动?

技术分享

技术分享

rpcbind的启动号比nfs小,所以两个一起打开的时候rpcbind自然会比nfs先启动

查看rpc里面有没有东西用:rpcinfo -p localhost

里面就是存放nfs给的东西

[root@NFS-SERVER ~]#  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

    100005    1   udp  50653  mountd

    100005    1   tcp  55661  mountd

    100005    2   udp  35917  mountd

    100005    2   tcp  39194  mountd

    100005    3   udp  49181  mountd

    100005    3   tcp  47489  mountd

    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  40329  nlockmgr

    100021    3   udp  40329  nlockmgr

    100021    4   udp  40329  nlockmgr

    100021    1   tcp  45731  nlockmgr

    100021    3   tcp  45731  nlockmgr

    100021    4   tcp  45731  nlockmgr

    100024    1   udp  35464  status

    100024    1   tcp  55621  status

二、配置

1、配置文件定义

NFS的配置文件为 /etc/exports,内容格式如下:

<共享目录> 客户端1(选项) [客户端2(选项) ...]

 共享目录:NFS共享给客户机的目录。

 客户端:网络中可以访问此目录的主机。多个客户端以空格分隔。

 选项:设置目录的访问权限、用户映射等,多个选项以逗号分隔。

例如:

/data/r_shared 192.168.20.0/24(rw,insecure,sync,all_squash,anonuid= 65534,anongid=65534)

2、客户端的指定方式

指定ip地址的主机:192.168.02.100

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

指定域名的主机:nfs.test.com

指定域中的所有主机:*.test.com

所有主机:*

 

3、选项说明

ro:共享目录只读;

rw:共享目录可读可写;

all_squash:所有访问用户都映射为匿名用户或用户组;

no_all_squash(默认):访问用户先与本机用户匹配,匹配失败后再映射为匿名用户或用户组;

root_squash(默认):将来访的root用户映射为匿名用户或用户组;

no_root_squash:来访的root用户保持root帐号权限;

anonuid=<UID>:指定匿名访问用户的本地用户UID,默认为nfsnobody65534);

anongid=<GID>:指定匿名访问用户的本地用户组GID,默认为nfsnobody65534);

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

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

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

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

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

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

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

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

如我的配置是:

[root@NFS-SERVER ~]# cat /etc/exports

/data/r_shared 192.168.20.0/24(ro,sync)

/data/w_shared 192.168.20.0/24(rw,sync)

 

配置好之后重启下rpcbindnfs服务:(注意重启前你所要共享的那两个目录得先存在没有的话要先创建

 mkdir -p /data/r_shared

mkdir -p /data/w_shared )

/etc/init.d/rpcbind restart

 /etc/init.d/nfs restart

 

 

三,测试

现在本地挂载试下有没有错误:

mount -t nfs 192.168.20.6:/data/r_shared /mnt

[root@NFS-SERVER ~]# df -h

Filesystem            Size  Used Avail Use% Mounted on

/dev/sda3              18G  1.2G   16G   8% /

tmpfs                 504M     0  504M   0% /dev/shm

/dev/sda1             190M   48M  132M  27% /boot

192.168.20.6:/data/r_shared

                       18G  1.2G   16G   8% /mnt

表示挂载成功

 

四,到客户端安装NFS服务

先检查有没有安装过NFS服务的包:rpm -aq nfs-utils rpcbind

没有的话就进行安装:yum install nfs-utils rpcbind -y

然后开启rpcbind的服务:

/etc/init.d/rpcbind start

也可以加入开机自启动里面:

[root@lnmp01 ~]# 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

>/etc/udev/rules.d/70-persistent-net.rules

/etc/init.d/rpcbind start

查看有没有启动成功

[root@lnmp01 ~]# /etc/init.d/rpcbind status

rpcbind (pid  2561) 正在运行...

然后开始挂载:

mount -t nfs 192.168.20.6:/data/r_shared /mnt

[root@lnmp01 ~]# mount -t nfs 192.168.20.6:/data/r_shared /mnt

mount.nfs: Connection timed out

出现这个问题一般是防火墙没有关闭

暂时关闭防火墙,重启后失效的命令是:

service iptables stop

查看防护墙状态的命令 是:

 service iptables status

想永久的关闭防火墙的命令是

vi /etc/selinux/config

SELINUX=enforcing

SELINUXTYPE=targeted 两行注释掉在最后加入

SELINUX=disabled

[root@lnmp01 ~]# cat /etc/selinux/config

 

# This file controls the state of SELinux on the system.

# SELINUX= can take one of these three values:

#     enforcing - SELinux security policy is enforced.

#     permissive - SELinux prints warnings instead of enforcing.

#     disabled - No SELinux policy is loaded.

#SELINUX=enforcing

# SELINUXTYPE= can take one of these two values:

#     targeted - Targeted processes are protected,

#     mls - Multi Level Security protection.

#SELINUXTYPE=targeted

SELINUX=disabled

然后再进行挂载:

[root@lnmp01 ~]# mount -t nfs 192.168.20.6:/data/r_shared /mnt

[root@lnmp01 ~]# df -h

Filesystem            Size  Used Avail Use% Mounted on

/dev/sda3              18G  1.2G   16G   8% /

tmpfs                 504M     0  504M   0% /dev/shm

/dev/sda1             190M   48M  132M  27% /boot

192.168.20.6:/data/r_shared

                       18G  1.2G   16G   8% /mnt

可以了

NFS服务基本配置

标签:配置文件   客户端.nfs.rpcbind.linux.   

原文地址:http://11374450.blog.51cto.com/11364450/1866370

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!