Centos 6.5 搭建NFS服務器筆記


NFS服務器端安裝

1、安裝nfs服務端程序

[root@nfs ~]# yum install rpcbind nfs-utils

[root@nfs ~]# rpm -qa | grep -E "nfs-utils|rpcbind"

rpcbind-0.2.0-11.el6.x86_64

nfs-utils-1.2.3-39.el6.x86_64

nfs-utils-lib-1.1.5-6.el6.x86_64

[root@nfs ~]# mkdir /home/data

[root@nfs ~]# chmod -R 755 /home/data

2、編輯配置文件/etc/exports,設置客戶端訪問權限。

[root@nfs ~]# vi /etc/exports

#mount share source

/home/data 192.168.3.0/24(rw)       #只允許192.168.3.0網段讀寫

3、啓動rpcbindnfs服務

[root@nfs ~]# chkconfig rpcbind on

[root@nfs ~]#chkconfig nfs on

[root@nfs ~]#service rpcbind start

Starting rpcbind:[  OK ]

[root@nfs ~]#service nfs start

Starting NFSservices:  [  OK  ]

Starting NFSmountd: [  OK  ]

Starting NFSdaemon: [  OK  ]

Starting RPCidmapd: [  OK  ]

4、創建一些測試資源

[root@nfs data]# touch text

[root@nfs data]# touch text.tar.gz


NFSclient安裝

1、客戶端安裝rpcbind

[root@nfsclient ~]# yum install rpcbind nfs-utils

[root@nfsclient ~]# service rpcbind start

Starting rpcbind: [  OK  ]

[root@nfsclient ~]# showmount -e 192.168.3.103      #查詢服務器端提供的資源

Export list for 192.168.3.103:

/home/data 192.168.3.0/24

2、創建本地掛載點,並掛載。

[root@nfsclient ~]# mkdir /mnt/data

[root@nfsclient ~]# mount 192.168.3.103:/home/data /mnt/data   #掛載服務器/home/data資源到本地/mnt/data

3、實現開機掛載/etc/fstab

[root@nfsclient data]# umount -lf /mnt/data         #爲了實驗開機掛載,先取消掛載

[root@nfsclient data]# vi /etc/fstab                 # 進入/etc/fstab添加以下配置

192.168.3.103:/home/data      /mnt/data         nfs    defaults        0 0

[root@nfsclient data]# reboot            #從啓看下是否開機後自動掛載

[root@nfsclient ~]# df -T

Filesystem                  Type  1K-blocks    Used Available Use% Mounted on

/dev/mapper/VolGroup-lv_root ext4   6926264 1294084   5280336  20%

192.168.3.103:/home/data    nfs     6926272 1402528   5171872 22% /mnt/data

4、測試掛載後的權限

[root@nfsclient ~]# cd /mnt/data        #進入掛載後的目錄,新建文件試下權限

[root@nfsclient data]# mkdir test

