Kerberized NFSv4 with NIS
<!--[if !supportLists]-->一、<!--[endif]-->環境
kdc:server1.example.com 192.168.32.31
nfs&nis server: station2.example.com 192.168.32.32
nfs&nis client: station3.example.com 192.168.32.33
注:默認kerberos和nis環境已有配置
<!--[if !supportLists]-->二、<!--[endif]-->NFSv4 Server配置
<!--[if !supportLists]-->1、 <!--[endif]-->固定相關端口,並開啓安全功能
[root@station2 ~]# vi /etc/sysconfig/nfs
LOCKD_TCPPORT=4001
LOCKD_UDPPORT=4001
MOUNTD_PORT=4002
STATD_PORT=4003
SECURE_NFS="yes"
#啓動nfs4必須開啓此選項,默認nfs4只支持tcp
<!--[if !supportLists]-->2、 <!--[endif]-->綁定mount需要共享的文件夾(即僞裝共享的真實目錄)
[root@station2 ~]#mkdir –p /export/nfs
[root@station2 ~]#mount --bind /home/nfs /export/nfs
[root@station2 ~]#vi /etc/fstab
/home/nfs /exports/nfs none bind 0 0
#共享的真實目錄是/home/nfs但客戶看到的將是/exports/nfs目錄
<!--[if !supportLists]-->3、 <!--[endif]-->設置NFSv4共享
[root@station2 ~]#vi /etc/exports
/exports gss/krb5p(rw,fsid=0,crossmnt)
/exports/nfs gss/krb5p(rw)
#使用fsid=0選項的時候只能共享一個目錄,這個目錄將成爲NFS服務器的根目錄。要通過NFS4共享一個目錄,首先需要在/etc/exports文件中定義這個目錄,並且使用 fsid=0 的參數。
#注kerberos認證支持三種模式:
gss/sys:只要有kerberos票據解決使用nfs共享目錄,nfsv3也支持此項
gss/krb5i:kerberos會檢查數據的完整性
gss/krb5p:kerberos會讀nfs共享數據進行加密
<!--[if !supportLists]-->4、 <!--[endif]-->在kdc中添加nfs服務器服務,並導出票據
[root@station2 ~]# kadmin
kadmin: addprinc -e des-cbc-md5:normal -randkey nfs/station2.example.com
kadmin: ktadd -e des-cbc-md5:normal -k /etc/krb5.keytab nfs/station2.example.com
[root@station2 ~]# ktutil #查看票據
ktutil: rkt /etc/krb5.keytab
ktutil: list
slot KVNO Principal
---- ---- -------------------------------------------------------------
1 4 host/[email protected]
2 4 host/[email protected]
3 4 host/[email protected]
4 4 host/[email protected]
<!--[if !supportLists]-->5、 <!--[endif]-->啓動服務器端相關服務(nfs、rpcsvcgssd、rpcidmapd)
[root@station2 ~]# service nfs start
啓動 RPC svcgssd: [確定]
啓動 NFS 服務: [確定]
關掉 NFS 配額: [確定]
啓動 NFS 守護進程: [確定]
啓動 NFS mountd: [確定]
#開啓nfsv4後,啓動nfs服務是會自動啓動rpcsvcgssd服務
[root@station2 ~]# service rpcidmapd start
<!--[if !supportLists]-->三、<!--[endif]-->NFSv4 Client配置
<!--[if !supportLists]-->1、 <!--[endif]-->開啓安全功能
[root@station3 ~]# vi /etc/sysconfig/nfs
SECURE_NFS="yes"
#要故障nfs4目錄客戶端也必須開啓此選項
<!--[if !supportLists]-->2、 <!--[endif]-->在kdc中添加nfs客戶端服務,並導出票據
[root@station3 ~]# kadmin
kadmin: addprinc -e des-cbc-md5:normal -randkey nfs/station3.example.com
kadmin: ktadd -e des-cbc-md5:normal -k /etc/krb5.keytab nfs/station3.example.com
[root@station3 ~]# ktutil
ktutil: rkt /etc/krb5.keytab
ktutil: list
slot KVNO Principal
---- ---- -------------------------------------------------------------
1 5 host/[email protected]
2 5 host/[email protected]
3 5 host/[email protected]
4 5 host/[email protected]
<!--[if !supportLists]-->3、 <!--[endif]-->啓動客戶端相關服務(rpcgssd、rpcidmapd)
[root@station3 ~]#sevice rpcgssd start
[root@station3 ~]#service rpcidmapd start
<!--[if !supportLists]-->4、 <!--[endif]-->掛載服務器共享目錄
[root@station3 ~]#mkdir /home/nfs
[root@station3 ~]#mount -t nfs4 -o rw,sec=krb5p 192.168.32.32:/nfs /home/nfs
#掛載時必須用-t nfs4 :掛載nfs4的共享目錄
#-o sec=krb5p:利用kerberos加密認證,與服務器向對應
[root@station3 ~]#vi /etc/fstab
192.168.32.32:/home/nfs /home/nfs nfs4 defaults,sec=krb5p 0 0
#開機自動掛載
<!--[if !supportLists]-->5、 <!--[endif]-->測試
[root@station3 ~]# su - netsword
[netsword@station3 ~]$ su - guest2001
口令:
-bash-3.2$ pwd
/home/nfs/guest2001
#只有獲擁有kdc認證票據的guest2001等用戶才能登錄並使用nfs4共享的目錄