NFS服务器安装与配置
场景
版本
[root@localhost ~]# cat /etc/redhat-release
Red Hat EnterpriseLinux Server release 6.4 (Santiago)
[root@localhost ~]# uname-a
Linuxlocalhost.localdomain 2.6.32-358.el6.x86_64 #1 SMP Tue Jan 29 11:47:41 EST 2013x86_64 x86_64 x86_64 GNU/Linux
创建目录挂载查看安装包
[root@localhost ~]# mkdir /mnt/cdrom/
[root@localhost ~]# mount /dev/cdrom /mnt/cdrom/
[root@localhost ~]# cd /mnt/cdrom/Packages/
[root@localhost Packages]# ls nfs*
nfs4-acl-tools-0.3.3-6.el6.x86_64.rpm nfs-utils-lib-1.1.5-6.el6.i686.rpm
nfs-utils-1.2.3-36.el6.x86_64.rpm nfs-utils-lib-1.1.5-6.el6.x86_64.rpm
安装包和所需的依赖包
[root@localhostPackages]# rpm -Uvh nfs-utils-1.2.3-36.el6.x86_64.rpm
nfs-utils-lib-1.1.5-6.el6.x86_64.rpmrpcbind-0.2.0-11.el6.x86_64.rpm keyutils-1.4-4.el6.x86_64.rpmlibevent-1.4.13-4.el6.x86_64.rpm libgssglue-0.1-11.el6.x86_64.rpmlibtirpc-0.2.1-5.el6.x86_64.rpm
启动NFS服务器
NFS依赖rpcbind 服务,设置为其自动启动
[root@localhostPackages]# chkconfig rpcbind on
[root@localhostPackages]# service rpcbind start
Starting rpcbind: [ OK ]
[root@localhostPackages]# service nfs start
Starting NFS services: [ OK ]
Starting NFS mountd: [ OK ]
Starting NFS daemon: [ OK ]
[root@localhostPackages]# service nfs restart
Shutting down NFS daemon: [ OK ]
Shutting down NFS mountd: [ OK ]
Starting NFS services: [ OK ]
Starting NFS mountd: [ OK ]
Starting NFS daemon: [ OK ]
[root@localhost Packages]#
配置NFS服务器
察看当前共享的NFS信息
[root@localhostPackages]# showmount -e localhost
Export list forlocalhost: 空白无输出
下面,做一个最基础的测试。创建 export 目录,分配权限
[root@localhostPackages]# mkdir /nfsdata
[root@localhostPackages]# ll /nfsdata/ -d
drwxr-xr-x 2 root root 4096 Aug 23 04:07/nfsdata/
[root@localhostPackages]# chmod a+w /nfsdata/
[root@localhostPackages]# ll /nfsdata/ -d
drwxrwxrwx 2 root root 4096 Aug 23 04:07/nfsdata/
配置 export 文件
/nfsdata*(rw,root_squash,no_all_squash,sync)
[root@localhostPackages]# exportfs -r
再次察看当前共享的NFS信息
[root@localhostPackages]# showmount -e localhost
Export list for localhost:
/nfsdata *
[root@localhost Packages]#
自己连接一下自己,测试一下。
[root@localhostPackages]# mkdir /mnt/nfs
[root@localhost Packages]# mount127.0.0.1:/nfsdata/ /mnt/nfs/
察看一下mount的信息
[root@localhostPackages]# mount
/dev/mapper/VolGroup-lv_root on / type ext4(rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts(rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw)
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc typebinfmt_misc (rw)
/dev/sr0 on /mnt/cdrom type iso9660 (ro)
sunrpc on /var/lib/nfs/rpc_pipefs typerpc_pipefs (rw)
nfsd on /proc/fs/nfsd type nfsd (rw)
注意在这:127.0.0.1:/nfsdata/on /mnt/nfs type nfs
(rw,vers=4,addr=127.0.0.1,clientaddr=127.0.0.1)
检查目录是否可以写入
[root@localhostPackages]# touch /mnt/nfs/testfile1.txt
[root@localhostPackages]# ll /mnt/nfs/testfile1.txt
-rw-r--r-- 1 nfsnobody nfsnobody 0 Aug 2304:14 /mnt/nfs/testfile1.txt
配置NFS客户机
NFS 客户机也需要安装一样的包
创建目录,和服务器一样
[root@localhost ~]# cd/mnt/
[root@localhost mnt]# ls
cdrom
连接服务器检查目录
[root@localhost mnt]#mkdir nfs
[root@localhost ~]# mount192.168.188.101:/nfsdata /mnt/nfs/
[root@localhost ~]# ls /mnt/nfs/ -l
total 0
-rw-r--r--. 1 nfsnobody nfsnobody 0 Aug 2304:14 testfile1.txt
[root@localhost ~]# echotest >>/mnt/nfs/testfile1.txt
[root@localhost ~]# ls/mnt/nfs/testfile1.txt
/mnt/nfs/testfile1.txt
[root@localhost ~]# ls/mnt/nfs/testfile1.txt -l
-rw-r--r--.1 nfsnobody nfsnobody 5 Aug 23 05:04 /mnt/nfs/testfile1.txt