問題描述:
公司的某個軟件項目處於內部測試期間,有2臺應用服務器短期內需要共享使用不少於500GB的磁盤空間,要求當軟件在執行讀寫操作時能像訪問本機的目錄一樣,相關條件和需求如下所述。
1.將服務器192.168.1.2的/NFS目錄作爲共享,此目錄已經掛載一個容量爲500GB的邏輯卷。
2./NFS目錄僅允許指定的2臺服務器(192.168.1.7、192.168.1.8)訪問
3.當從192.168.1.8掛載/NFS共享時,保留root的身份及完整權限
4.當從192.168.1.7掛載/NFS共享時,只有讀取權限,不可寫入,所有用戶均視爲nfsnobody對待
搭建過程:
1,查看服務器的192.168.1.2的掛載情況
[root@localhost~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 9.7G 2.3G 7.0G 25% /
/dev/sda2 9.7G 151M 9.1G 2% /date
/dev/sda1 99M 12M 82M 13% /boot
tmpfs 500M 0 500M 0% /dev/shm
/dev/hdc 4.1G 4.1G 0 100% /media/RHEL_5.9 x86_64 DVD
/dev/mapper/vg_date-lv_date
492G 198M 467G 1% /NFS
2,查看主要軟件包是否安裝
[root@localhost~]# rpm -q nfs-utils
nfs-utils-1.0.9-66.el5……已安裝
[root@localhost ~]# rpm -q portmap
portmap-4.0-65.2.2.1……已安裝
3,配置nfs服務
[root@localhost~]# vim /etc/exports
/NFS 192.168.1.7(rw,all_squash) 192.168.1.8(rw,no_root_squash)
~
~
-- INSERT-- 1,31-34 All
4,啓動nfs服務和portmap服務
[root@localhost~]# service nfs start
Starting NFSservices: [ OK ]
Starting NFSquotas: [ OK ]
Starting NFSdaemon: [ OK ]
Starting NFSmountd: [ OK ]
Stopping RPCidmapd: [ OK ]
Starting RPCidmapd: [ OK ]
[root@localhost~]# service portmap start
Startingportmap: [ OK ]
[root@localhost~]# chkconfig nfs on
[root@localhost~]# chkconfig portmap on
5,客戶端查看並掛載NFS目錄
[root@localhost~]# showmount -e 192.168.1.2
Export list for192.168.1.2:
/NFS192.168.1.8,192.168.1.7
[root@localhost~]# mount 192.168.1.2:/NFS /mnt/
[root@localhost~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 19G 2.7G 16G 15% /
/dev/sda1 99M 12M 82M 13% /boot
tmpfs 500M 0 500M 0% /dev/shm
192.168.1.2:/NFS 492G 198M 467G 1% /mnt
設置開機自動掛載
[root@localhost~]# vim /etc/fstab
LABEL=/ / ext3 defaults 1 1
LABEL=/boot /boot ext3 defaults 1 2
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
LABEL=SWAP-sda3 swap swap defaults 0 0
192.168.1.2:/NFS /mnt nfs defaults 00
~
-- INSERT-- 8,1 All
6,查看服務器端nfs服務狀態
[root@localhost~]# rpcinfo -p 192.168.1.2
program vers proto port
100000 2 tcp 111 portmapper
100000 2 udp 111 portmapper
100024 1 udp 891 status
100024 1 tcp 894 status
100011 1 udp 848 rquotad
100011 2 udp 848 rquotad
100011 1 tcp 851 rquotad
在/mnt下建立nfs目錄
[root@localhost~]# cd /mnt/
[root@localhostmnt]# mkdir nfs
7,服務端查看
[root@localhostNFS]# showmount -a
All mount pointson localhost.localdomain:
192.168.1.8:/NFS
[root@localhost~]# cd /NFS/
[root@localhostNFS]# ls
lost+found nfs
8,通過NFS搭建主要解決UNIX和Linux之間的共享服務,如果想通過windows主機和Linux主機之間通信則需要配置samba服務器