NFS服務器安裝與配置

                                                                                  NFS服務器安裝與配置

場景

wKioL1P4EpfCXV4FAAEPB6mjOnU724.jpg

版本

 [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


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章