【Linux】 NFS服務器實現開機自動掛載
文章目錄
NFS服務介紹
NFS存儲服務作用
安裝NFS:
1) yum安裝nfs
2) 配置文件位置
3) 啟動NFS服務
使用方法
1) 創建共享目錄
2) 設置配置文件并查看
3) 客戶端測試
NFS共享的常用參數
設置自動掛載NFS
總結
NFS,是Network File System的簡寫,即網絡文件系統。網絡文件系統是FreeBSD支持的文件系統中的一種,NFS允許一個系統在網絡上與他人共享目錄和文件。
它的主要功能是通過網絡(一般是局域網)讓不同的主機系統之間可以共享文件或目錄
通過使用NFS,用戶和程序可以像訪問本地文件一樣訪問遠端系統上的文件,如圖:
NFS的模式: C/S 模式
NFS監聽的端口: 2049
RHEL7是以NFSv4作為默認版本,NFSv4使用TCP協議(端口號是2049)和NFS服務器建立連接。
在/etc/services里定義了nfs的端口號
實現數據的共享存儲
編寫數據操作管理
節省購買服務器磁盤開銷 淘寶–上萬 用電開銷
[root@gaosh-64 ~]# yum install rpcbind nfs-utils
[root@gaosh-64 ~]# ls /etc/exports /etc/exports
1
2
[root@gaosh-64 ~]# systemctl restart rpcbind [root@gaosh-64 ~]# systemctl start nfs-server.service [root@gaosh-64 ~]# [root@gaosh-64 ~]# netstat -antup |grep 2049 tcp 0 0 0.0.0.0:2049 0.0.0.0:* LISTEN - tcp6 0 0 :::2049 :::* LISTEN - udp 0 0 0.0.0.0:2049 0.0.0.0:* - udp6 0 0 :::2049 :::* -
1
2
3
4
5
6
7
8
9
[root@gaosh-64 ~]# mkdir -p /share/{dir1,dir2} [root@gaosh-64 ~]# chmod -R 777 /share/ #給共享目錄寫的權限 [root@gaosh-64 ~]# ll /share/ 總用量 0 drwxrwxrwx 2 root root 6 7月 18 20:42 dir1 drwxrwxrwx 2 root root 6 7月 18 20:42 dir2
1
2
3
4
5
6
7
[root@gaosh-64 ~]# cat /etc/exports /share/dir1 *(ro) #只讀 /share/dir2 192.168.1.0/24(rw,sync) #讀寫
1
2
3
[root@gaosh-64 ~]# systemctl restart nfs.service #啟動 [root@gaosh-64 ~]# exportfs -v #檢查當前主機的NFS輸出(共享) /share/dir2 192.168.1.0/24(sync,wdelay,hide,no_subtree_check,sec=sys,rw,secure,root_squash,no_all_squash) /share/dir1
1
2
3
4
5
6
[root@gaosh-17 ~]# showmount -e 192.168.1.64 #查看存儲端共享 Export list for 192.168.1.64: /share/dir1 * /share/dir2 192.168.1.0/24 [root@gaosh-17 ~]#
1
2
3
4
5
6
掛載測試:
[root@gaosh-17 ~]# showmount -e 192.168.1.64 [root@gaosh-17 ~]# mkdir /mnt/test1 [root@gaosh-17 ~]# mkdir /mnt/test2 [root@gaosh-17 ~]# mount -t nfs 192.168.1.64:/share/dir1 /mnt/test1 [root@gaosh-17 ~]# mount -t nfs 192.168.1.64:/share/dir2 /mnt/test2 [root@gaosh-17 ~]# df -h 192.168.1.64:/share/dir1 17G 4.7G 13G 28% /mnt/test1 192.168.1.64:/share/dir2 17G 4.7G 13G 28% /mnt/test2
1
2
3
4
5
6
7
8
在上文中我們設置的test1 為只讀,test2 為可讀寫
為了驗證這一點,我們只需要復制一個文件過去查看即可
[root@gaosh-17 ~]# cp /etc/passwd /mnt/test1/ #只讀文件系統,無法復制文件進去 cp: 無法創建普通文件"/mnt/test1/passwd": 只讀文件系統 [root@gaosh-17 ~]# cp /etc/passwd /mnt/test2/
1
2
3
我們已經使用過ro和rw,sync, 三個參數,除此之外還有很多,如下表:
直接在配置文件 /etc/fstab里設置
[root@gaosh-17 ~]# grep '192.168.1.64' /etc/fstab 192.168.1.64:/share/dir1 /mnt/test1 nfs deaults 0 0
1
2
3
本文主要探討了NFS的安裝,及使用,實現的NFS開機自動掛載。 為了防止單點NFS,也是可以使用keepalived做高可用的。當你當前的服務器硬盤不夠用的時候,你可以使用NFS服務,分享一個硬盤過來使用。
Linux 網絡
版權聲明:本文內容由網絡用戶投稿,版權歸原作者所有,本站不擁有其著作權,亦不承擔相應法律責任。如果您發現本站中有涉嫌抄襲或描述失實的內容,請聯系我們jiasou666@gmail.com 處理,核實后本網站將在24小時內刪除侵權內容。
版權聲明:本文內容由網絡用戶投稿,版權歸原作者所有,本站不擁有其著作權,亦不承擔相應法律責任。如果您發現本站中有涉嫌抄襲或描述失實的內容,請聯系我們jiasou666@gmail.com 處理,核實后本網站將在24小時內刪除侵權內容。