13-3 14 NFS

14.1 NFS介紹

NFS用於在網絡上共享存儲mysql

  • NFS是Network File System的縮寫
  • NFS最先由Sun公司開發,分2,3,4三個版本,2和3由Sun起草開發,4.0開始Netapp公司參與並主導開發,最新爲4.1版本
  • NFS數據傳輸基於RPC協議,RPC爲Remote Procedure Call的簡寫。
  • NFS應用場景是:A,B,C三臺機器上須要保證被訪問到的文件是同樣的,A共享數據出來,B和C分別去掛載A共享的數據目錄,從而B和C訪問到的數據和A上的一致

NFS原理圖sql

14.2 NFS服務端安裝配置

服務端與客戶端都須要安裝nfs-util包vim

[root@axiang-02 ~]# yum install -y nfs-utils
[root@axiang-03 ~]# yum install -y nfs-utils

新增配置文件(原來沒有)網絡

vim /etc/exports
加入一行:
/home/nfstestdir 192.168.133.0/24(rw,sync,all_squash,anonuid=1000,anongid=1000)
  • 第一段爲定義共享的目錄
  • 第二段爲容許訪問的IP或IP段
  • 第三段即括號內容爲權限選項

服務端啓動app

[root@axiang-02 ~]# mkdir /home/nfstestdir
[root@axiang-02 ~]# chmod 777 !$  //方便實驗
chmod 777 /home/nfstestdir

[root@axiang-02 ~]# systemctl start rpcbind
[root@axiang-02 ~]# systemctl start nfs
[root@axiang-02 ~]# systemctl enable rpcbind  //開機啓動
[root@axiang-02 ~]# systemctl enable nfs    //開機啓動
[root@axiang-02 ~]# netstat -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      1/systemd   //111端口即rpc監聽端口

14.3 NFS配置選項

  • rw 讀寫
  • ro 只讀
  • sync 同步模式,內存數據實時寫入磁盤
  • async 非同步模式
  • no_root_squash 客戶端掛載NFS共享目錄後,root用戶不受約束,權限很大
  • root_squash 與上面選項相對,客戶端上的root用戶收到約束,被限定成某個普通用戶
  • all_squash 客戶端上全部用戶在使用NFS共享目錄時都被限定爲一個普通用戶
  • anonuid/anongid 和上面幾個選項搭配使用,定義被限定用戶的uid和gid

客戶端掛載async

安裝完不用設置,須要關閉防火牆。即便放行111端口。因此建議先把兩邊防火牆關掉。便可使用tcp

[root@axiang-02 ~]# iptables -F 或者 systemctl stop firewalld
[root@axiang-03 ~]# iptables -F 或者 systemctl stop firewalld
[root@axiang-03 ~]# showmount -e 10.1.1.8
Export list for 10.1.1.8:
/home/nfstestdir 10.1.1.0/24
[root@axiang-03 ~]# mount -t nfs 10.1.1.8:/home/nfstestdir /mnt
[root@axiang-03 ~]# df -h
10.1.1.8:/home/nfstestdir   18G  7.1G   11G   40% /mnt
[root@axiang-03 ~]# cd /mnt
[root@axiang-03 mnt]# touch 111.txt
[root@axiang-03 mnt]# ll
總用量 0
-rw-r--r-- 1 mysql mysql 0 8月  23 15:49 111.txt

成功共享存儲。且限定用戶id爲1000ui

[root@axiang-02 ~]# ll /home/nfstestdir/
總用量 0
-rw-r--r-- 1 mysql mysql 0 8月  23 15:49 111.txt
[root@axiang-02 ~]# id mysql
uid=1000(mysql) gid=1000(mysql) 組=1000(mysql)
相關文章
相關標籤/搜索