1.环境准备

主机 ⻆⾊ ip
web01 NFS客户端、RSYNC客户端 172.16.1.7
nfs NFS服务端、RSYNC客户端 172.16.1.31
backup NFS服务端、RSYNC服务端 172.16.1.41

2.搭建上传XX系统

1)安装httpd或nginx服务

 yum install -y httpd php

2)配置httpd⽤户

[root@web01 ~]# vim /etc/httpd/conf/httpd.conf
User www
Group www

3)创建⽤户

[root@web01 ~]# groupadd www -g 666
[root@web01 ~]# useradd www -u 666 -g 666 -s /sbin/nologin -M

4)上传代码

[root@web01 ~]# cd /var/www/html/ [root@web01 html]# rz kaoshi.zip [root@web01 html]# ll
total 28
-rw-r--r-- 1 root root 26995 Feb 13 22:23 kaoshi.zip [root@web01 html]# unzip kaoshi.zip
Archive: kaoshi.zip
inflating: info.php
inflating: bg.jpg
inflating: index.html
inflating: upload_file.php [root@web01 html]# ll
total 80
-rw-r--r-- 1 root root 38772 Apr 27 2018 bg.jpg
-rw-r--r-- 1 root root 2633 May 4 2018 index.html -rw-r--r-- 1 root root 52 May 10 2018 info.php
-rw-r--r-- 1 root root 26995 Feb 13 22:23 kaoshi.zip -rw-r--r-- 1 root root 1192 Jan 10 15:35 upload_file.php
[root@web01 html]#

5)授权

[root@web01 html]# chown -R www.www /var/www/html/

6)启动httpd

[root@web01 html]# systemctl start httpd [root@web01 html]# netstat -lntp | grep 80
tcp6 0 0 :::80 :::* LISTEN 23791/httpd

7)访问测试

3.将站点⽬录挂载到nfs服务器

服务端

1)安装nfs

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

2)配置nfs

[root@nfs ~]# vim /etc/exports
/data 172.16.1.0/24(rw,sync,all_squash,anonuid=666,anongid=666)

3)创建⽤户

[root@nfs ~]# groupadd www -g 666
[root@nfs ~]# useradd www -u 666 -g 666 -s /sbin/nologin -M

4)创建⽬录并授权

[root@nfs ~]# mkdir /data
[root@nfs ~]# chown -R www.www /data/

5)启动NFS

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

6)验证NFS配置

[root@nfs ~]# cat /var/lib/nfs/etab
/data
172.16.1.0/24(rw,sync,wdelay,hide,nocrossmnt,secure,root_squash,all_squash,n o_subtree_check,secure_locks,acl,no_pnfs,anonuid=666,anongid=666,sec=sys,rw, secure,root_squash,all_squash)

客户端(web01)

7)安装rpcbind和nfs

root@web01 ~]# yum install -y nfs-utils rpcbind

8)查看挂载点

[root@web01 ~]# showmount -e 172.16.1.31 Export list for 172.16.1.31:
/data 172.16.1.0/24

9)挂载

root@web01 ~]# mount -t nfs 172.16.1.31:/data /var/www/html/upload [root@web01 ~]# df -h
Filesystem Size Used Avail Use% Mounted on /dev/sda3 18G 1.7G 17G 10% /
devtmpfs 476M 0 476M 0% /dev
tmpfs 487M 0 487M 0% /dev/shm
tmpfs 487M 7.7M 479M 2% /run
tmpfs 487M 0 487M 0% /sys/fs/cgroup /dev/sda1 1014M 127M 888M 13% /boot
tmpfs 98M 0 98M 0% /run/user/0
172.16.1.31:/data 18G 1.6G 17G 9% /var/www/html/upload

10)测试

4.把NFS挂载⽬录数据同步到backup服务器

rsync服务端(backup)

1)安装rsync

[root@backup ~]# yum install -y rsync

2)配置rsync

[root@backup ~]# vim /etc/rsyncd.conf uid = www
gid = www
port = 873
fake super = yes
use chroot = no
max connections = 200 timeout = 600
ignore errors
read only = false list = false
auth users = rsync_backup secrets file = /etc/rsync.passwd log file = /var/log/rsyncd.log ####################
[data]
path = /data

3)创建⽤户和⽤户组

[root@backup ~]# groupadd www -g 666
[root@backup ~]# useradd www -u 666 -g 666 -s /sbin/nologin -M

4)创建密码⽂件并授权

[root@backup ~]# echo "rsync_backup:123" > /etc/rsync.passwd
[root@backup ~]# chmod 600 /etc/rsync.passwd

5)创建⽬录并授权

[root@backup ~]# mkdir /data
[root@backup ~]# chown -R www.www /data

