服务器信息:
*.*.110.72:rsync客户端+inotify(下文110.72代替)
*.*.41.66:rsync服务器端(下文41.66)
其中*.*.110.72向*.*.41.66中的两个目录进行同步,防火墙、selinux、NetworkManager均已关闭(已向网络工程师发出请求:开放873端口)
部署rsync:
41.66使用yum安装rsync、xinted
# yum -y install rsync xinetd
添加配置文件:
# vim /etc/rsyncd.conf
log file = /var/log/rsyncd.log 日志文件
pidfile = /var/run/rsyncd.pid pid文件
lock file = /var/run/rsync.lock lock文件
secrets file = /etc/rsync.pass 用户文件
motd file = /etc/rsyncd.Motd
[images]
path = /webapp/rhweb/public/images 文件被同步的路径
comment = Qzinfo 描述
uid = root 运行权限
gid = root 运行权限
port=873 端口号
use chroot = no 增加软连接的备份
read only = no 可写
list = no 不现实本地资源列表
max connections = 200 最大连接数
timeout = 600 超时时间
auth users = Qzinfo 允许的用户
hosts allow = 172.16.110.72 允许的IP
[qyqz]
path = /webapp/fpcy/fpcy/jsp/einv/common/images/qyqz
comment = qyqz
uid = root
gid = root
port=873
use chroot = no
read only = no
list = no
max connections = 200
timeout = 600
auth users = Qzinfo
hosts allow = 172.16.110.72
[test]
path = /test
comment = test
uid = root
gid = root
port=873
use chroot = no
read only = no
list = no
max connections = 200
timeout = 600
auth users = Qzinfo
hosts allow = 172.16.110.72
配置用户密码:
# vim /etc/rsync.pass
用户名:密码
为两个文件夹设置600的权限。
# chmod 600 /etc/rsync.pass
# chmod 600 /etc/rsyncd.conf
将rsync添加到xinetd
# vim /etc/xinetd.d/rsync
disable = yes
启动服务
# /etc/init.d/xinetd start
110.72部署客户端
yum安装rsync
# yum -y install rsync
新建密码文件:
# vim /etc/rsync.pass
密码
设置权限
# chmod 600 /etc/rsync.pass
测试:
rsync -vzrtopg --progress --password-file=/etc/rsync.pass /test Qzinfo@*.*.110.72::test
部署Inotify(110.72)
解压编译并安装
# tar -zxf inotify-tools-3.14.tar.gz
# ./config --prefix=/usr/local/inotify/ && make && make install
向sysctl.conf添加最大文件数并使其生效
# vim /etc/sysctl.conf
fs.inotify.max_queued_events=99999999
fs.inotify.max_user_watches=99999999
fs.inotify.max_user_instances=65535
# sysctl -p
编写监控脚本
# vim inotify_images.sh
#!/bin/bash
host=*.*.41.66 目标ip
src=/app/ZZSDZFP_PDF_BJ/WebRoot/WEB-INF/classes/file/qzimg/ 目标路径
des=images 模块名
user=Qzinfo 用户名
/usr/local/inotify/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f%e' -e modify,delete,create,attrib $src | while read files
do
/usr/bin/rsync -vzrtopg --progress --password-file=/etc/rsync.pass $src $user@$host::$des
echo "${files} was rsynced" >>/usr/local/inotify/rsync.log 2>&1
done
添加执行权限:
# chmod +x inotify_images.sh
后台运行
# nohup ./inotify_images.sh
编写另一个脚本:
vim inotify_qyqz.sh
#!/bin/bash
host=*.*.41.66 目标ip
src=/app/ZZSDZFP_PDF_BJ/WebRoot/WEB-INF/classes/file/qzimg/ 目标路径
des=qyqz 模块名
user=Qzinfo 用户名
/usr/local/inotify/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f%e' -e modify,delete,create,attrib $src | while read files
do
/usr/bin/rsync -vzrtopg --progress --password-file=/etc/rsync.pass $src $user@$host::$des
echo "${files} was rsynced" >>/usr/local/inotify/rsync.log 2>&1
done
添加权限:
# chmod +x inotify_qyqz.sh
后台运行
# nohup ./inotify_qyqz.sh