實時復制實踐:
前提: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)命令參數和事件知識
略
5)測試實踐
inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f' -e create /data
6)思考:實現數據復制
監(jiān)控哪些事件孵滞?
增 改 刪 需要監(jiān)控
[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 &
sersync實踐:
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)完成監(jiān)控配置:
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:在監(jiān)控前诬滩,將監(jiān)控目錄與遠程主機用rsync命令推送一遍
c參數-n: 指定開啟守護線程的數量,默認為10個
參數-o:指定配置文件伦腐,默認使用confxml.xml文件
參數-m:單獨啟用其他模塊赢底,使用 -m refreshCDN 開啟刷新CDN模塊
參數-m:單獨啟用其他模塊,使用 -m socket 開啟socket模塊
參數-m:單獨啟用其他模塊柏蘑,使用 -m http 開啟http模塊
不加-m參數幸冻,則默認執(zhí)行同步程序
________________________________________________________________
[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