好程序員雲計算學習路線分享:關於NFS

好程序員雲計算學習路線分享:關於NFS

項目名稱爲集羣中的 Web Server 配置後端存儲

NFSNetwork File System 網絡文件系統,Unix系統之間共享文件的一種協議

NFS 的客戶端主要爲Linux

支持多節點同時掛載以及併發寫入

========================================================

nas 192.168.122.59

web1 192.168.122.85

web2 192.168.122.166

web3 192.168.122.111

nas web1 web2 web3

# sed -ri '/^SELINUX=/cSELINUX=disabled' /etc/selinux/config

# setenforce 0

centos6

# iptables -F

# service iptables save

centos7

# systemctl stop firewalld

# systemctl disable firewalld

# vim /etc/hosts [可選]

192.168.122.59 nas

192.168.122.85 web1

192.168.122.166 web2

192.168.122.111 web3

NFS

1.安裝軟件

yum -y install nfs-utils(主包提供文件系統)

yum -y install rpcbind(提供rpc協議)

2.啓動服務------>這兩個服務必須同時啓用

systemctl start nfs

systemctl start rpcbind

一、nas(存儲端)

[root@nas ~]# yum -y install nfs-utils

[root@nas ~]# mkdir /webdata //存儲網站代碼!

[root@nas ~]# echo "nfs test..." > /webdata/index.html

[root@nas ~]# vim /etc/exports

/webdata 192.168.122.0/24(rw,sync,no_root_squash) //不壓制root(client端使用root掛載時,也有root權限掛載是root ,同樣保持root權限

[root@nas ~]# systemctl start nfs-server

[root@nas ~]# systemctl enable nfs-server

[root@nas ~]# exportfs -v

/webdata 192.168.122.0/24(rw,wdelay,no_root_squash,no_subtree_check,sec=sys,rw,secure,no_root_squash,no_all_squash)

his

二、web1 web2 web3 客戶端

web1爲例:

[root@web1 ~]# yum -y install nfs-utils httpd

[root@web1 ~]# systemctl start httpd

[root@web1 ~]# systemctl enable httpd

httpd

1. 查看存儲端共享 [可選]

[root@web1 ~]# showmount -e nas

Export list for nas:

/webdata 192.168.122.0/24

ps -ef | grep nfs

2. 手動掛載 [可選]

[root@web1 ~]# mount -t nfs nas:/webdata /var/www/html/

[root@web1 ~]# umount /var/www/html/

3. 自動掛載到網站主目錄

[root@web1 ~]# vim /etc/fstab

nas:/webdata /var/www/html nfs defaults 0 0

[root@web1 ~]# mount -a

4. 查看掛載

[root@web1 ~]# df

nas:/webdata 7923136 692416 6821568 10% /var/www/html

[root@web1 ~]# ls /var/www/html/

index.html

5. web2 web3同上

三、測試網站訪問

# firefox 192.168.122.85

# firefox 192.168.122.111

# firefox 192.168.122.166


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章