实时复制实践:
前提:backup rsync服务端部署好。
1)部署NFS客户端
[root@nfs01 ~]# echo 'export RSYNC_PASSWORD=oldboy' >>/etc/bashrc
[root@nfs01 ~]# source /etc/bashrc
[root@nfs01 ~]# echo $RSYNC_PASSWORD
oldboy
测试推送
[root@nfs01 ~]# rsync -avz /data rsync_backup@172.16.1.41::backup/
sending incremental file list
sent 164 bytes received 25 bytes 126.00 bytes/sec
total size is 0 speedup is 0.00
2)查看inotify支持情况
[root@nfs01 ~]# uname -r
3.10.0-957.5.1.el7.x86_64
[root@nfs01 ~]# ls -l /proc/sys/fs/inotify/
总用量 0
-rw-r--r-- 1 root root 0 4月 19 09:45 max_queued_events
-rw-r--r-- 1 root root 0 4月 19 09:45 max_user_instances
-rw-r--r-- 1 root root 0 4月 19 09:45 max_user_watches
3)安装inotify-tools
yum install epel-release -y
yum install inotify-tools -y
[root@nfs01 ~]# rpm -ql inotify-tools|head -2
/usr/bin/inotifywait
/usr/bin/inotifywatch
[root@nfs01 ~]# rpm -qa inotify-tools
inotify-tools-3.14-8.el7.x86_64
4)命令参数和事件知识
image.png image.png
5)测试实践
inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f' -e create /data
6)思考:实现数据复制
监控哪些事件?
增 改 删 需要监控
[root@nfs01 ~]# inotifywait -mrq --format '%w%f' -e close_write,delete /data
/data/a.txt
/data/a.txt
/data/a.txt
7)编写脚本
mkdir /server/scripts -p
rsync -az --delete /data/ rsync_backup@172.16.1.41::backup
[root@nfs01 /server/scripts]# /bin/sh /server/scripts/monitor1.sh &
[2] 9199
[root@nfs01 /server/scripts]# tail -2 /etc/rc.local
########################
/bin/sh /server/scripts/monitor1.sh &
ersync实践:
1)客户端推送成功
rsync -az /data rsync_backup@172.16.1.41::backup
2)部署sersync服务(NFS)
wget https://github.com/wsgzao/sersync/blob/master/sersync2.5.4_64bit_binary_stable_final.tar.gz
sersync_oldboy_64bit_20160928.tar.gz
[root@nfs01 /server/tools]# mkdir /application -p
[root@nfs01 /server/tools]# mv application/sersync /application/
[root@nfs01 /server/tools]# tree /application/
/application/
└── sersync
├── bin
│ └── sersync
├── conf
│ ├── confxml.xml
│ └── confxml.xml.ori
├── logs
│ └── rsync_fail_log.sh
└── readme.txt
4 directories, 5 files
[root@nfs01 /server/tools]# cd /application/sersync/
[root@nfs01 /application/sersync]# ls
bin conf logs readme.txt
[root@nfs01 /application/sersync]# cd conf/
[root@nfs01 /application/sersync/conf]# ls
confxml.xml confxml.xml.ori
3)sersync配置文件:干两件事:
1)完成监控配置:
inotifywait -mrq --format '%w%f' -e createFolder,close_write,delete,moveFrom,moveTo /data
2)完整命令拼接:
rsync -az /data --timeout=100 rsync_backup@172.16.1.41::backup
4)启动服务
[root@nfs01 /application/sersync/conf]# ../bin/sersync -h
set the system param
execute:echo 50000000 > /proc/sys/fs/inotify/max_user_watches
execute:echo 327679 > /proc/sys/fs/inotify/max_queued_events
parse the command param
_______________________________________________________
参数-d:启用守护进程模式
参数-r:在监控前,将监控目录与远程主机用rsync命令推送一遍
c参数-n: 指定开启守护线程的数量,默认为10个
参数-o:指定配置文件,默认使用confxml.xml文件
参数-m:单独启用其他模块,使用 -m refreshCDN 开启刷新CDN模块
参数-m:单独启用其他模块,使用 -m socket 开启socket模块
参数-m:单独启用其他模块,使用 -m http 开启http模块
不加-m参数,则默认执行同步程序
[root@nfs01 /application/sersync/conf]# /application/sersync/bin/sersync -d -n 10 -o /application/sersync/conf/confxml.xml
最终
/application/sersync/bin/sersync -d
pkill sersync
二进制程序,不是yum安装的,所以不能systemctl start sersync
配置:systemctl start sersync启动方案
https://blog.51cto.com/oldboy/2155931
[root@nfs01 /data]# tail -1 /etc/rc.local
/application/sersync/bin/sersync -d
配置:systemctl start sersync启动方案
https://blog.51cto.com/oldboy/2155931
[root@nfs01 /data]# cat /etc/rc.d/init.d/sersync
#!/bin/bash
# chkconfig: 2345 21 81
# description: rsync service start and stop scripts
# Author: oldboy
# Organization: www.oldboyedu.com
start(){
/application/sersync/bin/sersync -d -o /application/sersync/conf/confxml.xml &>/dev/null
}
stop(){
killall sersync 2>/dev/null
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
sleep 2
start
;;
*)
echo $"Usage:$0 {start|stop|restart}"
exit 1
esac
chmod +x /etc/rc.d/init.d/sersync
[root@nfs01 /data]# cat /usr/lib/systemd/system/sersync.service
[Unit]
Description=sersyncd service
After=network.target
[Service]
Type=forking
ExecStart=/etc/rc.d/init.d/sersync start
ExecReload=/etc/rc.d/init.d/sersync restart
ExecStop=/etc/rc.d/init.d/sersync stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target
chmod +x /usr/lib/systemd/system/sersync.service
[root@nfs01 /data]# systemctl enable sersync.service
Created symlink from /etc/systemd/system/multi-user.target.wants/sersync.service to /usr/lib/systemd/system/sersync.service.
[root@nfs01 /data]# systemctl status sersync.service
● sersync.service - sersyncd service
Loaded: loaded (/usr/lib/systemd/system/sersync.service; enabled; vendor preset: disabled)
Active: inactive (dead)
[root@nfs01 /data]# systemctl stop sersync
[root@nfs01 /data]# ps -ef|grep sersync|grep -v grep
[root@nfs01 /data]# systemctl start sersync
网友评论