一 NFS集羣環境搭建準備
1.1 準備好NFS服務器
二 開始安裝NFS
2.1 環境信息確認
[root@LAMP ~]# cat /etc/redhat-release
CentOS release 6.7 (Final)
[root@LAMP ~]# uname -r
2.6.32-573.el6.x86_64
[root@LAMP ~]# uname -m
x86_64
2.2 NFS軟件列表
查看系統是否安裝:
[root@LAMP ~]# rpm -qa nfs-utils rpcbind
2.3 yum安裝軟件包
安裝epel yum源:
rpm -Uvhhttp://mirrors.kernel.org/fedora-epel/6/i386/epel-release-6-8.noarch.rpm
安裝nfs-utilsrpcbind包
[root@NFS-SER ~]# yum install nfs-utilsrpcbind
安裝完畢後檢查安裝結果:
[root@LAMP ~]# rpm -qa nfs-utils rpcbind
nfs-utils-1.2.3-64.el6.x86_64
rpcbind-0.2.0-11.el6_7.x86_64
TIPs:爲什麼所有客戶端都安裝nfs?因爲客戶端showmount命令在nfs裏面,如果不安裝找不到這條命令
三 啓動NFS及相關知識講解
3.1 服務的啓動順序
先把Rpcbind啓用:
[root@NFS-SER ~]# /etc/init.d/rpcbindstatus
rpcbind is stopped
[root@NFS-SER ~]# /etc/init.d/rpcbindstart
Starting rpcbind: [ OK ]
[root@NFS-SER ~]# lsof -i :111
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
rpcbind 25222 rpc 6u IPv4 34655 0t0 UDP *:sunrpc
rpcbind 25222 rpc 8u IPv4 34658 0t0 TCP *:sunrpc (LISTEN)
rpcbind 25222 rpc 9u IPv6 34660 0t0 UDP *:sunrpc
rpcbind 25222 rpc 11u IPv6 34663 0t0 TCP *:sunrpc (LISTEN)
[root@NFS-SER ~]# netstat -lntup|greprpcbind|grep -v grep
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 25222/rpcbind
tcp 0 0 :::111 :::* LISTEN 25222/rpcbind
udp 0 0 0.0.0.0:805 0.0.0.0:* 25222/rpcbind
udp 0 0 0.0.0.0:111 0.0.0.0:* 25222/rpcbind
udp 0 0 :::805 :::* 25222/rpcbind
udp 0 0 :::111 :::* 25222/rpcbind
[root@NFS-SER ~]# netstat -lntup|grep111
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 25222/rpcbind
tcp 0 0 :::111 :::* LISTEN 25222/rpcbind
udp 0 0 0.0.0.0:111 0.0.0.0:* 25222/rpcbind
udp 0 0 :::111 :::* 25222/rpcbind
[root@NFS-SER ~]# chkconfig --list |greprpcbind
rpcbind 0:off 1:off 2:on 3:on 4:on 5:on 6:off
再次啓用NFS服務
[root@NFS-SER ~]# netstat -lntup|grep2049
tcp 0 0 0.0.0.0:2049 0.0.0.0:* LISTEN -
tcp 0 0 :::2049 :::* LISTEN -
udp 0 0 0.0.0.0:2049 0.0.0.0:* -
udp 0 0 :::2049 :::* -
3.2 rpcbind 查看NFS共享的信息
[root@NFS-SER ~]# rpcinfo -p localhost
program vers proto port service
100000 4 tcp 111 portmapper
100000 3 tcp 111 portmapper
100000 2 tcp 111 portmapper
100000 4 udp 111 portmapper
100000 3 udp 111 portmapper
100000 2 udp 111 portmapper
100011 1 udp 875 rquotad
100011 2 udp 875 rquotad
100011 1 tcp 875 rquotad
100011 2 tcp 875 rquotad
100005 1 udp 45070 mountd
100005 1 tcp 51837 mountd
100005 2 udp 37124 mountd
100005 2 tcp 49654 mountd
100005 3 udp 59899 mountd
100005 3 tcp 59234 mountd
100003 2 tcp 2049 nfs
100003 3 tcp 2049 nfs
100003 4 tcp 2049 nfs
100227 2 tcp 2049 nfs_acl
100227 3 tcp 2049 nfs_acl
100003 2 udp 2049 nfs
100003 3 udp 2049 nfs
100003 4 udp 2049 nfs
100227 2 udp 2049 nfs_acl
100227 3 udp 2049 nfs_acl
100021 1 udp 42632 nlockmgr
100021 3 udp 42632 nlockmgr
100021 4 udp 42632 nlockmgr
100021 1 tcp 59242 nlockmgr
100021 3 tcp 59242 nlockmgr
100021 4 tcp 59242 nlockmgr
[root@NFS-SER ~]# chkconfig --list nfs
nfs 0:off 1:off 2:off 3:off 4:off 5:off 6:off
[root@NFS-SER ~]# chkconfig nfs on
從這裏看出,NFS開啓了很多的服務。
3.3 開機自啓動順序情況
Less /etc/init.d/rpcbind
Less /etc/init.d/nfs
3.4 配置開機自啓動
四 NFS服務常見進程詳解說明
[root@NFS-SER ~]# ps -ef |egrep"rpc|nfs"
rpc 25222 1 0 03:33 ? 00:00:00 rpcbind
root 25310 2 0 03:39 ? 00:00:00 [rpciod/0]
root 25319 1 0 03:39 ? 00:00:00rpc.rquotad 磁盤配額進程
root 25324 1 0 03:39 ? 00:00:00 rpc.mountd 權限管理驗證等
root 25331 2 0 03:39 ? 00:00:00 [nfsd4]
root 25332 2 0 03:39 ? 00:00:00 [nfsd4_callbacks]
root 25333 2 0 03:39 ? 00:00:00 [nfsd] nfs主進程
root 25334 2 0 03:39 ? 00:00:00 [nfsd] nfs主進程
root 25335 2 0 03:39 ? 00:00:00 [nfsd] nfs主進程
root 25336 2 0 03:39 ? 00:00:00 [nfsd] nfs主進程
root 25337 2 0 03:39 ? 00:00:00 [nfsd] nfs主進程
root 25338 2 0 03:39 ? 00:00:00 [nfsd] nfs主進程
root 25339 2 0 03:39 ? 00:00:00 [nfsd] nfs主進程
root 25340 2 0 03:39 ? 00:00:00 [nfsd] nfs主進程
root 25371 1 0 03:39 ? 00:00:00 rpc.idmapd name maping daem
root 25403 2295 0 03:56 pts/0 00:00:00 grep -E rpc|nfs
五 NFS實戰配置服務端
5.1 默認配置文件介紹
NFS默認配置文件/etc/exports是存在的,但是默認是沒有內容的,需要配置。有些Linux版本不提供這個配置文件,需要手動創建。
Man exports 我們可以看到exports的書寫格式
5.2配置exports文件
vim /etc/exports
[root@NFS-SER ~]# /etc/init.d/nfs reload
exportfs: Failed to stat /nfs_data: Nosuch file or directory
[root@NFS-SER ~]# mkdir /nfs_data
[root@NFS-SER ~]# /etc/init.d/nfs reload
[root@NFS-SER ~]# exportfs -rv
exporting 10.0.0.*:/nfs_data
[root@NFS-SER~]# grep -A 1 "reload" /etc/init.d/nfs exports –r 爲什麼等於reload
reload | force-reload)
/usr/sbin/exportfs -r
--
echo $"reload"; exit 0
fi
--
echo $"Usage: nfs {start|stop|status|restart|reload|force-reload|condrestart|try-restart|condstop}"
RETVAL=2
[root@NFS-SER ~]#
5.3 NFS測試
[root@NFS-SER ~]# showmount -e 127.0.0.1
Export list for 127.0.0.1:
/nfs_data 10.0.0.*
[root@NFS-SER ~]#
[root@NFS-SER ~]# mount -t nfs 10.0.0.100:/nfs_data/mnt
[root@NFS-SER ~]# mount
/dev/sda3 on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts(rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs(rw,rootcontext="system_u:object_r:tmpfs_t:s0")
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc typebinfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs typerpc_pipefs (rw)
nfsd on /proc/fs/nfsd type nfsd (rw)
10.0.0.100:/nfs_data on /mnt type nfs(rw,vers=4,addr=10.0.0.100,clientaddr=10.0.0.100)
[root@NFS-SER ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 7.1G 1.5G 5.3G 21% /
tmpfs 491M 0 491M 0% /dev/shm
/dev/sda1 190M 36M 145M 20% /boot
10.0.0.100:/nfs_data 7.1G 1.5G 5.3G 21% /mnt
六 客戶端配置
#/etc/init.d/rpcbind start
#chkconfig rpcbind on
#vim /etc/rc.local
#setenforce 0
#getenforce
#etc/init.d/iptables status
#chkconfig --list|grep iptables
#etc/init.d/iptables stop
#chkconfig iptables off
[root@LAMP~]# showmount -e 10.0.0.100 這裏可以看到NFS-SER端共享的目錄
Export list for 10.0.0.100:
/nfs_data 10.0.0.*
[root@LAMP~]# mount -t nfs 10.0.0.100:/nfs_data /mnt 掛載到本地/mnt下
[root@LAMP ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 7.1G 1.5G 5.3G 21% /
tmpfs 491M 0 491M 0% /dev/shm
/dev/sda1 190M 36M 145M 20% /boot
10.0.0.100:/nfs_data 7.1G 1.5G 5.3G 21% /mnt
[root@LAMPmnt]# ls 這裏可以看到服務端創建的文件
t1.txt
這個時候在客戶端是不能給這個共享目錄創建文件,沒有寫到權限,這個是nfs默認配置的:
[root@NFS-SER ~]# cat /var/lib/nfs/etab
/nfs_data 10.0.0.*(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)
這裏我們看到,默認是65534這個uid和gid用戶和組,所有我們要給nfs共享的這個目錄修改權限:
[root@NFS-SER~]# ll /nfs_data/ 查看nfs_data目錄權限
total 0
-rw-r--r--. 1 root root 0 Mar 1 04:22 t1.txt
[root@NFS-SER~]# cat /var/lib/nfs/etab nfs默認參數配置信息
/nfs_data 10.0.0.*(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)
[root@NFS-SER~]# grep 65534 /etc/passwd 查看65534屬於哪個用戶
nfsnobody:x:65534:65534:Anonymous NFSUser:/var/lib/nfs:/sbin/nologin
[root@NFS-SER~]# chown -R 65534 /nfs_data 修改nfs_data共享目錄的權限
[root@NFS-SER ~]# ll /nfs_data/
total 0
-rw-r--r--. 1 nfsnobody root 0 Mar 1 04:22 t1.txt
[root@NFS-SER ~]#
[root@LAMPmnt]# touch Lamp.txt 測試客戶端是可以寫了
[root@LAMP mnt]# ls
Lamp.txt t1.txt
[root@LAMP mnt]#
最後,在客戶端我們要把掛載命令寫入到rc.loal配置文件裏面。
七 NFS常見故障排查及解決方案
附加:★NFS常見故障排除
-------------------
1、Therpcbind failure error
故障現象:
nfs mount: server1:: RPC: Rpcbind failure
RPC: Timed Out
nfs mount: retrying: /mntpoint
原因:
第一,可能因爲客戶機的hosts文件中存在錯誤的ip地址、主機名或節點名組合;
第二,服務器因爲過載而暫時停止服務。
2、Theserver not responding error
現象:
NFS server server2 not responding, still trying
原因:
第一,網絡不通,用ping命令檢測一下。
第二,服務器關機。
3、The NFSclient fails a reboot error
現象:
啓動客戶機後停住了,不斷顯示如下提示信息:
Setting default interface for multicast: add net 224.0.0.0: gateway:
client_node_name.
原因:
在etc/vfstab的mount選項中使用了fg而又無法成功mount服務器上的資源,改成bg或將該行註釋掉,直到服務器可用爲止。
4、Theservice not responding error
現象:
nfs mount: dbserver: NFS: Service not responding
nfs mount: retrying: /mntpoint
原因:
第一,當前級別不是級別3,用who –r查看,用init切換。
第二,NFSServer守護進程不存在,用ps–ef | grep nfs檢查,用/etc/init.d/nfs.serverstart啓動。
5、Theprogram not registered error
現象:
nfs mount: dbserver: RPC: Program not registered
nfs mount: retrying: /mntpoint
原因:
第一,當前級別不是級別3。
第二,mountd守護進程沒有啓動,用/etc/init.d/nfs.server腳本啓動NFS守護進程。
第三,看/etc/dfs/dfstab中的條目是否正常。
6、Thestale file handle error
現象:
stale NFS file handle
原因:
服務器上的共享資源移動位置了,在客戶端使用umount和mount重新掛接就可以了。
7、The unknownhost error
現象:
nfs mount: sserver1:: RPC: Unknown host
原因:
hosts文件中的內容不正確。
8、Themount point error
現象:
mount: mount-point /DS9 does not exist.
原因:
該掛接點在客戶機上不存在,注意檢查命令行或/etc/vfstab文件中相關條目的拼寫。
9、The nosuch file error
現象:
No such file or directory.
原因:
該掛接點在服務器上不存在,注意檢查命令行或/etc/vfstab文件中相關條目的拼寫。
10、Noroute to host
錯誤現象:
[root@msa30 sysconfig]# mount 10.10.11.211:/opt/b2b-data/xmldb /b2b-web1/b2b-data/xmldb -t nfs -o rw
mount: mount to NFS server '10.10.11.211' failed: System Error: No route tohost.
原因:
防火牆被打開,關閉防火牆。
11、Notowner
現象:
[root@msa30:/founder/shell]# mount -F nfs -o rw10.10.2.3:/mnt/b2b/b2b-data/resinfo2 /data/b2b-data/resinfo2
nfs mount: mount: /data/b2b-data/resinfo2: Not owner
原因:
這是Solaris10版本掛載較低版本nfs時報的錯誤。
解決:
需要用-overs=3參數
示例:
[root@msa30:/founder/shell]# mount -F nfs -o vers=3 10.10.2.3:/mnt/b2b/b2b-data/resinfo2 /data/b2b-data/resinfo2
12、RPC:Program not registered & retrying
現象:
nfs mount: 10.10.2.3: : RPC: Program not registered
nfs mount: retrying: /data/b2b-data/resinfo2
原因:
沒有啓動NFS共享端服務。
解決:需要重新啓動share端的NFS服務,
Linux:
mount: RPC: Program not registered
#service nfs restart
Solaris:
mount: RPC: Program not registered
#/etc/rc.d/init.d/nfs restart
13、can'tcontact portmapper: RPC: Remote system error - Connection refused
現象:
#exportfs -a
can't contact portmapper: RPC: Remote system error - Connection refused
原因:
出現這個錯誤信息是由於SEVER端的PORTMAP沒有啓動。
解決:
#service portmap start
#service pcmcia start
八 NFS服務端的權限參數詳解
Async 異步寫入數據,先寫入內存當中,缺點是延遲,丟數據
Sync 同步數據寫入到硬盤中,數據安全,但是性能比不加這個參數差
no_root_squash,如果客戶端是root權限,那麼訪問這個目錄後也有root權限,用於無盤工作站
root_squash 把普通用戶映射成root用戶
all_squash 把所有客戶端都壓縮成指定的匿名用戶。這個匿名用戶就是/var/lib/nfs/etab 下默認的用戶。工作中默認最好是加上。
九 NFS重點知識梳理
十 NFS 客戶端mount 掛載深入
十一 客戶端優化
11.1 安全的掛載
11.2 掛載性能優化
11.3 掛載內核優化
11.4 生產場景NFS共享優化[K1]
12 NFS效率不高如何解決:
優點:
簡單:容易上手,容易掌握
NFS 文件系統內數據是在文件系統之上,是可以看見的
方便:部署快速,維護簡單,可控且滿足需求是最好的
穩定: 非常穩定
可靠:從軟件層面上看,數據可靠性高經久耐用。
侷限:
1. 存在單點故障,如果NFS-SERVER宕機,所有客戶端都無法訪問。
2. 大數據高併發的場合NFS 幾千萬的pv
3. 客戶端認識時候基於IP和主機名,安全性一般。沒有密碼
4. 多臺客戶端掛一個服務端,維護麻煩。
Autofs 介紹
作用就是:客戶端需要時候,我給你掛載。沒有請求時候我就卸載掉。
[K1]多塊網卡BOND 如何操作??