rsync远程同步+inotify-tools自动检测笔记
来源:互联网 发布:房卡麻将源码教程 编辑:程序博客网 时间:2024/05/02 00:40
构建rsync远程同步
-------------同步源-----------------发起端-------------
192.168.1.1 192.168.1.10
1、配置IP地址并保证互通
2、确定备份源
[root@localhost ~]# mkdir /www
[root@localhost ~]# touch /www/{1..100}.html
3、创建备份账号
[root@localhost ~]# vim /etc/rsyncd_users.db
[root@localhost ~]# chmod 600 /etc/rsyncd_users.db //必须设置为600,否则客户端认证失败。
添加:
hehe:123.com
4、创建rsync配置文件
[root@localhost ~]# vim /etc/rsyncd.conf //系统中无此文件,需手动创建。
添加:
uid = nobody
gid = nobody
use chroot = yes
address = 192.168.1.1
port 873
log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid
hosts allow = 192.168.1.0/24
[www]
path = /www
第13章:rsync远程同步.txt[2015/8/5 16:31:06]
comment = hehe
read only = yes
dont compress = *.gz *.bz2 *.tgz *.zip *.rar *.z
auth users = hehe
secrets file = /etc/rsyncd_users.db
5、启动(终止)rsync
[root@localhost ~]# rsync --daemon
[root@localhost ~]# netstat -anpt | grep rsync
[root@localhost ~]# rsync --daemon
[root@localhost ~]# netstat -anpt | grep rsync
[root@localhost ~]# kill -9 PID号(例如:kill -9 9290)
注意:如果重新启动失败时,先删除pid文件,然后再启动。
[root@localhost ~]# rm -rf /var/run/rsyncd.pid
6、验证:
1)本地验证:(类似复制)
[root@localhost ~]# rsync -rl /etc/httpd/ /tmp/
2)发起端验证:( 把同步源的重要文件同步到发起端,作为备份)
[root@localhost ~]#mkdir /www
[root@localhost ~]#rsync -avz hehe@192.168.1.1::www /www/
或者
[root@localhost ~]#rsync -avz rsync://hehe@192.168.1.1/www /www/
增量:
[root@localhost ~]#rsync -avz --delete hehe@192.168.1.1::www /www/
注:之前学习的内容为下行同步(类似于下载)
第13章:rsync远程同步.txt[2015/8/5 16:31:06]
上行同步:(类似于上传)
[root@localhost ~]# rsync -avz --delete /www hehe@192.168.1.1::www
注意:
1、同步源中的权限:要把 read only 改写成 no;
2、同步源中/www/的权限改为757
7、设置计划任务自动远程同步
在发起端作如下操作:
[root@localhost ~]# vim /etc/hehe.password
[root@localhost ~]# chmod 600 /etc/hehe.password
[root@localhost ~]# crontab -e root
添加:
30 22 * * * /usr/bin/rsync -az --delete --password-file=/etc/hehe.password
hehe@192.168.1.1::www /www/
[root@localhost ~]# service crond restart
[root@localhost ~]# chkconfig crond on
配置rsync+inotify实时同步
1、调整内核参数
[root@localhost ~]#cat /proc/sys/fs/inotify/max_queued_events
[root@localhost ~]#cat /proc/sys/fs/inotify/max_user_instances
[root@localhost ~]#cat /proc/sys/fs/inotify/max_user_watches
[root@localhost ~]#vim /etc/sysctl.conf
第13章:rsync远程同步.txt[2015/8/5 16:31:06]
添加:
fs.inotify.max_queued_events = 16384
fs.inotify.max_user_instances = 1024
fs.inotify.max_user_watches = 1048576
[root@localhost ~]#sysctl -p
2、安装inotify软件
[root@localhost ~]#tar -zxvf inotify-tools-3.14.tar.gz -C /usr/src/
[root@localhost ~]#/usr/src/inotify-tools-3.14/
[root@localhost inotify-tools-3.14]#./configure && make && make install
3、验证监控效果
[root@localhost ~]#inotifywait -mrq -e modify,create,move,delete /var/www/html
在另一个终端上进行增删改查的操作。
4、编写触发式同步脚本
[root@localhost ~]# vim inotify_rsync.sh
添加:
#!/bin/bash
INOTIFY_CMD="inotifywait -mrq -e modify,create,attrib,move,delete /var/www/html/"
RSYNC_CMD="rsync -azH --delete --password-file=/etc/hehe.password /var/www/html/
hehe@192.168.1.1:/var/www/html"
$INOTIFY_CMD | while read DIRECTORY EVENT FILE
do
if [ $(pgrep rsync | wc -l) -le 0 ] ; then
$RSYNC_CMD
fi
done
-------------同步源-----------------发起端-------------
192.168.1.1 192.168.1.10
1、配置IP地址并保证互通
2、确定备份源
[root@localhost ~]# mkdir /www
[root@localhost ~]# touch /www/{1..100}.html
3、创建备份账号
[root@localhost ~]# vim /etc/rsyncd_users.db
[root@localhost ~]# chmod 600 /etc/rsyncd_users.db //必须设置为600,否则客户端认证失败。
添加:
hehe:123.com
4、创建rsync配置文件
[root@localhost ~]# vim /etc/rsyncd.conf //系统中无此文件,需手动创建。
添加:
uid = nobody
gid = nobody
use chroot = yes
address = 192.168.1.1
port 873
log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid
hosts allow = 192.168.1.0/24
[www]
path = /www
第13章:rsync远程同步.txt[2015/8/5 16:31:06]
comment = hehe
read only = yes
dont compress = *.gz *.bz2 *.tgz *.zip *.rar *.z
auth users = hehe
secrets file = /etc/rsyncd_users.db
5、启动(终止)rsync
[root@localhost ~]# rsync --daemon
[root@localhost ~]# netstat -anpt | grep rsync
[root@localhost ~]# rsync --daemon
[root@localhost ~]# netstat -anpt | grep rsync
[root@localhost ~]# kill -9 PID号(例如:kill -9 9290)
注意:如果重新启动失败时,先删除pid文件,然后再启动。
[root@localhost ~]# rm -rf /var/run/rsyncd.pid
6、验证:
1)本地验证:(类似复制)
[root@localhost ~]# rsync -rl /etc/httpd/ /tmp/
2)发起端验证:( 把同步源的重要文件同步到发起端,作为备份)
[root@localhost ~]#mkdir /www
[root@localhost ~]#rsync -avz hehe@192.168.1.1::www /www/
或者
[root@localhost ~]#rsync -avz rsync://hehe@192.168.1.1/www /www/
增量:
[root@localhost ~]#rsync -avz --delete hehe@192.168.1.1::www /www/
注:之前学习的内容为下行同步(类似于下载)
第13章:rsync远程同步.txt[2015/8/5 16:31:06]
上行同步:(类似于上传)
[root@localhost ~]# rsync -avz --delete /www hehe@192.168.1.1::www
注意:
1、同步源中的权限:要把 read only 改写成 no;
2、同步源中/www/的权限改为757
7、设置计划任务自动远程同步
在发起端作如下操作:
[root@localhost ~]# vim /etc/hehe.password
[root@localhost ~]# chmod 600 /etc/hehe.password
[root@localhost ~]# crontab -e root
添加:
30 22 * * * /usr/bin/rsync -az --delete --password-file=/etc/hehe.password
hehe@192.168.1.1::www /www/
[root@localhost ~]# service crond restart
[root@localhost ~]# chkconfig crond on
配置rsync+inotify实时同步
1、调整内核参数
[root@localhost ~]#cat /proc/sys/fs/inotify/max_queued_events
[root@localhost ~]#cat /proc/sys/fs/inotify/max_user_instances
[root@localhost ~]#cat /proc/sys/fs/inotify/max_user_watches
[root@localhost ~]#vim /etc/sysctl.conf
第13章:rsync远程同步.txt[2015/8/5 16:31:06]
添加:
fs.inotify.max_queued_events = 16384
fs.inotify.max_user_instances = 1024
fs.inotify.max_user_watches = 1048576
[root@localhost ~]#sysctl -p
2、安装inotify软件
[root@localhost ~]#tar -zxvf inotify-tools-3.14.tar.gz -C /usr/src/
[root@localhost ~]#/usr/src/inotify-tools-3.14/
[root@localhost inotify-tools-3.14]#./configure && make && make install
3、验证监控效果
[root@localhost ~]#inotifywait -mrq -e modify,create,move,delete /var/www/html
在另一个终端上进行增删改查的操作。
4、编写触发式同步脚本
[root@localhost ~]# vim inotify_rsync.sh
添加:
#!/bin/bash
INOTIFY_CMD="inotifywait -mrq -e modify,create,attrib,move,delete /var/www/html/"
RSYNC_CMD="rsync -azH --delete --password-file=/etc/hehe.password /var/www/html/
hehe@192.168.1.1:/var/www/html"
$INOTIFY_CMD | while read DIRECTORY EVENT FILE
do
if [ $(pgrep rsync | wc -l) -le 0 ] ; then
$RSYNC_CMD
fi
done
0 0
- rsync远程同步+inotify-tools自动检测笔记
- rsync实时同步(搭配inotify-tools)
- rsync+inotify-tools实时同步模式
- rsync + sersync + inotify-tools实现数据同步
- Rsync+inotify实时同步笔记
- 通过rsync+inotify-tools+ssh实现触发式远程实时同步
- 通过rsync+inotify-tools+ssh实现触发式远程实时同步
- 通过rsync+inotify-tools+ssh实现触发式远程实时同步
- rsync + inotify-tools 实现web发布目录同步
- Linux下Rsync+Inotify-tools实现数据实时同步
- Linux下Rsync+Inotify-tools实现数据实时同步
- inotify-tools时实调用rsync同步文件
- Linux下Rsync+Inotify-tools实现数据实时同步
- Linux下Rsync+Inotify-tools实现数据实时同步
- Linux下Rsync+Inotify-tools实现数据实时同步
- 【实时文件同步】rsync+inotify-tools的安装与配置
- Linux下Rsync+Inotify-tools实现数据实时同步
- 使用rsync+inotify-tools+ssh实现文件实时同步
- 注释 Android Framework 中的一堆 debug 信息
- Qt 渐变色Gradient
- 【整理】Adam Taylor玩转Microzed系列——以太网通信部分
- An unhandled exception of type 'System.IO.FileNotFoundException' occurred in Unknown Module
- 微信自适应页面
- rsync远程同步+inotify-tools自动检测笔记
- php上传文件并存储到mysql数据库的方法
- Vue监听数据变化
- 终端环境运维菜单-yaml
- 最简单的鼠标悬停,实现下拉列表功能 bootstrap
- HDU1698 Just a Hook
- 云端卫士实战录 | OFTest 的安装和使用
- 写给开发者:记录日志的10个建议
- MySQL 游标遍历