mkdir: cannot create directory `test': Permission denied


試下在服務器端設置文件權限爲777

[root@nfs ~]# chmod -R 777 /home/data/

[root@nfsclient data]# mkdir test

[root@nfsclient data]# ll

total 8

drwxr-xr-x 2 nfsnobody nfsnobody 4096 Apr 26 20:55 test

可以創建文件,但通過root訪問nfs服務器,默認root會由root_squash的設定壓縮成nfsnobody,成爲匿名使用名。

5、測試創建用戶去掛載,以及使用root用戶不壓縮掛載。

先在服務器端新建一個www用戶,uidgid都爲800

[root@nfs ~]# useradd -u 800 www

[root@nfs ~]# id www

uid=800(www) gid=800(www) groups=800(www)

[root@nfs ~]# setfacl -R -m u:800:rwx /home/data/    #只有使用者身份是www纔可讀寫

[root@nfs ~]# getfacl /home/data                  #查看一下權限

getfacl: Removing leading '/' from absolute path names

# file: home/data

# owner: root

# group: root

user::rwx

user:www:rwx

group::rwx

mask::rwx

other::rwx

在客戶端機器上創建一個與服務器端一樣的用戶,並且uidgid要與服務器相同。

[root@nfsclient ~]# useradd -u 800 www

[root@nfsclient ~]# su – www        #切換到用戶www測試。

[www@nfsclient ~]$ cd /mnt/data

[www@nfsclient data]$ mkdir 123

[www@nfsclient data]$ ll

total 12

drwxrwxr-x 2 www    www      4096 Apr 26 21:24  123     #用戶和組都爲www

6、測試root用戶不壓縮時掛載

先在服務器端修改nfs配置文件/etc/exports

[root@nfshome]# vi /etc/exports

#mount share source

/home/data192.168.3.0/24(rw,no_root_squash)    #增加no_root_squash不壓縮root

[root@nfs home]# service rpcbind restart

Stoppingrpcbind: [  OK  ]

Startingrpcbind: [  OK  ]

[root@nfshome]# service nfs restart

Shuttingdown NFS daemon: [  OK  ]

Shuttingdown NFS mountd: [  OK  ]

Shuttingdown NFS services:  [  OK  ]

Shuttingdown RPC idmapd: [  OK  ]

StartingNFS services:  [  OK  ]

StartingNFS mountd: [  OK  ]

StartingNFS daemon: [  OK  ]

Starting RPC idmapd: [ OK  ]

在客戶端機器上測試驗證

[root@nfsclientdata]# mkdir 123

[root@nfsclientdata]# ll

total 12

drwxr-xr-x 2 root     root      4096 Apr 26 21:47  123    #用戶和組爲root


7、如果服務器使用防火牆,客戶端就無法訪問,但除了固定的port 1112049外,其它不固定的端口是由rpc.mountd,rpc,rquotad等服務所開啓,所以iptables很難設定規則, rpc 服務主要有 mountd, rquotad, nlockmgr 三個,Centos 6.X提供一個固定特定NFS服務端口的配置文件,如下:

在服務器端設置

[root@nfs ~]# vi /etc/sysconfig/nfs

RQUOTAD_PORT=1001

LOCKD_TCPPORT=30001

LOCKD_UDPPORT=30001

MOUNTD_PORT=1002


添加十個端口到防火牆規則裏,並保存

[root@nfs ~]#iptables -I INPUT -p tcp --dport 111 -j ACCEPT

[root@nfs ~]#iptables -I INPUT -p tcp --dport 2049 -j ACCEPT

[root@nfs ~]#iptables -I INPUT -p tcp --dport 1001 -j ACCEPT

[root@nfs ~]#iptables -I INPUT -p tcp --dport 1002 -j ACCEPT

[root@nfs ~]#iptables -I INPUT -p tcp --dport 30001 -j ACCEPT

[root@nfs ~]#iptables -I INPUT -p udp --dport 111 -j ACCEPT

[root@nfs ~]#iptables -I INPUT -p udp --dport 2049 -j ACCEPT

[root@nfs ~]#iptables -I INPUT -p udp --dport 1001 -j ACCEPT

[root@nfs ~]#iptables -I INPUT -p udp --dport 1002 -j ACCEPT

[root@nfs ~]#iptables -I INPUT -p udp --dport 30001 -j ACCEPT

[root@nfs ~]# service iptables save

iptables: Saving firewall rules to /etc/sysconfig/iptables: [  OK  ]


8、客戶端測試是否掛載成功

[root@nfsclient ~]# df -T

Filesystem                 Type  1K-blocks    Used Available Use% Mounted on

192.168.3.103:/home/data  nfs     6926272 1406016   5168416 22% /mnt/data








參考:http://linux.vbird.org/linux_server/0330nfs.php

           http://jishuweiwang.blog.51cto.com/6977090/1390579


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