linux系統搭建nfs共享儲存
阿新 • • 發佈:2020-07-13
1.web01和web02作為nfs的客戶端,共享一個目錄,會做的apache /var/www/html , 自己建立 /opt/nfs_ljp
\2. nfs客戶端建立一個共享目錄 /data_2020_05_08
3.當用戶上傳了圖片給web01的時候,(就是在web01的/opt/nfs_ljp/建立一個zhaopian)
上傳完之後,如果是apache,兩個網站都能訪問到,如果是手動建立的,自己去web02的共享目錄下,ll
4.把共享目錄中的重要資料做個備份,推送到backup伺服器的/backup目錄下。
1.1環境準備
使用者名稱 | 外網IP | 內網IP | 角色 |
---|---|---|---|
web01 | 10.0.0.7 | 172.16.1.7 | 客戶端 |
web02 | 10.0.0.8 | 172.16.1.8 | 客戶端 |
nfs | 10.0.0.31 | 172.16.1.31 | 服務端 |
## 首先關閉防火牆 systemctl stop firewalld ## 禁止開機自啟 systemctl disable firewalld ## sed替換修改配置配置檔案/etc/selinux/config sed -i '/^SELINUX=/c SELINUX=disabled' /etc/selinux/config # centos7服務端客戶端都要下載nfs-utils [root@nfs ~]# yum install -y nfs-utils # centos6則需要下載rpcbind 和nfs-utils # 然後下載httpd和php [root@nfs ~]# yum install -y httpd php
1.2 服務端配置
## 編輯nfs的配置檔案 # 編輯nfs的配置檔案 [root@nfs ~]# vim /etc/exports /data 172.16.1.0/24(rw,sync,all_squash,anonuid=666,anongid=666) # 建立配置檔案制定的目錄和使用者 [root@nfs ~]# mkdir /data [root@nfs ~]# useradd www -u 666 -g 666 -s /sbin/nologin -M #授權/data目錄所屬使用者和使用者組 [root@nfs ~]# chown www.www /data [root@nfs ~]# ll /data -d drwxr-xr-x 2 www www 6 May 8 19:48 /data # 啟動服務先啟動rpcbind 再啟動nfs-server [root@nfs ~]# systemctl start rpcbind nfs-server #新增服務的開機自啟 systemctl enable rpcbind nfs-server # 檢視有沒有房源 [root@nfs ~]# showmount -e Export list for nfs: /data * ##服務端OK
1.3客戶端配置
## 進入到httpd的站點目錄,如果不知道可以用rpm -ql httpd查一下
最後找到是在/var/www/html
## 進入這個目錄,把kaoshi.zip壓縮包上傳過去
[root@web02 ~]# cd /var/www/html
[root@web02 html]# rz
[root@web02 html]# ll
total 28
-rw-r--r-- 1 www www 26927 May 8 12:46 kaoshi.zip
# 解壓壓縮包
[root@web02 html]# unzip kaoshi.zip
Archive: kaoshi.zip
inflating: info.php
inflating: upload_file.php
inflating: bg.jpg
inflating: index.html
# 修改httpd的配置檔案和服務端保持一致
[root@web02 ~]# vim /etc/httpd/conf/httpd.conf
把user apache 和group apache 的apache 改為www 儲存退出
# 創建出和服務端一樣的使用者和使用者組
[root@web02 ~]# useradd www -u 666 -g 666 -s /sbin/nologin -M
## 授權html目錄許可權所屬使用者和使用者組為www
[root@web02 ~]# chown -R www.www /var/www/html
# 檢視服務端房源
[root@web02 ~]# showmount -e 10.0.0.31
Export list for 10.0.0.31:
/data *
# 把html裡面的壓縮包移走
[root@web02 html]# mv kaoshi.zip /root/
# 掛載目錄
[root@web02 ~]# mount -t nfs 10.0.0.31:/data /var/www/html/
#檢視客戶端/var/www/html目錄內容
[root@web02 html]# ll
total 0
-rw-r--r-- 1 root root 0 May 9 01:28 a.txt
#檢視服務端的/data目錄裡的內容
[root@nfs data]# ll
total 0
-rw-r--r-- 1 root root 0 May 9 01:28 a.txt
## 同理web01 和web02操作方式一樣