NFS網絡共享服務部署

10.3 NFS服務端部署環境準備

10.3.1 NFS服務部署服務器準備

     服務器系統             角色                Ip        
Centos6.7 x86_64NFS服務器端(NFS-server)192.168.1.14
Centos6.7 x86_64NFS客戶端(Web-lamp01)192.168.1.15
Centos6.7 x86_64NFS客戶端(Web-lnmp02)192.168.1.16

10.3.2 NFS服務部署架構圖

wKiom1bPy7PzN-6iAAEkaumDoaE671.jpg

10.3.3 NFS服務器端操作系統及內核版本

[root@NFS-server ~]# cat /etc/redhat-release 
CentOS release 6.7 (Final)
[root@NFS-server ~]# username -r
[root@NFS-server ~]# uname -r
2.6.32-573.el6.x86_64
[root@NFS-server ~]# uname -m
x86_64

10.3.4 NFS客戶端操作系統及內核版本

[root@Web-lamp01 ~]# cat /etc/redhat-release 
CentOS release 6.7 (Final)
[root@Web-lamp01 ~]# uname -r
2.6.32-573.el6.x86_64
[root@Web-lamp01 ~]# uname -m
x86_64

10.4 NFS服務安裝前準備

10.4.1 查詢nfs-utils和rpcbind包是否安裝

[root@NFS-server ~]# rpm -qa nfs-utils rpcbind   ##查詢結果爲兩個安裝包都未安裝
[root@NFS-server ~]#

知識擴展:

安裝NFS軟件安裝的3種方法:

檢查:rpm -qa nfs-utils rpcbind ←最佳

1)方法1:yum -y install nfs-utils rpcbind

2)方法2:通過系統光盤裏的rpm包安裝,命令如:rpm -ivh nfs-utils-1.2.3-36.e16.x86_64.rpm

3)方法3:LANG=en

yum grouplist|grep -i nfs

yum groupinstall "NFS file server" -y


10.4.2使用方法1安裝所需軟件包

[root@NFS-server ~]# yum -y install nfs-utils rpcbind
Loaded plugins: fastestmirror, security
Setting up Install Process
Loading mirror speeds from cached hostfile
 * base: mirrors.sina.cn
 * extras: mirrors.opencas.cn
 * updates: centos.ustc.edu.cn
base                                      | 3.7 kB     00:00     
extras                                    | 3.4 kB     00:00     
extras/primary_db                         |  34 kB     00:00     
updates                                   | 3.4 kB     00:00     
updates/primary_db                        | 3.9 MB     00:04

10.4.3檢查安裝包是否安裝上

[root@NFS-server ~]# rpm -qa nfs-utils rpcbind
rpcbind-0.2.0-11.el6_7.x86_64
nfs-utils-1.2.3-64.el6.x86_64
[root@NFS-server ~]#

10.4.4 接下來啓動相應的服務

[root@NFS-server ~]# /etc/init.d/rpcbind status  <==檢查rpcbind服務狀態
rpcbind is stopped
[root@NFS-server ~]# rpcinfo -p localhost  <==rpcbind服務未啓動檢查 rpcinfo信息報錯
rpcinfo: can't contact portmapper: RPC: Remote system error - Connection refused
[root@NFS-server ~]# /etc/init.d/rpcbind start  <==啓動rpcbind服務
Starting rpcbind:                                          [  OK  ]
[root@NFS-server ~]# /etc/init.d/rpcbind status
rpcbind (pid  2083) is running...
[root@NFS-server ~]# /etc/init.d/nfs status  <==查看nfs服務狀態
rpc.svcgssd is stopped
rpc.mountd is stopped
nfsd is stopped
rpc.rquotad is stopped
[root@NFS-server ~]# /etc/init.d/nfs start  <==啓動nfs服務
Starting NFS services:                                     [  OK  ]
Starting NFS quotas:                                       [  OK  ]
Starting NFS mountd:                                       [  OK  ]
Starting NFS daemon:                                       [  OK  ]
Starting RPC idmapd:                                       [  OK  ]

10.4.5 設置開機自啓動

