nfs

###nfs
nfs:network file system

RPC:遠程過程調用


1.nfs安裝


centos5.x中,portmap就是指centos6.x中的rpcbind

[root@s01 tech]# yum install rpcbind.x86_64 nfs-utils.x86_64


2.檢查RPC的註冊狀況

rpcinfo -p [ip|hostname]
rpcinfo -t|-u ip|hostname 程序名稱

-p:針對某個IP或者主機名顯示出全部的端口和程序信息。
-t/-u:針[root@Cent64 raid]# rpcinfo -t 10.10.54.64 mountd
program 100005 version 1 ready and waiting
program 100005 version 2 ready and waiting
program 100005 version 3 ready and waiting

對某主機的某個程序檢查其tcp/udp數據包所在的軟件版本。服務器端vim



#例子
1.共享/stu1目錄,容許全部的客戶端訪問該目錄,但只具備只讀權限。
2.共享/stu2目錄,容許10.10.54.0/24網段客戶端訪問,而且對該目錄具備只讀權限。
3.共享/stu3目錄,10.10.54.0/24網段的客戶端具備只讀權限,而且將root用戶映射成匿名用戶。
4.共享/stu4目錄,全部人具備讀寫權限,但當用戶使用該共享目錄的時候將賬號映射爲匿名用戶,指定匿名用戶的uid/gid爲600。

客戶端
1.使用showmount命令查看nfs服務器發佈的共享目錄
2.掛載服務器端的/stu1目錄到本地的/mnt/stu1目錄
3.卸載/mnt/stu1目錄
4.自動掛載nfs服務器上/stu4到本地的/mnt/stu4目錄

環境:
服務器:10.10.54.64
客戶端:10.10.54.63
服務器和客戶端:
yum install rpcbind.x86_64 nfs-utils.x86_64
1.服務器端
[root@Cent64 /]# mkdir /stu1
[root@Cent64 /]# chmod 755 /stu1

[root@Cent64 /]# mkdir /stu2
[root@Cent64 /]# chmod 755 /stu2

[root@Cent64 /]# mkdir /stu3
[root@Cent64 /]# chmod 755 /stu3

[root@Cent64 /]# mkdir /stu4
[root@Cent64 /]# groupadd -g 600 nfs-stu4
[root@Cent64 /]# useradd -u 600 -g  nfs-stu4 nfs-stu4
[root@Cent64 /]# chown -R nfs-stu4:nfs-stu4 /stu4

2.配置服務器文件
[root@Cent64 share]# vim /etc/exports
/stu1   *(ro)
/stu2   10.10.54.0/24(ro)                                        
/stu3   10.10.54.0/24(ro,root_squash)
/stu4   *(rw,all_squash,anonuid=600,anongid=600)

3.重啓服務
[root@Cent64 /]# /etc/init.d/rpcbind restart
[root@Cent64 /]# /etc/init.d/nfs restart

4.客戶端查看nfs服務器發佈的共享目錄centos

[root@Cent63 ~]# /etc/init.d/rpcbind stop
[root@Cent63 ~]# /etc/init.d/rpcbind start[root@CentOS63 usr]# showmount -e 10.10.54.64
clnt_create: RPC: Program not registered
解決方法服務器端
[root@Cent64 ~]# /etc/init.d/rpcbind stop
[root@Cent64 ~]# /etc/init.d/rpcbind start

[root@CentOS63 usr]# showmount -e 10.10.54.64
Export list for 10.10.54.64:
/stu4 *
/stu1 *
/stu3 10.10.54.0/24
/stu2 10.10.54.0/24

5.掛載服務器端的/stu1目錄到本地的/mnt/stu1目錄
客戶端
[root@CentOS63 usr]# mkdir /mnt/stu1
[root@CentOS63 usr]# mount -t nfs 10.10.54.64:/stu1 /mnt/stu1/
[root@CentOS63 usr]# df
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/sda2              6192704   3951784   1926348  68% /
tmpfs                   510268         0    510268   0% /dev/shm
/dev/sda1               198337     25836    162261  14% /boot
/dev/sda5               516040     16780    473048   4% /swap
/dev/sda3              5160576   4862248     36184 100% /usr
10.10.54.64:/stu1      6192768   1597184   4281088  28% /mnt/stu1

6.卸載/mnt/stu1目錄
[root@CentOS63 mnt]# umount /mnt/stu1
[root@CentOS63 mnt]# df
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/sda2              6192704   3787340   2090792  65% /
tmpfs                   510268         0    510268   0% /dev/shm
/dev/sda1               198337     25836    162261  14% /boot
/dev/sda5               516040     16780    473048   4% /swap
/dev/sda3              5160576   4862248     36184 100% /usr

7.自動掛載nfs服務器上/stu4到本地的/mnt/stu4目錄
客戶端服務器


[root@CentOS63 mnt]# yum install autofs.x86_64

###開機自動掛載
[root@CentOS63 mnt]# vim /etc/rc.d/rc.local
[root@CentOS63 usr]# mount -t nfs 10.10.54.64:/stu4 /mnt/stu4/

###使用/mnt/stu4/數據時自動掛載,5分鐘不使用自動卸載,/mnt和stu4都是自動創建
//建立/etc/auto.master,自動檢測特定目錄
[root@CentOS63 mnt]# vim /etc/auto.master
/mnt  /etc/auto.nfs
..../mnt是子目錄stu1所在的文件夾
..../etc/auto.nfs文件設置掛載狀況

//建立/etc/auto.nfs
[root@CentOS63 mnt]# vim /etc/auto.nfs
stu4  -rw,bg,soft,rsize=32768,wsize=32768 10.10.54.64:/stu4

[root@CentOS63 ~]# rm -rf /mnt

//啓動autofs服務
[root@CentOS63 ~]# /etc/init.d/autofs restart
Starting automount:  
#自動創建/mnt文件夾                                      [  OK  ]
[root@CentOS63 ~]# ls -dl /mnt
drwxr-xr-x 2 root root 0 3月   5 19:39 /mnt


[root@CentOS63 ~]# cd /mnt/stu4/ ....使用時df才能看到掛載
[root@CentOS63 ~]#mount |grep stu4
10.10.54.64:/stu4 on /mnt/stu4 type nfs (rw,soft,rsize=32768,wsize=32768,sloppy,vers=4,addr=10.10.54.183,clientaddr=10.10.54.184)
[root@CentOS63 ~]# df /mnt/stu4
Filesystem           1K-blocks      Used Available Use% Mounted on
10.10.54.64:/stu4     6192704   1553952   4324192  27% /mnt/stu4tcp



nfs固定端口配置有助於防火牆編寫

vim /etc/sysconfig/nfs

# TCP port rpc.lockd should listen on.
LOCKD_TCPPORT=32803
# UDP port rpc.lockd should listen on.
LOCKD_UDPPORT=32769
# Port rpc.mountd should listen on.
MOUNTD_PORT=892
# Port rquotad should listen on.
RQUOTAD_PORT=875
# Port rpc.statd should listen on.
STATD_PORT=662測試

測試:
ui

[root@Cent64 raid]# rpcinfo -p|grep mount
    100005    1   udp    892  mountd
    100005    1   tcp    892  mountd
    100005    2   udp    892  mountd
    100005    2   tcp    892  mountd
    100005    3   udp    892  mountd
    100005    3   tcp    892  mountd

rest

相關文章
相關標籤/搜索
本站公眾號
   歡迎關注本站公眾號,獲取更多信息