天天看點

Centos7.5離線搭建NFS檔案系統,附開啟NFS需要用到的防火牆端口

應用場景

tomcat叢集中,主備指定某個檔案夾,檔案共享

效果圖

Centos7.5離線搭建NFS檔案系統,附開啟NFS需要用到的防火牆端口

NFS伺服器:192.168.254.129

從伺服器:192.168.254.130

1、nfs服務需要的rpm包下載下傳位址:https://download.csdn.net/download/qq_35197601/10782606

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 測試!!!大功告成!!!

參考部落格:https://blog.csdn.net/u014635472/article/details/71375048,https://blog.csdn.net/w171066/article/details/52934862

繼續閱讀