NFS(网路文件系统)
任务要求:j将原有的WEB服务器上的静态文件分离出来,放到另外一台文件服务器上。并且对NFS服务器上保存的静态文件资源进行实时备份
具体措施:
环境准备:
WEB-server 192.168.11.16
NFS-server 192.168.11.17
backup-server 192.168.11.18
一、WEB-server服务搭建(192.168.11.16)
关闭防火情/清空防火情
方法一:service iptables stop
chkconfig --list|grep iptables
getenforce
setenforce 0
方法二:iptables -F
安装:
yum -y install httpd
netstat -nltp |grep 80
测试:
echo This is test page > /var/www/html/index.html
二、NFS-server搭建(192.168.11.17)
1.安装:
#yum -y install nfs-utils rpcbind
2.创建共享目录。并给其他人读写权限
#mkdir -p /share/data
chmod o+w /share/data/
3.编写NFS配置文件
#cat /etc/exports
/share/data 192.168.10.0/24(rw)
4.重启服务
#service rpcbind start
#service nfs start
三、挂载
web-server端挂载
#showmount -e 192.168.10.17(nfs端的ip)
#mount-t 192.168.10.17:/share/data /var/www/html/
#df -Th
四、实时备份nfs-server上的静态资源文件,以下内容在nfs-server完成
1)在nfs-server上安装inotify-tools工具
解压:
[root@nfs-server soft]# tar -xf inotify-tools-3.13.tar.gz
进入解压目录安装:
[root@nfs-server soft]# cd inotify-tools-3.13
[root@nfs-server inotify-tools-3.13]# ./configure
[root@nfs-server inotify-tools-3.13]# make
[root@nfs-server inotify-tools-3.13]# make install
2)编写脚本实时监控
[root@nfs-server ~]# cat 1.sh
#!/bin/bash
/usr/local/bin/inotifywait -mrq -e modify,delete,create,attrib,move /share/data |while read
events
do
rsync -a --delete /share/data/ 192.168.10.19:/backup
echo "`date +%F\ %T`出现事件$events" >> /var/log/rsync.log 2>&1
done
后台执行脚本:
./1.sh &
jobs #查看后台运行程序