:CentOS下NFS安装与配置 Centos5.3下安装配置NFS linux下安装配置NFS

来源:百度文库 编辑:九乡新闻网 时间:2024/04/30 03:39:08
CentOS下NFS安装与配置 Centos5.3下安装配置NFS linux下安装配置NFS2011年08月30日 星期二 下午 06:11

 经过我的的实践,在Centos6下必须先启动rpcbind,而不是portmap:

service   rpcbind  start  再安装启动NFS成功! 1、是否安装了NFS和portmap RPM包
[root@ha01 /]# rpm -qa | grep nfs
nfs-utils-1.0.9-44.el5
nfs-utils-lib-1.0.8-7.6.el5

[root@ha01 /]# rpm -qa | grep portmap
portmap-4.0-65.2.2.1

2、若没有安装则需要安装如下的RPM包
[root@ha01 /]# find /media/ -name nfs*
/media/CentOS_5.5_Final/CentOS/nfs4-acl-tools-0.3.3-1.el5.i386.rpm
/media/CentOS_5.5_Final/CentOS/nfs-utils-lib-1.0.8-7.6.el5.i386.rpm
/media/CentOS_5.5_Final/CentOS/nfs-utils-1.0.9-44.el5.i386.rpm
/media/CentOS_5.5_Final/CentOS/nfs-utils-lib-devel-1.0.8-7.6.el5.i386.rpm

[root@ha01 /]# find /media/ -name portmap*
/media/CentOS_5.5_Final/CentOS/portmap-4.0-65.2.2.1.i386.rpm

3、NFS配置
NFS Server:192.168.1.100
NFS Client:192.168.1.200

NFS Server:
共享目录:/nfspool
NFS 运行用户(RPM包自动生成):nfsnobody

[root@ha01 /]# mkdir /nfspool
[root@ha01 /]# chown nfsnobody:nfsnobody /nfspool
[root@ha01 /]# id nfsnobody
uid=65534(nfsnobody) gid=65534(nfsnobody) groups=65534(nfsnobody) context=root:system_r:unconfined_t:SystemLow-SystemHigh
[root@ha01 /]# chown -R nfsnobody:nfsnobody /nfspool/.
[root@ha01 /]# vi /etc/exports
/nfspool 192.168.1.200(rw,async,anonuid=65534,anongid=65534)

Server端启动服务:
[root@ha01 /]# service portmap start
启动 portmap:                                             [确定]
[root@ha01 /]# service nfslock start
[root@ha01 /]# service nfs start
启动 NFS 服务:                                            [确定]
关掉 NFS 配额:                                            [确定]
启动 NFS 守护进程:                                      [确定]
启动 NFS mountd:                                      [确定]

NFS Client:
远程NFS目录在客户端的挂载点:/nfs

[root@ha02 /]# mkdir /nfs
[root@ha02 /]# service portmap start
启动 portmap:                                             [确定]

[root@ha02 /]# chown nfsnobody:nfsnobody /nfs
[root@ha02 /]# chmod 777 /nfs

[root@ha02 /]# mount -t nfs -o soft,intr,bg,timeo=50 192.168.1.100:/nfspool /nfs

测试:
[root@ha02 /]# ls -all /nfs
总计 20
drwxr-xr-x  2 nfsnobody nfsnobody 4096 04-02 13:53 .
drwxr-xr-x 24 root      root      4096 04-02 13:49 ..
-rw-r--r--  1 root      root         0 04-02 13:53 test.t    

Client启动后的自动mount:
[root@ha02 /]# vi /etc/fstab
192.168.1.100:/nfspool /nfs nfs soft,intr,bg,timeo=50 0 0

4、服务起停顺序
启动:
service portmap start
service nfslock  start
service nfs  start
停止:
service nfslock stop
service nfs stop
service portmap stop

5、安全性
portmap PORT: 111
NFS PORT: 2049

防止使用IP欺骗和RPC重定向技术通过lo回环进行攻击以及限定授权主机:
iptables -A INPUT -p udp -d 127.0.0.1 --dport 111 -j DROP
iptables -A INPUT -p udp -d 127.0.0.1 --dport 2049 -j DROP
iptables -A INPUT -p udp -s 192.168.100.2 --dport 111 -j ACCEPT
iptables -A INPUT -p udp -s 192.168.100.2 --dport 2049 -j ACCEPT

说明:

1、exports参数说明
rw: 读写模式;
async: 异步磁盘读写;
anonu(g)id: 指定NFS在进行操作时所使用的匿名用户uid/gid

2、NFS 管理命令
showmount -e 在NFS Server上执行此命令显示NFS Server上所有的共享卷;
showmount -e 192.168.1.100在NFS Client上执行此命令显示NFS Server上所有共享卷;
export -av 根据/etc/exports导出所有卷;
export -rv 重新导出所有卷,增加/etc/exports中的新项目、删除不存在的项目、更新改变的项目;  Centos5.3下安装配置NFS  

使用NFS服务,至少需要启动以下系统守护进程。
chkconfig nfs on
chkconfig portmap  on

一:服务器端的设定
1)修改配置文件
vi /etc/exports
/home  192.168.1.2(rw,async) *(ro)               #注意红色部分没有空格
/home    192.168.1.*(rw,sync,no_root_squash,no_subtree_check)
rw:可读写的权限;
ro:只读的权限;
no_root_squash:登入到NFS主机的用户是ROOT用户,他就拥有ROOT的权限,此参数很不安全,建议不要使用。
root_squash:在登入 NFS 主使用分享之目的使用者如果是 root
all_squash:不管登陆NFS主机的用户是什么都会被重新设定为nobody。
anonuid:将登入NFS主机的用户都设定成指定的user id,此ID必须存在于/etc/passwd中。
anongid:同 anonuid ,但是成 group ID 就是
sync:资料同步写入存储器中。
async:资料会先暂时存放在内存中,不会直接写入硬盘。
insecure 允许从这台机器过来的非授权访问。

2)启动服务
/etc/rc.d/init.d/portmap start
/etc/rc.d/init.d/nfs start
3)exportfs命令
启动了NFS之后又修改了/etc/exports,这个时候我们就可以用exportfs命令来使改动立刻生效,该命令格式如下:
exportfs [-aruv]
-a :全部mount或者unmount /etc/exports中的内容
-r :重新mount /etc/exports中分享出来的目录
-u :umount 目录
-v :在 export 的时候,将详细的信息输出到屏幕上。
具体例子:
exportfs -rv <==全部重新export一次!
exportfs -au <==全部都卸载了。

 

二:客户端的操作:
1、showmout命令对于NFS的操作和查错有很大的帮助
showmout
-a :这个参数是一般在NFS SERVER上使用,是用来显示已经mount上本机nfs目录的cline机器。
-e :显示指定的NFS SERVER上export出来的目录。
例如:
showmount -e 192.168.0.30
2、mount nfs目录的方法:
mount -t nfs hostname(orIP):/directory /mount/point
具体例子:
mount -t nfs 192.168.0.1:/tmp /mnt/nfs

3、与NFS有关的一些命令介绍
nfsstat:
查看NFS的运行状态,对于调整NFS的运行有很大帮助
rpcinfo:
查看rpc执行信息,可以用于检测rpc运行情况的工具。

完成!

                                                 一个NFS实例

目标:1。实现手动挂载

             2。实现自动挂载,卸载

方法:NFS服务器依靠的几个程序包:portmap,nfs,依次安装,启动。

[root@localhost ~]# service portmap status

portmap (pid 4213) is running...

[root@localhost ~]#

[root@localhost ~]# service nfs status

rpc.mountd (pid 4559) is running...

nfsd (pid 4556 4555 4554 4553 4552 4551 4550 4549) is running...

[root@localhost ~]#

NFS的服务器配置/ect/explores,系统默认不一定有,没有就自己新建一个

/var/ftp/pub/   192.168.1.0/24(rw)

很简单:共享的目录  共享给谁(可以是IP,主机名,网段,域名) 读写权限

 

重起portmap和nfsd服务,注意先后顺序,先portmap。

 

现在我检查一下共享是否已经成功:

[root@localhost ~]# showmount -e 192.168.1.200

Export list for 192.168.1.200:

/var/ftp/pub 192.168.1.0/24

说明我们服务器端的共享是成功的!

 

现在配置客户端

手动加载比较简单

首先,参看一下共享

[root@RHEL mnt]# showmount -e 192.168.1.200

Export list for 192.168.1.200:

/var/ftp/pub 192.168.1.0/24

然后使用命令挂载

[root@RHEL mnt]# mount -t nfs 192.168.1.200:/var/ftp/pub /temp

[root@RHEL mnt]# cd /temp

[root@RHEL temp]# ls -l /temp

total 340

drwxr-xr-x 2 root      root        4096 Mar 31  2009 1

drwxr-xr-x 2 nfsnobody nfsnobody   4096 Mar 31  2009 2

下面配置自动挂载,卸载。

安装autofs服务

[root@RHEL temp]# service autofs status

automount (pid 5655) is running...

配置/etc/auto.master

添加一条记录

/mnt    /etc/auto.mnt --timeout=10

挂载点   这个挂载点的具体配置  多少时间没有访问将自动短开连接(秒)

配置/etc/auto.mnt

nfs     -fstype=nfs,rw  192.168.1.200:/var/ftp/pub

挂载点下的目录名 挂载的文件类型,读取权限 共享的路径

 

重新启动autofs服务

 [root@RHEL temp]# service autofs restart

Stopping automount:                                        [  OK  ]

Starting automount:                                        [  OK  ]

验证:

我们挂载到/mnt下的,先看一下/mnt下有些什么

[root@RHEL /]# ls /mnt

[root@RHEL /]#

什么都没有

 

我们再访问/mnt/nfs

[root@RHEL /]# ls /mnt/nfs

1               EULA        isolinux                 RPM-GPG-KEY-redhat-release

2               eula.en_US  README-en                Server

Cluster         GPL         RELEASE-NOTES-en         TRANS.TBL

ClusterStorage  images      RPM-GPG-KEY-redhat-beta  VT

这些正是服务器上的共享文件,说明自动挂载已经成功。同时,我们也可以得出结论,挂载点下的文件(也就是/etc/auto.mnt第一列)是自动建立的,不需要我们手动建立。

再看卸载,其实很简单,刚才在配置/etc/auto.master中已经设置了timeout=10秒,所以我们现在在回过去看/mnt下还有没有nfs目录

[root@RHEL /]# ls /mnt

[root@RHEL /]#

已经没有了,卸载成功! 

其实再往下就可以做异地定时自动备份,只要at和cp命令搭配使用。