NFS服務搭建與配置

2021-09-29 07:39:32 字數 4252 閱讀 2287

yum install nfs-utils -y

[root@tanyvlinux mnt]# netstat -lntp #安裝後偵聽了111埠;

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

[root@tanyvlinux mnt]# ps aux |grep rpc

root 6600 0.0 0.0 0 0 ? s< 10月17 0:00 [rpciod]

rpc 6693 0.0 0.1 69264 1156 ? ss 10月17 0:02 /sbin/rpcbind -w

root 75923 0.0 0.0 112728 988 pts/0 s+ 04:45 0:00 grep --color=auto rpc

[root@draft ~]# vi /etc/exports #服務端需要配置配置檔案;內容如下;

/home/nfs 192.168.87.0/24(rw,sync,no_root_squash,anonuid=1000,anongid=1000) #具體說明如下;

/home/nfs nfs服務的目錄,可以說是共享的目錄;

192.168.87.0/24 允許訪問的ip範圍;

rw 允許讀寫;ro可設為主讀;

sync 同步模式,記憶體資料實時寫入磁碟;async 非同步模式

no_root_squash 客戶端掛載nfs共享目錄後,root使用者不受約束,許可權很大;root_squash 與上面選項相對,客戶端上的root使用者收到約束,被限定成某個普通使用者;all_squash 客戶端上所有使用者在使用nfs共享目錄時都被限定為乙個普通使用者;

anonuid/anongid 和上面幾個選項搭配使用,定義被限定使用者的uid和gid;

[root@draft ~]# systemctl start nfs #服務端啟動nfs服務;

[root@draft nfs]# ps aux |grep rpc #啟動之後rpc多了程序;

rpc 4242 0.0 0.1 73652 1688 ? ss 12:07 0:00 /sbin/rpcbind -w

rpcuser 4243 0.0 0.1 48960 1936 ? ss 12:07 0:00 /usr/sbin/rpc.statd

root 4245 0.0 0.0 0 0 ? s< 12:07 0:00 [rpciod]

root 4251 0.0 0.3 50268 3040 ? ss 12:07 0:00 /usr/sbin/rpc.mountd

root 4295 0.0 0.0 45972 540 ? ss 12:07 0:00 /usr/sbin/rpc.idmapd

root 10652 0.0 0.0 112728 972 pts/0 r+ 14:04 0:00 grep --color=auto rpc

[root@draft ~]# mkdir -p /home/nfs #建立服務目錄;

[root@draft ~]# chmod 777 !$ #修改服務許可權;

[root@tanyvlinux ~]# showmount -e 192.168.87.133			#顯示掛載資訊;

export list for 192.168.87.133:

/home/nfs 192.168.87.0/24

[root@tanyvlinux ~]# mount -t nfs 192.168.87.133:/home/nfs /mnt #掛載;

[root@tanyvlinux ~]# df -h

檔案系統 容量 已用 可用 已用% 掛載點

devtmpfs 470m 0 470m 0% /dev

tmpfs 487m 0 487m 0% /dev/shm

tmpfs 487m 39m 448m 8% /run

tmpfs 487m 0 487m 0% /sys/fs/cgroup

/dev/sda1 197m 168m 30m 86% /boot

tmpfs 98m 0 98m 0% /run/user/0

192.168.87.133:/home/nfs 18g 4.8g 14g 27% /mnt

[root@tanyvlinux ~]# cd /mnt

[root@tanyvlinux mnt]# ls

[root@tanyvlinux mnt]# touch nfs.txt #可以在目錄裡建立檔案;

[root@tanyvlinux mnt]# ll

總用量 0

-rw-r--r-- 1 vsftpd vsftpd 0 11月 4 2019 nfs.txt #檔案建立的uid是1000;

[root@tanyvlinux mnt]# id vsftpd

uid=1000(vsftpd) gid=1000(vsftpd) 組=1000(vsftpd)

服務端

[root@draft nfs]# ll

總用量 0

-rw-r--r--. 1 mysql mysql 0 11月 4 12:17 nfs.txt #服務端顯示檔案建立uid也是1000;

[root@draft nfs]# id mysql

uid=1000(mysql) gid=1000(mysql) 組=1000(mysql)

[root@draft nfs]# vi /etc/exports		#修改如下配置,設定no_root_squash;

/home/nfs 192.168.87.0/24(rw,sync,no_root_squash,anonuid=1000,anongid=1000

[root@draft nfs]# exportfs -arv #使用exportfs命令得新載入;

exporting 192.168.87.0/24:/home/nfs

exportfs命令說明:

-a 全部掛載或者全部解除安裝

-r 重新掛載

-u 解除安裝某乙個目錄

-v 顯示共享目錄

客戶端再新建檔案

[root@tanyvlinux mnt]# touch nff		

[root@tanyvlinux mnt]# ll

總用量 0

-rw-r--r-- 1 root root 0 11月 4 2019 nff #設定後,檔案顯示由root建立;

服務端資訊

[root@draft nfs]# ll

總用量 0

-rw-r--r--. 1 root root 0 11月 4 12:28 nff

客戶端掛載時加上 -o nfsvers=3

mount -t nfs -oremount,nfsvers=3 192.168.87.133:/home/nfs /mnt
客戶端和服務端都需要 vim /etc/idmapd.conf #把「#domain = local.domain.edu」 改為 「domain = ***.com」 (這裡的***.com,隨意定義吧),然後再重啟rpcidmapd服務;

NFS服務搭建與配置

nfs服務搭建與配置 一 linux之間 nfs network file system 即網路檔案系統,是freebsd支援的檔案系統中的一種,它允許網路中的計算機之間共享資源。在nfs的應用中,本地nfs的客戶端應用可以透明地讀寫位於遠端nfs伺服器上的檔案,就像訪問本地檔案一樣。實驗需要兩台機...

NFS服務搭建與配置

nfs就是network file system的縮寫,它最大的功能就是可以通過網路,讓不同的機器 不同的作業系統可以共享彼此的檔案。nfs應用場合 在生產環境,我們很少使用單機部署應用,因為單機存在單點故障,一旦宕機,將無法為前端業務提供服務,這是客戶無法容忍的。現在提倡的高可用及7 24服務,是...

NFS 服務搭建與配置

a,b,c三颱機器上需要保證被訪問到的檔案是一樣的,a共享資料出來,b和c分別去掛載a共享的資料目錄,從而b和c訪問到的資料和a上的一致 安裝 yum install y nfs utils rpcbind 新增配置 vim etc exports 加入如下內容 home nfstestdir 19...