NFS企業級配置實戰

NFS服務企業級配置實戰

1、服務器信息

由於我的是在虛擬機中實戰的,服務器信息如下

[root@localhost~]# cat /etc/redhat-release
CentOSrelease 6.6 (Final)
[root@localhost~]# uname -r
2.6.32-504.el6.x86_64
[root@localhost~]# uname -m
x86_64

2、查看並啓動rpcbind以及NFS服務,然後加入開機自啓

[root@localhost~]# /etc/init.d/rpcbind status

rpcbind 已停

開啓rpcbind服務

#如果沒有請按裝nfs#

yum install nfs-utils  rpcbind -y
[root@localhost~]# /etc/init.d/rpcbind start

正在啓動 rpcbind                                         [確定]

[root@localhost~]# /etc/init.d/rpcbind status

rpcbind(pid  3746) 正在運行...

查看NFS服務,並啓動

[root@localhost~]# /etc/init.d/nfs status
rpc.svcgssd已停
rpc.mountd已停
nfsd 已停
rpc.rquotad已停
[root@localhost~]# /etc/init.d/nfs start
啓動 NFS 服務:                                            [確定]
關掉 NFS 配額:                                            [確定]
啓動 NFS mountd:                                          [確定]
啓動 NFS 守護進程:                                        [確定]
正在啓動 RPC idmapd:                                      [確定]

加入開機自啓動

[root@localhost~]# chkconfig --list rpcbind
rpcbind            0:關閉     1:關閉     2:啓用     3:啓用     4:啓用     5:啓用     6:關閉
[root@localhost~]# chkconfig --list nfs
nfs               0:關閉     1:關閉     2:關閉     3:關閉     4:關閉     5:關閉     6:關閉
[root@localhost~]# chkconfig nfs on
[root@localhost~]# chkconfig --list nfs
nfs               0:關閉     1:關閉     2:啓用     3:啓用     4:啓用     5:啓用     6:關閉


3、創建要共享的文件並授權

[root@localhost~]# mkdir /sharedata
[root@localhost~]# ls -ld /sharedata/
drwxr-xr-x2 root root 4096 9月  18 09:52 /sharedata/
[root@localhost~]# touch /sharedata/wu.txt
[root@localhost~]# echo "This is a test NFS">/sharedata/wu.txt
[root@localhost~]# chown-R nfsnobody.nfsnobody /sharedata/
[root@localhost~]# ls -ld /sharedata/
drwxr-xr-x2 nfsnobody nfsnobody 4096 9月  1809:52 /sharedata/

檢測nfsnobody是否存存在

[root@localhost~]# grep nfsnobody /etc/passwd
nfsnobody:x:65534:65534:AnonymousNFS User:/var/lib/nfs:/sbin/nologin

注意:由於在NFS服務器端要把共享的NFS目錄賦予NFS默認用戶nfsnobody用戶和用戶組權限,如果不設置這個權限,會導致NFS客戶端訪問時無法通過NFS本地共享目錄權限寫入數據。

4、在服務端配置文件,並在本地查看掛載信息

##寫入配置文件

[

root@localhost~]#
echo"/sharedata 172.16.30.0/24(rw,sync)" /etc/exports

##查看配置文件

[root@localhost~]# tail  /etc/exports
/sharedata172.16.30.0/24(rw,sync)

##重新加載

[root@localhost~]# exportfs -rv
exporting172.16.30.0/24:/sharedata

##在服務器端檢測掛載情況

[root@localhostlog]# showmount -e localhost
Exportlist for localhost:
/sharedata172.16.30.0/24

##查看NFS Server配置文件的參數

[root@localhostlog]# cat /var/lib/nfs/etab
/sharedata 172.16.30.0/24(rw,sync,wdelay,hide,nocrossmnt,secure,root_squash,no_all_squash,no_subtree_check,secure_locks,acl,anonuid=65534,anongid=65534,sec=sys,rw,root_squash,no_all_squash)

5、把共享的軟件掛載在本地服務端

[root@localhostlog]# mount -t nfs 172.16.30.91:/sharedata /mnt
[root@localhostlog]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda3              18G  3.9G  13G  24% /
tmpfs                 491M     0 491M   0% /dev/shm
/dev/sda1             190M   27M 153M  15% /boot
172.16.30.91:/sharedata
                       18G  3.9G  13G  24% /mnt

 

 

服務器端NFS配置已經完成。

 

6、客戶端配置:

 

##安裝rpcbindNFS

 

[root@localhost~]# yum install rpcbind -y
[root@localhost~]# rpm -qa rpcbind
rpcbind-0.2.0-12.el6.x86_64
 
[root@localhost~]# yum install nfs-utils -y
[root@localhost~]# rpm -qa nfs-utils
nfs-utils-1.2.3-70.el6_8.1.x86_64

啓動RPC服務(無須啓動NFS服務)

##查看服務器共享的文件

[root@localhost~]# showmount -e 172.16.30.91
Exportlist for 172.16.30.91:
/sharedata172.16.30.0/24

##掛載到客戶機上

 

[root@localhost ~]# mount -t nfs172.16.30.91:/sharedata /mnt/

##查看磁盤

[root@localhost~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda3              18G  3.2G  14G  19% /
tmpfs                 491M     0 491M   0% /dev/shm
/dev/sda1             190M   27M 153M  15% /boot
172.16.30.91:/sharedata
                       18G  3.9G  13G  24% /mnt

7、測試讀寫數據:

##查看服務端共享的文件

[root@localhost~]# ls /mnt/
wu.txt
[root@localhost~]# cat /mnt/wu.txt
This is atest NFS

##客戶端新建文件

[root@localhost~]# mkdir /mnt/userwu
[root@localhost~]# tree /mnt/
/mnt/
├── userwu
└── wu.txt
 
1directory, 1 file

8、將rpcbind服務和掛載加入開機自啓動

[root@localhost~]# echo "/etc/init.d/rpcbind start" >>/etc/rc.local
[root@localhost~]# echo "/bin/mount -t nfs 172.16.30.91:/sharedata /mnt">>/etc/rc.local
[root@localhost~]# tail -2 /etc/rc.local
/etc/init.d/rpcbindstart
/bin/mount-t nfs 172.16.30.91:/sharedata /mnt

至此,NFS服務端和客戶端配置完成

 


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