6)启动rsyncd服务

[root@backup ~]# systemctl start rsyncd

rsync客户端(NFS服务器)

7)将/data⽬录推送⾄backup服务器/data

#⽅式⼀:⼿动输⼊密码
[root@nfs data]# rsync -avz /data/ rsync_backup@172.16.1.41::data Password:
#⽅式⼆:配置环境变量
[root@nfs data]# export RSYNC_PASSWORD=123
[root@nfs data]# rsync -avz /data/ rsync_backup@172.16.1.41::data #⽅式三:指定密码⽂件
[root@nfs data]# echo "123" > /etc/rsync.password [root@nfs data]# chmod 600 /etc/rsync.password
[root@nfs data]# rsync -avz /data/ rsync_backup@172.16.1.41::data -- password-file=/etc/rsync.password

5.当NFS服务器出现问题,将web服务器挂载到backup服务器

backup服务器搭建NFS服务端

1)安装NFS

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

2)配置nfs

[root@backup ~]# vim /etc/exports
/data 172.16.1.0/24(rw,sync,all_squash,anonuid=666,anongid=666)

3)创建⽬录并授权

[root@backup ~]# mkdir /data
[root@backup ~]# chown -R www.www /data/

4)启动NFS

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

5)验证NFS

[root@backup ~]# cat /var/lib/nfs/etab /data
172.16.1.0/24(rw,sync,wdelay,hide,nocrossmnt,secure,root_squash,all_squash,n o_subtree_check,secure_locks,acl,no_pnfs,anonuid=666,anongid=666,sec=sys,rw, secure,root_squash,all_squash)

6.当nfs服务器出现问题,切换挂载

[root@web01 ~]# umount -lf /var/www/html
[root@web01 ~]# mount -t nfs 172.16.1.41:/data /var/www/html

7.实时同步inotify

1)安装inotify

[root@nfs data]# yum install -y inotify-tools

2)inotify参数

-m 持续监控

-r 递归

-q 静默,仅打印时间信息

--timefmt 指定输出时间格式

--format 指定事件输出格式

%Xe 事件

%w ⽬录

%f ⽂件

-e 指定监控的事件

access 访问

modify 内容修改

attrib 属性修改

close_write 修改真实⽂件内容

open 打开

create 创建

delete 删除

umount 卸载

3)测试命令

/usr/bin/inotifywait  -mrq  --format '%w %f' -e create,delete,attrib,close_write  /data

4)编写实时同步脚本

[root@nfs ~]# cat inotify.sh #!/bin/bash
dir=/data
export RSYNC_PASSWORD=123
/usr/bin/inotifywait -mrq --format '%w %f' -e
create,delete,attrib,close_write $dir | while read line;do
cd $dir && rsync -az -R --delete . rsync_backup@172.16.1.41::data >/dev/null 2>&1 done &
[root@nfs ~]# sh inotify.sh

5)上传⼀个⽂件,web端查看,nfs挂载⽬录查看,backup服务器备份⽬录查看

最新文章

  1. 让linux好用起来--操作使用技巧
  2. java函数
  3. SharePoint 2013 Excel Services ECMAScript 示例之明日限行
  4. 深入浅出SQL笔记1–数据和表
  5. JAVA04类与对象之课后问题解决
  6. 部署额外域控制器,Active Directory
  7. Effective Objective-C 2.0 — 第二章 对象、消息、运行期 - 第六条:理解“属性”这一概念
  8. svn cleanup failed–previous operation has not finished; run cleanup if it was interrupted
  9. python成长之路【第三篇】:函数
  10. 浅谈HTTP协议(上)
  11. Solr5.3.1 SolrJ查询索引结果
  12. Javascript基础--成员函数(六)
  13. 【设计模式】装饰者模式(Decorator)
  14. C# 保存和读取TreeView展开的状态
  15. jQuery入门第三
  16. (视频)《高速创建站点》 4.2 完结篇 – 应用运营vs.发射卫星,遥測(Telemetry) 技术
  17. php覆盖理解
  18. C++编程之面向对象的三个基本特征
  19. bzoj2339[HNOI2011]卡农 dp+容斥
  20. GitLab服务器IP地址设置

热门文章

  1. Netty Reactor模型
  2. SpringBoot 配置内部tomcat https双向验证
  3. re的finditer()
  4. java的集合以及数据结构
  5. 跨时钟域之异步FIFO
  6. TypeScript 对象
  7. Python3之并发(七)---线程同步队列(queue)
  8. JS篇(004)-js 是一门怎样的语言,它有什么特点?
  9. holiday04
  10. 用shape-outside实现文字环绕、CSS圆锥色彩渐变、指定背景在容器上如何附着、长度单位vh