1. 程式人生 > >Centos7.5離線搭建NFS檔案系統,附開啟對應防火牆埠

Centos7.5離線搭建NFS檔案系統,附開啟對應防火牆埠

NFS伺服器:192.168.254.129 從伺服器:192.168.254.130

1

2、安裝、編譯

[[email protected] soft]# rpm -Uvh *.rpm --nodeps --force
Updating / installing...
   1:glibc-2.17-222.el7               ################################# [  9%]
   2:libtirpc-0.2.4-0.10.el7          ################################# [ 18%]
   3:rpcbind-0.2.0-44.el7             ################################# [ 27%]
   4:keyutils-1.5.8-3.el7             ################################# [ 36%]
   5:libevent-2.0.21-4.el7            ################################# [ 45%]
   6:nfs-utils-1:1.3.0-0.54.el7       ################################# [ 55%]
   7:libgssglue-0.4-2.el7.nux         ################################# [ 64%]
   8:net-tools-2.0-0.22.20131004git.el################################# [ 73%]
   9:nfs-utils-lib-1.1.5-13.el6       ################################# [ 82%]
  10:libevent-2.0.21-4.el7            ################################# [ 91%]
  11:xinetd-2:2.3.14-29.el6           ################################# [100%]

3、新減/home/nfs資料夾,編輯exports檔案,新增從機   

[[email protected] soft]# vi /etc/exports

/home/nfs 192.168.254.130(rw,sync,all_squash,anonuid=0,anongid=0)

配置說明:     這一行分為三個部分:     第一部分:/home/nfs ,這個是本地要共享出去的目錄。     第二部分:192.168.254.130 ,允許訪問的主機,     第三部分:括號中部分。     rw表示可讀寫,ro只讀;     sync :同步模式,記憶體中資料時時寫入磁碟;async :不同步,把記憶體中資料定期寫入磁碟中;     no_root_squash :加上這個選項後,root使用者就會對共享的目錄擁有至高的許可權控制,就像是對本機的目錄操作一樣。不安全,不建議使用;root_squash:和上面的選項對應,root使用者對共享目錄的許可權不高,只有普通使用者的許可權,即限制了root;all_squash:不管使用NFS的使用者是誰,他的身份都會被限定成為一個指定的普通使用者身份;     anonuid/anongid :要和root_squash 以及all_squash一同使用,用於指定使用NFS的使用者限定後的uid和gid,前提是本機的/etc/passwd中存在這個uid和gid。     fsid=0表示將/home/nfs整個目錄包裝成根目錄

使配置及時生效

[[email protected] soft]# exportfs -rv

4、啟動A機上rpcbind,nfs服務  

[[email protected] soft]# systemctl enable rpcbind.service
[[email protected] soft]# systemctl enable nfs-server.service    
[[email protected] soft]# systemctl start rpcbind.service  
[[email protected] soft]# systemctl start nfs-server.service

5、檢視可掛載目錄及可連線的IP

[[email protected] soft]# showmount -e 192.168.254.129
Export list for 192.168.254.129:
/home/nfs 192.168.254.130

6、暫時先關閉防火牆,後面介紹nfs需要開放的埠

[[email protected] soft]# systemctl stop firewalld.service

7、切換到從機,安裝nfs,並啟動服務。

[[email protected] soft]# systemctl enable rpcbind.service
[[email protected] soft]# systemctl start rpcbind.service

8、檢查 NFS 伺服器端是否有目錄共享

[[email protected] soft]# showmount -e 192.168.254.129

9、使用mount掛載資料夾

[[email protected] soft]# mount -t nfs 192.168.254.129:/home/nfs/ /home/nfs/ 
[[email protected] ~]# df -h
Filesystem                 Size  Used Avail Use% Mounted on
/dev/mapper/centos-root     17G 1018M   16G   6% /
devtmpfs                   476M     0  476M   0% /dev
tmpfs                      488M     0  488M   0% /dev/shm
tmpfs                      488M  7.7M  480M   2% /run
tmpfs                      488M     0  488M   0% /sys/fs/cgroup
/dev/sda1                 1014M  130M  885M  13% /boot
tmpfs                       98M     0   98M   0% /run/user/0
192.168.254.129:/home/nfs   17G  1.1G   16G   6% /home/nfs

掛載完成,可以正常訪問本機下的/home/nfs,如果在129在共享目錄/home/nfs中寫入檔案,130上可以看到,但是不能在這個目錄中寫入檔案.

10、在客戶端實現掛載,編輯vi /etc/fstab,新增以下內容

192.168.254.129:/home/nfs                  /home/nfs    nfs    nolock   0 0

儲存後,重新掛載 

[[email protected] soft]# mount -a

11、上面配置必須關閉防火牆才可以,以下開啟防火牆,開放nfs服務需要的埠,執行以下命令,開啟埠

firewall-cmd --permanent --zone=public --add-port=111/tcp;
firewall-cmd --permanent --zone=public --add-port=111/udp;
firewall-cmd --permanent --zone=public --add-port=2049/tcp;
firewall-cmd --permanent --zone=public --add-port=2049/udp;
firewall-cmd --permanent --zone=public --add-port=1001/tcp;
firewall-cmd --permanent --zone=public --add-port=1001/udp;
firewall-cmd --permanent --zone=public --add-port=32803/tcp;
firewall-cmd --permanent --zone=public --add-port=32769/udp;
firewall-cmd --permanent --zone=public --add-port=892/tcp;
firewall-cmd --permanent --zone=public --add-port=892/udp;
firewall-cmd --reload

12、編輯/etc/sysconfig/nfs,新增以下內容

RQUOTAD_PORT=1001
LOCKD_TCPPORT=32803
LOCKD_UDPPORT=32769
MOUNTD_PORT=892

reboot 測試!!!大功告成!!!