[root@NFS-server ~]# chkconfig --level 35  nfs on  <==設置nfs服務開機自啓動
[root@NFS-server ~]# chkconfig --list nfs
nfs             0:off   1:off   2:off   3:on    4:off   5:on    6:off
[root@NFS-server ~]# chkconfig --level 35 rpcbind on
[root@NFS-server ~]# chkconfig --list rpcbind     <==<==設置rpcbind服務開機自啓動
rpcbind         0:off   1:off   2:on    3:on    4:on    5:on    6:off

10.5 配置NFS服務端

10.5.1 NFS服務端配置文件路徑

NFS服務配置文件路徑爲:/etc/exports,並且默認是爲空。

[root@NFS-server ~]# ll /etc/exports
-rw-r--r--. 1 root root 0 Jan 12  2010 /etc/exports
[root@NFS-server ~]# cat /etc/exports
[root@NFS-server ~]#

10.5.2 編輯NFS服務端配置文件

[root@NFS-server ~]# vim /etc/exports
/data 192.168.1.0/24(rw,sync,all_squash)  <==添加如下內容
[root@NFS-server ~]# mkdir -p /data  <==創建共享目錄/data
[root@NFS-server ~]# ls -ld /data
drwxr-xr-x. 3 root root 4096 Nov 26 15:19 /data  <==當前共享目錄的屬主屬組分別爲root
[root@NFS-server ~]# chown -R nfsnobody.nfsnobody /data  <==修改/data及子文件屬主屬組爲nfsnobody
[root@NFS-server ~]# ls -ld /data                      
drwxr-xr-x. 3 nfsnobody nfsnobody 4096 Nov 26 15:19 /data

10.5.3 重新加載NFS服務(優雅重啓)

[root@NFS-server ~]# /etc/init.d/nfs reload ===exportfs -r
[root@NFS-server ~]# cat /var/lib/nfs/etab                
/data   192.168.1.0/24(rw,sync,wdelay,hide,nocrossmnt,secure,root_squash,all_squash,no_subtree_check,secure_locks,acl,anonuid=65534,anongid=65534,sec=sys,rw,root_squash,all_squash)
[root@NFS-server ~]# showmount -e 192.168.1.14 <==掛載前首先檢查有權限需要掛載的信息
Export list for 192.168.1.14:
/data 192.168.1.0/24 <---可以看到共享/data目錄

10.5.4 檢查或測試掛載

[root@NFS-server test]# mount -t nfs 192.168.1.14:/data /mnt
[root@NFS-server test]# df -h
Filesystem          Size  Used Avail Use% Mounted on
/dev/sda3           7.1G  1.5G  5.3G  22% /
tmpfs               279M     0  279M   0% /dev/shm
/dev/sda1           190M   36M  145M  20% /boot
192.168.1.14:/data  7.1G  1.5G  5.3G  22% /mnt

注意:

大型企業工作場景統一按照運維規範將服務的啓動寫到/etc/rc.local文件裏,而不用chkconfig管理。把/etc/rc.local文件作爲本機的重要檔案,所有服務的開機自啓動都必須放入/etc/rc.local。這樣規範的好處是,一旦有運維人員離職,或者業務遷移時都通過/etc/rc.local很容易查看服務器相關的服務,可以方便運維管理。並且把啓動命令放入到/etc/rc.local文件中一定要加上啓動服務的註釋。

[root@NFS-server test]# vim /etc/rc.local 
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.

touch /var/lock/subsys/local
#start up nfs services by zhurui at 20160226
/etc/init.d/rpcbind start <==開機自啓rpcbind服務
/etc/init.d/nfs start  <==開機自啓nfs服務

Web-lamp01客戶端部署:

1.安裝軟件
[root@Web-lamp01 ~]# yum -y install nfs-utils rpcbind   
Loaded plugins: fastestmirror, security
Setting up Install Process
Loading mirror speeds from cached hostfile
 * base: mirrors.sina.cn
 * extras: mirrors.opencas.cn
 * updates: centos.ustc.edu.cn
