Linux——配置NFS及autofs自動掛載服務


一、NFS服務配置步驟

NFS的作用:能夠使兩台虛擬機之間實現文件共享、數據同步

(一)准備:主機名、網絡、yum源

1、更改主機名:

[root@localhost ~]# hostnamectl set-hostname $主機名 [root@localhost ~]# bash #環境變量重載 

2、配置網絡

(1)虛擬交換機、網絡適配器選擇僅主機模式,並且配置為192.168.100.0網段;

(2)編輯網絡配置文件:

[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33 修改: BOOTPROTO=static #改為靜態IP地址 ONBOOT=yes #改為開機自啟 IPADDR=192.168.100.10 PREFIX=24 或者 NETMASK=255.255.255.0 

(3)重啟網絡服務:

[root@localhost ~]# systemctl restart network 

3、配置yum源

(1)先在VMware里面把系統鏡像文件連接到虛擬機的光驅上;

(2)掛載光驅里的鏡像:

[root@localhost ~]# mount /dev/cdrom /media 

(3)修改yum源配置文件:

[root@localhost ~]# vim /etc/yum.repos.d/local.repo [rhel] name=rhel baseurl=file:///media enabled=1 gpgcheck=0 

(4)清空yum源緩存信息:

[root@localhost ~]# yum clean all 

(5)檢索當前yum源信息:

[root@localhost ~]# yum repolist 

(二)配置NFS服務步驟

Server端:

1、安裝nfs-util和rpcbind:(圖形化自帶)

[root@server ~]# yum -y install nfs-util rpcbind 

2、新建共享目錄及標記文件:

[root@server ~]# mkdir /opt/share [root@server ~]# touch /opt/share/flag 

3、開放讀寫權限:

[root@server ~]# chmod -R 777 /opt/share 

4、修改配置文件:

[root@server ~]# vim /etc/exports 寫入:/opt/share 192.168.100.0/24(rw,sync) 

5、生效配置:

[root@server ~]# exportfs -r 

6、啟動並開機自啟NFS服務:

[root@server ~]# systemctl start rpcbind [root@server ~]# systemctl start nfs [root@server ~]# systemctl enable rpcbind [root@server ~]# systemctl enable nfs 

7、查看掛載目:

[root@server ~]# showmount -e 192.168.100.10 

8、查看端口是否開啟(111和2049):

[root@server ~]# netstat -pant 

Client端:

1、安裝nfs-util和rpcbind:(圖形化自帶)

[root@client ~]# yum -y install nfs-util rpcbind 

2、關閉SELinux服務:

[root@client ~]# setenforce 0 

3、掛載共享目錄:

[root@client ~]# mount -t nfs 192.168.100.10:/opt/share /mnt 

4、查看掛載情況:

[root@client ~]# df -h 

5、在/mnt里面創建文件驗證

[root@client ~]# cd /mnt [root@client mnt]# touch abc 

二、autofs自動掛載配置步驟

(一)准備:要在NSF的基礎上進行配置

如上操作

(二)配置autofs步驟

Server端:

檢查nfs是否開啟:

[root@server ~]# systemctl status nfs 

檢查端口號:

[root@server ~]# netstat -pant 

檢查防火牆:

[root@server ~]# systemctl status firewalld 

Client端:

先查看掛載目:

[root@client ~]# showmount -e 192.168.100.10 

1、安裝autofs:

[root@client ~]# yum -y install autofs 

2、配置/share:

[root@client ~]# vim /etc/auto.master.d/test.autofs 寫入:/share /etc/auto.test 

3、配置pub:

[root@client ~]# vim /etc/auto.test 寫入:pub 192.168.100.10:/opt/nfsshare 

4、重啟並開啟自啟:

[root@client ~]# systemctl restart autofs [root@client ~]# systemctl enable autofs 

5、訪問目錄:

[root@client ~]# cd /share/pub 

注意:第一個文件要以autofs結尾,第二個配置文件名要與第一個配置文件里定義的參數一致


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM