NFS服務
原理:供檔案共享服務,為Web Server 配置集群中的后端存盤, 支持多節點同時掛載以及并發送與寫入,
架構決議

這是一張大型網站高并發架構圖,我們只需注意圖中圈紅的地方
建立NFS檔案系統本質就是用來進行存盤,一般資料是不會放本地
比如一些MySQL資料庫/var/lib/mysql ,nginx網站目錄 /usr/share/nginx/html/..........還有很多
這些都可以結合NFS網路檔案系統進行掛載與遠程存盤
主要是增加資料的可靠性與安全性,方便與資料災備方案與備份.........
? 一、環境準備

CentOS版本: CentOS Linux release 7.9.2009 (Core)
埠:111
1、關閉firewalld、selinux
2、準備兩臺機器:
nfs-servce:192.168.178.135
nfs-cilent:192.168.178.139
nfs-server/nfs-client
#兩臺主機同時進行
?
#1. 關閉防火墻:
[root@192 ~]# systemctl stop firewalld
[root@192 ~]# systemctl disable firewalld
?
#2. 關閉Selinux:
[root@192 ~]# sed -i '/^SELINUX=/c SELINUX=disabled' /etc/selinux/config #永久關閉
?
#3. 因為永久關閉要重啟,先進行臨時關閉
[root@192 ~]# setenforce 0
?
#4. 查看是否成功關閉Selinux:
[root@192 ~]# getenforce
Permissive #出現此,代表臨時關閉Selinux成功
二、安裝軟體與配置
nfs-server
#1. 進行域名決議:
[root@nfs-server ~]# vim /etc/hosts
192.168.178.135 nfs-server #Server IP
192.168.178.139 nfs-client #Client IP
?
#2. 獲取阿里云源:
[root@nfs-server ~]# yum -y install wget && wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
?
#3. 安裝相關軟體:
[root@nfs-server ~]# yum -y install nfs-utils
?
#4. 創建網站檔案存放目錄:
[root@nfs-server ~]# mkdir /webdata
[root@nfs-server ~]# chmod 777 /webdata/
[root@nfs-server ~]# echo "nfs-test 2021-09-23 Sunny" > /webdata/index.html
[root@nfs-server ~]# df /webdata/ -hT
檔案系統 型別 容量 已用 可用 已用% 掛載點
/dev/mapper/centos-root xfs 3.5G 1.5G 2.1G 42% /
?
#5. 撰寫NFS配置:
[root@nfs-server ~]# vim /etc/exports
#添加
/webdata 192.168.178.0/24(rw) #代表所有的178網段的主機擁有讀寫權限
?
#6. 開啟服務:
[root@nfs-server ~]# systemctl start nfs-server && systemctl enable nfs-server
Created symlink from /etc/systemd/system/multi-user.target.wants/nfs-server.service to /usr/lib/systemd/system/nfs-server.service.
?
#7. 檢查語法格式:
[root@nfs-server ~]# exportfs -v
/webdata 192.168.178.0/24(sync,wdelay,hide,no_subtree_check,sec=sys,rw,secure,root_squash,no_all_squash)
?
#8. 查看nfs-server是否啟動成功:
[root@nfs-server ~]# ss -anpt | grep 111
LISTEN 0 128 *:111 *:* users:(("rpcbind",pid=1709,fd=8))
LISTEN 0 128 [::]:111 [::]:* users:(("rpcbind",pid=1709,fd=11))
nfs-client
#1. 進行域名決議:
[root@nfs-client ~]# vim /etc/hosts
192.168.178.135 nfs-server
192.168.178.139 nfs-client
?
#2. 獲取阿里云源:
[root@nfs-client ~]# yum -y install wget && wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
?
#3. 安裝相對應的軟體:
[root@nfs-client ~]# yum -y install nfs-utils httpd
?
#4. 啟動網站服務:
[root@nfs-client ~]# systemctl start httpd && systemctl enable httpd
?
#5. 查看nfs-server上可用的掛載點:
[root@nfs-client ~]# showmount -e nfs-server
Export list for nfs-server:
/webdata 192.168.178.0/24
?
#6. 進行掛載到httpd的默認網站目錄:
[root@nfs-client ~]# mount -t nfs nfs-server:/webdata /var/www/html/
[root@nfs-client ~]# df -hT
檔案系統 型別 容量 已用 可用 已用% 掛載點
192.168.178.135:/webdata nfs4 3.5G 1.5G 2.1G 42% /var/www/html
?
#7. 獲取網站主頁:
[root@nfs-client ~]# curl nfs-client:80
nfs-test 2021-09-23 Sunny #遠程掛載共享檔案成功
🗡問題解決:客戶端不能寫入
在服務端:
# vim /etc/exports
/var/lib/mysql 192.168.178.0/24(rw,no_root_squash) #只需添加 no_root_squash
其他一些權限的代碼
- rw:可讀寫的權限;
- ro:只讀的權限;
- no_root_squash:登入到NFS主機的用戶如果是root,該用戶即擁有root權限;(不添加此選項ROOT只有RO權限)
- root_squash:登入NFS主機的用戶如果是root,該用戶權限將被限定為匿名使用者nobody;
- all_squash:不管登陸NFS主機的用戶是何權限都會被重新設定為匿名使用者nobody,
- anonuid:將登入NFS主機的用戶都設定成指定的user id,此ID必須存在于/etc/passwd中,
- anongid:同anonuid,但是變成group ID就是了!
- sync:資料同步寫入存盤器中, async:資料會先暫時存放在記憶體中,不會直接寫入硬碟,
- insecure:允許從這臺機器過來的非授權訪問,
三、設定開機自動加載
#1. 在家目錄中加載:
[root@nfs-client ~]# cat ~/.bashrc
#加入
mount -t nfs nfs-server:/webdata /var/www/html/ #就是把之間掛載的命令寫進去,開機會加載該檔案
?
#2. 通過/etc/profile加載:
[root@nfs-client ~]# vim /etc/profile
#在最后一行加入即可:
mount -t nfs nfs-server:/webdata /var/www/html/
?
#3. 使用fstab自動掛載:
[root@nfs-client ~]# vim /etc/fstab
#加入 掛載的服務器上的路徑 要掛載到本機的路徑 型別
nfs-server:/webdata /var/www/html nfs defaults 0 0
決議:
- Defaults 同事具有rw,suid,dev,exec,auto,nouser,async等默認引數的設定
- 第1個1 表示備份檔案系統,
- 第2個1 表示從/磁區的順序開始fsck磁盤檢測,0表示不檢測,
- _rnetdev 表示主機無法掛載直接跳過,避免無法掛載主機無法啟動
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/302477.html
標籤:其他
上一篇:計算機網路之運輸層
下一篇:MQTT協議介紹
