2018-05-09 Linux學習
阿新 • • 發佈:2018-05-10
Linux學習14.1 NFS介紹
/home/nfstestdir 192.168.133.0/24(rw,sync,all_squash,anonuid=1000,anongid=1000)
保存配置文件後,執行如下準備操作
mkdir /home/nfstestdir
chmod 777 /home/nfstestdir
systemctl start rpcbind
systemctl start nfs
systemctl enable rpcbind
systemctl enable 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上的一致
14.2 NFS服務端安裝配置
yum install -y nfs-utils rpcbind
vim /etc/exports //加入如下內容
保存配置文件後,執行如下準備操作
mkdir /home/nfstestdir
chmod 777 /home/nfstestdir
systemctl start rpcbind
systemctl start nfs
systemctl enable rpcbind
systemctl enable nfs
操作過程
[root@linux-01 ~]# yum install -y nfs-utils [root@linux-01 ~]# vim /etc/exports /home/nfstestdir 192.168.106.0/24(rw,sync,all_squash,anonuid=1000,anongid=1000) [root@linux-01 ~]# mkdir /home/nfstestdir [root@linux-01 ~]# chmod 777 /home/nfstestdir [root@linux-01 ~]# systemctl start rpcbind [root@linux-01 ~]# systemctl start nfs [root@linux-01 ~]# systemctl enable rpcbind [root@linux-01 ~]# systemctl enable nfs Created symlink from /etc/systemd/system/multi-user.target.wants/nfs-server.service to /usr/lib/systemd/system/nfs-server.service.
14.3 NFS配置選項
NFS配置選項
rw 讀寫
ro 只讀
sync 同步模式,內存數據實時寫入磁盤
async 非同步模式
no_root_squash 客戶端掛載NFS共享目錄後,root用戶不受約束,權限很大
root_squash 與上面選項相對,客戶端上的root用戶收到約束,被限定成某個普通用戶
all_squash 客戶端上所有用戶在使用NFS共享目錄時都被限定為一個普通用戶
anonuid/anongid 和上面幾個選項搭配使用,定義被限定用戶的uid和gid
客戶端掛載
yum install -y nfs-utils showmount -e 192.168.133.130 //該ip為NFS服務端ip mount -t nfs 192.168.133.130:/home/nfstestdir /mnt df -h touch /mnt/aminglinux.txt ls -l /mnt/aminglinux.txt //可以看到文件的屬主和屬組都為1000
操作過程
客戶機
[root@linux-02 ~]# showmount -e 192.168.106.160
clnt_create: RPC: Port mapper failure - Unable to receive: errno 113 (No route to host)
關閉服務器防火墻
[root@linux-01 ~]# systemctl stop firewalld.service
客戶機
[root@linux-02 ~]# showmount -e 192.168.106.160
Export list for 192.168.106.160:
/home/nfstestdir 192.168.106.0/24
[root@linux-02 ~]# mount -t nfs 192.168.106.160:/home/nfstestdir /mnt
[root@linux-02 ~]# df -h
文件系統 容量 已用 可用 已用% 掛載點
/dev/sda3 26G 4.7G 22G 18% /
devtmpfs 902M 0 902M 0% /dev
tmpfs 912M 0 912M 0% /dev/shm
tmpfs 912M 8.7M 903M 1% /run
tmpfs 912M 0 912M 0% /sys/fs/cgroup
/dev/sda1 197M 156M 42M 79% /boot
tmpfs 183M 0 183M 0% /run/user/0
192.168.106.160:/home/nfstestdir 26G 9.8G 17G 38% /mnt
[root@linux-02 ~]# touch /mnt/aminglinux.txt
[root@linux-02 ~]# ls -l /mnt/aminglinux.txt
-rw-r--r--. 1 1000 1000 0 4月 10 01:28 /mnt/aminglinux.txt
2018-05-09 Linux學習