NFS介紹、NFS服務端安裝配置、NFS配置選項介紹

NFS介紹

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服務須要藉助RPC服務去通訊。mysql

NFS介紹、NFS服務端安裝配置、NFS配置選項介紹
NFS介紹、NFS服務端安裝配置、NFS配置選項介紹

NFS服務端安裝配置

1.安裝應用包

服務端linux

[root@gary-tao ~]# yum install -y nfs-utils rpcbind

客戶端sql

[root@gary-tao ~]# yum install -y nfs-utils
2.修改配置文件
[root@gary-tao ~]# vim /etc/exports

增長以下配置內容:

/home/nfstestdir 192.168.133.0/24(rw,sync,all_squash,anonuid=1000,anongid=1000)

//註解:

第一部分是本地要共享出去的目錄。
第二部分是容許訪問的主機(能夠是一個IP,也能夠是一個IP段)
第三部分就是小括號裏面的一些權限選項。
3.建立目錄及更改權限
[root@gary-tao ~]# mkdir /home/nfstestdir
[root@gary-tao ~]# chmod 777 /home/nfstestdir/
4.啓動NFS服務
[root@gary-tao ~]# systemctl start nfs  //啓動nfs服務
[root@gary-tao ~]# ps aux |grep nfs
root      13990  0.0  0.0      0     0 ?        S<   21:40   0:00 [nfsd4_callbacks]
root      13996  0.0  0.0      0     0 ?        S    21:40   0:00 [nfsd]
root      13997  0.0  0.0      0     0 ?        S    21:40   0:00 [nfsd]
root      13998  0.0  0.0      0     0 ?        S    21:40   0:00 [nfsd]
root      13999  0.0  0.0      0     0 ?        S    21:40   0:00 [nfsd]
root      14000  0.0  0.0      0     0 ?        S    21:40   0:00 [nfsd]
root      14001  0.0  0.0      0     0 ?        S    21:40   0:00 [nfsd]
root      14002  0.0  0.0      0     0 ?        S    21:40   0:00 [nfsd]
root      14003  0.0  0.0      0     0 ?        S    21:40   0:00 [nfsd]
root      14007  0.0  0.0 112684   976 pts/1    S+   21:40   0:00 grep --color=auto nfs
[root@gary-tao ~]# ps aux |grep rpc
rpc       13799  0.0  0.1  64964  1412 ?        Ss   21:25   0:00 /sbin/rpcbind -w
rpcuser   13963  0.0  0.1  42380  1748 ?        Ss   21:40   0:00 /usr/sbin/rpc.statd
root      13964  0.0  0.0      0     0 ?        S<   21:40   0:00 [rpciod]
root      13969  0.0  0.0  42564   944 ?        Ss   21:40   0:00 /usr/sbin/rpc.mountd
root      13980  0.0  0.0  21404   536 ?        Ss   21:40   0:00 /usr/sbin/rpc.idmapd
root      14009  0.0  0.0 112680   976 pts/1    R+   21:41   0:00 grep --color=auto rpc
[root@gary-tao ~]# systemctl enable nfs  //設置nfs開機啓動
Created symlink from /etc/systemd/system/multi-user.target.wants/nfs-server.service to /usr/lib/systemd/system/nfs-server.service.
[root@gary-tao ~]# systemctl start rpcbind   //啓動rpc服務
[root@gary-tao ~]# systemctl enable rpcbind  //設置rpc開機啓動

NFS配置選項

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

客戶端掛載NFS

[root@gary ~]# showmount -e 172.16.111.100  //查看NFS的共享狀況 
clnt_create: RPC: Port mapper failure - Unable to receive: errno 113 (No route to host)

//以上報錯緣由是由防火牆致使,按下面方法關閉服務端與客戶端的防火牆

[root@gary ~]# systemctl stop firewalld //關閉防火牆
[root@gary ~]# getenforce     //關閉seLinux
Enforcing
[root@gary ~]# setenforce 0
[root@gary ~]# showmount -e 172.16.111.100
Export list for 172.16.111.100:
/home/nfstestdir 172.16.111.0/24
[root@gary ~]# mount -t nfs 172.16.111.100:/home/nfstestdir /mnt/   //掛載服務端nfs
[root@gary ~]# df -h  //查看磁盤掛載
文件系統                         容量  已用  可用 已用% 掛載點
/dev/sda3                         18G  1.1G   17G    7% /
devtmpfs                         479M     0  479M    0% /dev
tmpfs                            489M     0  489M    0% /dev/shm
tmpfs                            489M   19M  470M    4% /run
tmpfs                            489M     0  489M    0% /sys/fs/cgroup
/dev/sda1                        197M  109M   88M   56% /boot
tmpfs                             98M     0   98M    0% /run/user/0
172.16.111.100:/home/nfstestdir   18G  6.9G   11G   39% /mnt

客戶端創建文件測試:vim

[root@gary ~]# cd /mnt/
[root@gary mnt]# ls
[root@gary mnt]# touch aminglinux.111
[root@gary mnt]# ls -l
總用量 0
-rw-r--r--. 1 xietao xietao 0 1月  16 14:19 aminglinux.111
[root@gary mnt]# id xietao
uid=1000(xietao) gid=1000(xietao) 組=1000(xietao)

服務端查詢創建文件是否同步:app

[root@gary-tao ~]# ls -l /home/nfstestdir/
總用量 0
-rw-r--r-- 1 mysql mysql 0 1月  16 14:19 aminglinux.111
[root@gary-tao ~]# id mysql
uid=1000(mysql) gid=1000(mysql) 組=1000(mysql)
說明:在客戶端創建文件時會發現文件用戶屬主與屬組是xietao,並且在服務端查詢文件時用戶倒是mysql,這是由於nfs限定了用戶,因此最終顯示成這樣。
相關文章
相關標籤/搜索