NFS Server with openSUSE Leap 42.3
OS: openSUSE Leap 42.3
目的: 提供 NFS version 3 and NFS version 4 檔案分享
使用 zypper 安裝相關套件
# zypper install yast2-nfs-server
Loading repository data...
Reading installed packages...
Resolving package dependencies...
The following 2 NEW packages are going to be installed:
nfs-kernel-server yast2-nfs-server
The following recommended package was automatically selected:
nfs-kernel-server
2 new packages to install.
Overall download size: 241.2 KiB. Already cached: 0 B. After the operation, additional 659.3 KiB will be used.
Continue? [y/n/...? shows all options] (y):
建立分享目錄
# mkdir /dmshare
設定權限
# chmod o+w /dmshare/
還沒設定前, 先觀察相關資訊
# rpcinfo -p localhost
localhost: RPC: Port mapper failure - Unable to receive: errno 111 (Connection refused)
# cat /etc/exports
# See the exports(5) manpage for a description of the syntax of this file.
# This file contains a list of all directories that are to be exported to
# other computers via NFS (Network File System).
# This file used by rpc.nfsd and rpc.mountd. See their manpages for details
# on how make changes in this file effective.
# systemctl status nfsserver.service
● nfsserver.service - Alias for NFS server
Loaded: loaded (/usr/lib/systemd/system/nfsserver.service; disabled; vendor preset: disabled)
Active: inactive (dead)
檢查 NFS4_SUPPORT 是否有啟用
# grep NFS4 /etc/sysconfig/nfs
NFS4_SUPPORT="yes"
NFS4_SERVER_MINOR_VERSION="0"
使用 YaST 方式設定 NFS
啟動 yast2 nfs_server 模組
# yast2 nfs_server
點選 Start -- > 點選 Next
設定要分享的目錄
點選 Add Directory
輸入或是選取要分享的目錄, 這邊以 /dmshare 為例
點選 OK
接下來針對分享目錄的設定
針對 主機或是選項進行調整, 請注意預設值選項有 ro ( read-only )
點選 OK
確認相關資訊 -- > 點選 Finish
觀察相關資訊,
這邊會看到 v3 的 port 111 with portmapper 以及 v4 port 2049
# 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
100024 1 udp 47009 status
100024 1 tcp 40382 status
100005 1 udp 20048 mountd
100005 1 tcp 20048 mountd
100005 2 udp 20048 mountd
100005 2 tcp 20048 mountd
100005 3 udp 20048 mountd
100005 3 tcp 20048 mountd
100003 3 tcp 2049 nfs
100003 4 tcp 2049 nfs
100227 3 tcp 2049 nfs_acl
100003 3 udp 2049 nfs
100003 4 udp 2049 nfs
100227 3 udp 2049 nfs_acl
100021 1 udp 58709 nlockmgr
100021 3 udp 58709 nlockmgr
100021 4 udp 58709 nlockmgr
100021 1 tcp 44774 nlockmgr
100021 3 tcp 44774 nlockmgr
100021 4 tcp 44774 nlockmgr
觀察設定檔 /etc/exports, 這邊我有針對特定網段才能進行連線, 以及給 rw 設定
# cat /etc/exports
/dmshare xxx.xxx.xxx.0/24(rw,root_squash,sync,no_subtree_check)
觀察服務狀態
# systemctl status nfsserver.service
● nfsserver.service - Alias for NFS server
Loaded: loaded (/usr/lib/systemd/system/nfsserver.service; enabled; vendor preset: disabled)
Active: active (exited) since Thu 2018-02-08 10:48:30 CST; 4min 26s ago
Process: 9921 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
Main PID: 9921 (code=exited, status=0/SUCCESS)
Tasks: 0 (limit: 512)
CGroup: /system.slice/nfsserver.service
Feb 08 10:48:30 nfs systemd[1]: Starting Alias for NFS server...
Feb 08 10:48:30 nfs systemd[1]: Started Alias for NFS server.
因為是使用 YaST 設定的, 所以會把開機啟動也設定完成
# systemctl is-enabled nfsserver.service
enabled
接下來進行相關測試
於用戶端進行掛載測試
Client side:
觀察Server 分享目錄
# showmount -e 對方IP
建立掛載目錄
# mkdir /mnt/nfs
測試掛載
# mount xxx.xxx.xxx.xxx:/dmshare /mnt/nfs
觀察掛載狀況 , 這邊很有趣的是, 不需要特別指定 type 就會掛載 nfs v4
# mount | grep dmshare
xxx.xxx.xxx.xxx:/dmshare on /mnt/nfs type nfs4 (rw,relatime,vers=4.0,rsize=524288,wsize=524288,namlen=255,hard,proto=tcp,port=0,timeo=600,retrans=2,sec=sys,clientaddr=xxx.xxx.xxx.xxx,local_lock=none,addr=xxx.xxx.xxx.xxx)
測試建立檔案
# touch /mnt/nfs/nfstest
觀察資訊, 因為有做 root_squash , 所以會被轉成 nobody
# ls -l /mnt/nfs/
total 0
-rw-r--r-- 1 nobody nogroup 0 Feb 8 11:31 nfstest
同場加映, 如何知道 NFS version 4 client 連線狀況
在 Server 端
# netstat | grep :nfs
tcp 0 0 linux-xp5z.suse:nfs xxx.xxx.xxx.xxx:726 ESTABLISHED
Reference
~ enjoy it
沒有留言:
張貼留言