base                                             | 3.7 kB     00:00     
extras                                           | 3.4 kB     00:00     
extras/primary_db                                |  34 kB     00:00     
updates                                          | 3.4 kB     00:00 
2.啓動rpcbind
[root@Web-lamp01 ~]# /etc/init.d/rpcbind start
Starting rpcbind:                                          [  OK  ]
[root@Web-lamp01 ~]# 
3.配置開機自啓動
[root@Web-lamp01 ~]# chkconfig --level 35 rpcbind on
[root@Web-lamp01 ~]# chkconfig --list rpcbind
rpcbind         0:off   1:off   2:on    3:on    4:on    5:on    6:off
[root@Web-lamp01 ~]# 
4.測試服務端共享
[root@Web-lamp01 ~]# showmount -e 192.168.1.14
Export list for 192.168.1.14:
/data 192.168.1.0/24
5.掛載
[root@Web-lamp01 ~]# mount -t nfs 192.168.1.14:/data /mnt
[root@Web-lamp01 ~]# df -h
Filesystem          Size  Used Avail Use% Mounted on
/dev/sda3           7.1G  1.5G  5.3G  22% /
tmpfs               279M     0  279M   0% /dev/shm
/dev/sda1           190M   36M  145M  20% /boot
192.168.1.14:/data  7.1G  1.5G  5.3G  22% /mnt
6.測試讀,寫
服務器端:
[root@NFS-server test]# cd /data/
[root@NFS-server data]# ll
total 8
-rw-r--r--. 1 nfsnobody nfsnobody    0 Nov 28 12:20 fs.sf
drwxr-xr-x. 2 nfsnobody nfsnobody 4096 Nov 26 15:19 test
drwxr-xr-x. 2 nfsnobody nfsnobody 4096 Nov 28 12:20 zhurui
[root@NFS-server data]# mkdir zhurui1
[root@NFS-server data]# ll
total 12
-rw-r--r--. 1 nfsnobody nfsnobody    0 Nov 28 12:20 fs.sf
drwxr-xr-x. 2 nfsnobody nfsnobody 4096 Nov 26 15:19 test
drwxr-xr-x. 2 nfsnobody nfsnobody 4096 Nov 28 12:20 zhurui
drwxr-xr-x. 2 root      root      4096 Nov 28 12:21 zhurui1
客戶端:
[root@Web-lamp01 ~]# cd /mnt/
[root@Web-lamp01 mnt]# ll
total 4
drwxr-xr-x. 2 nobody nobody 4096 Nov 26 15:19 test
[root@Web-lamp01 mnt]# touch fs.sf
[root@Web-lamp01 mnt]# ll
total 4
-rw-r--r--. 1 nobody nobody    0 Nov 28 12:20 fs.sf
drwxr-xr-x. 2 nobody nobody 4096 Nov 26 15:19 test
[root@Web-lamp01 mnt]# mkdir zhurui
[root@Web-lamp01 mnt]# ls -ld zhurui/
drwxr-xr-x. 2 nobody nobody 4096 Nov 28 12:20 zhurui/
[root@Web-lamp01 mnt]# ll
total 12
-rw-r--r--. 1 nobody nobody    0 Nov 28 12:20 fs.sf
drwxr-xr-x. 2 nobody nobody 4096 Nov 26 15:19 test
drwxr-xr-x. 2 nobody nobody 4096 Nov 28 12:20 zhurui
drwxr-xr-x. 2 nobody nobody 4096 Nov 28 12:21 zhurui1
7.開機自啓動
[root@Web-lamp01 mnt]# vim /etc/rc.local

Web-lnmp02客戶端部署跟Web-lamp01部署步驟相同,這裏就不多加說明


10.6 mount掛載性能優化參數選項

(1)禁止更新目錄及文件時間戳掛載

mount -t nfs -o noatime,nodiratime 192.168.1.14:/data

(2)安全加優化的掛載方式

mount -t nfs -o nosuid,noexec,nodev,noatime,nodiratime,intr,rsize=131072,wsize=131072 192.168.1.14:/data /mnt

wKioL1bQLXqzy4n-AAD9GVWTmFw970.jpg

(3)默認的掛載方式

mount -t nfs 192.168.1.14:/data /mnt

10.7 NFS內核優化

對應的具體內核優化命令:


cat >>/etc/sysctl.conf<<EOF
net.core.wmem_default = 8388608
net.core.rmem_default = 8388608
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
EOF
執行sysctl -p生效











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