知识点029-NFS和rsync和inotify实现文件的数据实时备份

本测试需要3台服务器,1,2,3

1.NFS客户端,RSYNC客户端

2.NFS服务端,RSYNC客户端,inotify软件

3.NFS客户端,RSYNC服务端

以下是各个服务器的安装脚本:

NFS客户端

#!/bin/bash
Path1=/data/a_w_lin 
Path2=/data/a_r_lin

### nfs rpcbind install ###
yum -y install nfs-utils rpcbind &&\
rpm -qa nfs-utils rpcbind

### mkdir dir ###
mkdir $Path1 -p
mkdir $Path2 -p

### check nfs ###
showmount -e 10.0.137.145

### mount ###
mount -t nfs  10.0.137.145:/data/w_shared  $Path1
mount -t nfs  10.0.137.145:/data/r_shared  $Path2

### rc.local ###
echo "mount -t nfs  10.0.137.145:/data/w_shared  $Path1" >>/etc/rc.local
echo "mount -t nfs  10.0.137.145:/data/r_shared  $Path2" >>/etc/rc.local

NFS服务端

#/bin/bash!
### nfs install ###
yum -y install nfs-utils rpcbind
rpm -qa nfs-utils rpcbind

### nfs start ###
/etc/init.d/rpcbind start &&\
/etc/init.d/nfs start
/usr/sbin/rpcinfo -p localhost

### mkdir dir ###
mkdir /data/w_shared -p
mkdir /data/r_shared -p
chown -R nfsnobody.nfsnobody /data/w_shared
chown -R nfsnobody.nfsnobody /data/r_shared

### nfs config ###
echo "/data/w_shared     10.0.137.0/24(rw,sync)" >>/etc/exports
echo "/data/r_shared     10.0.137.0/24(ro,sync)" >>/etc/exports

### nfs reload ###
/etc/init.d/nfs reload
showmount -e 127.0.0.1

### chkconfig ###
chkconfig rpcbind on
chkconfig nfs on

RSYNC服务端

#!/bin/bash
cat >>/etc/rsyncd.conf <<EOF
#rsync_config____________________start
#created bycarltonat 20180306
##rsyncd.conf start##
uid = rsync      					                         
gid = rsync							                       
use chroot £»= no					                       
max connections = 200  				                       
timeout = 300						                       
pid file = /var/run/rsyncd.pid		                       
lock file = /var/run/rsyncd.lock	                       
log file = /var/log/rsyncd.log		                       
[backup]							                       
path = /backup						                       
ignore errors						                       
read only = false					                       
list = false						                       
hosts allow = 10.0.137.0/24			                       
hosts deny = 0.0.0.0/24				                       
auth users = rsync_backup			                       
secrets file = /etc/rsync.password	                       
#rsync_config____________________start   
EOF
useradd rsync -s /sbin/nologin -M
rsync --daemon
mkdir /backup
chown rsync.rsync /backup
cat >> /etc/rsync.password  <<EOF
rsync_backup:carlton
EOF
chmod 600 /etc/rsync.password 
echo "/usr/bin/rsync --daemon" >>/etc/rc.d/rc.local

RSYNC客户端

#!/bin/bash
echo "carlton" >/etc/rsync.password
chmod 600 /etc/rsync.password

inotify安装及配置

#!/bin/bash
### instal inotify ###
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
yum -y install inotify-tools
rpm -qa inotify-tools

### optimize ###
echo 655350 >/proc/sys/fs/inotify/max_user_watches
echo 655350 >/proc/sys/fs/inotify/max_queued_events
#!/bin/bash
/usr/bin/inotifywait -mrq --format "%w%f" -e close_write,delete /data/w_shared \
|while   read file
do 
cd /data/w_shared
rsync -az  ./ rsync_backup@10.0.137.146::backup --password-file=/etc/rsync.password
done 

inotify加入到chkconfig --list 中

cat /etc/init.d/inotify
#!/bin/bash
#chkconfig: 2345 38 46
. /etc/init.d/functions
if [ $# -ne 1 ];then
 usage: $0 {start|stop}
 exit 1
fi
case "$1" in
start)
 /bin/bash /server/scripts/inotify.time.sh &
 echo $$ >/var/run/inotify.pid
 if [ `ps -ef|grep inotify|wc -l` -gt 2 ];then
 action "inotify service is started" /bin/true
 else
 action "inotify
service is started" /bin/false
 fi
 ;;
stop)
 kill -9 `cat /var/run/inotify.pid` >/dev/null 2>&1
 pkill inotifywait
 sleep 2
 if [ `ps -ef|grep inotify|grep -v grep|wc -l` -eq 0 ];then
 action "inotify service is stopped" /bin/true
 else
 action "inotify service is stopped" /bin/false
 fi
 ;;
*)
 usage: $0 {start|stop}
 exit 1
esac 

 

转载于:https://my.oschina.net/u/3635512/blog/1632845

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值