当前位置:网站首页>Rsync+inotyfy realize real-time synchronization of single data monitoring
Rsync+inotyfy realize real-time synchronization of single data monitoring
2022-07-29 05:55:00 【JACK-JIE】
One , environmental information
1, Usage environment
CentOS Linux release 7.5.1804 (Core)
Update source :192.168.21.131
Target source :192.168.21.132
2, Check Rsync Whether to install ( If not, directly yum Can be installed )
rpm -qa | grep rsync
2.1, I use rsync edition
rsync-3.1.2-6.el7_6.1.x86_64
2.2,rsync Common parameters of
-v –verbose Detailed mode output .
-a –archive Archiving mode , Indicates that files are transferred recursively , And keep all file attributes unchanged .
-l Keep soft links
-R Keep relative path
-H Keep hard links
-p,-o,-g,-A Reserve permissions separately , Belong to , Generic group ,acl etc. , But if you add -a, These include
-z, –compress Compress the backup files during transmission .
-D be equal to –devices --specials Express support b,c,s,p Files of type
–delete Delete those DST Exist in SRC Files not in .
–progress Show the progress during the transfer
Two , Configuration of the target server ,Rsync Server side (192.168.21.132)
3, Definition Rsync The configuration file
vim /etc/rsyncd.conf
uid = tongbu # Daemon user
gid = tongbu # Daemon Group
use chroot = no # Do not apply chroot
max connections = 100 # maximum connection ,0 For no limit
port = 873 # The default port is 873
timeout = 600 # Appoint IP Timeout for
pid file = /var/run/rsyncd.pid #Pid Storage location
lock file = /var/run/rsyncd.lock # Lock file storage location , The default is /var/run/rsync.lock
log file = /var/log/rsyncd.log # The location of the log file
Log format = %t %a %m %f %b # Custom log file fields
syslog facility = local3 # Define log levels , The default is daemon
# Module parameters
[web1] # Authentication module name , stay client End needs to be specified
path = /home # Directory to be mirrored
ignore errors # Ignore irrelevant IO error
comment = backup web # Comment information of the module
read only = no # Whether to allow customers to upload files
list = no # Column file not allowed
hosts allow = 192.168.21.0/255.255.255.0 # Allowed host network segments
auth users = tongbu # Authenticated user name , If there is no such line, it means anonymity , This user has nothing to do with the system
secrets file = /etc/tongbu.pwd # User and password comparison table
3.1, Be careful
Wrong content :rsync: failed to set times on “xxxx”: Operation not permitted
here uid And gid It needs to be consistent with the users and groups of the synchronized directory , Otherwise, an error will be reported
4, Create authentication file
echo “tongbu:Admin123” >> /etc/tongbu.pwd
5, Set permissions
chmod 600 /etc/{tongbu.pwd,rsyncd.conf}
6, establish motd file (rsync Welcome to , Fill in as you like )
echo “Welcome to use the rsync services!” >> /var/rsyncd.motd
7, start-up Rsync( Start with daemons )
/usr/bin/rsync –daemon
8, Join auto start
echo “/usr/bin/rsync --daemon” >> /etc/rc.local
3、 ... and , Update server configuration ,Rsync client (192.168.21.131)
1, install inotify-tools
1.1, Be careful
In the installation inotify-tools Please confirm your linux Whether the kernel hits 2.6.13, And it turns on at compile time CONFIG_INOTIFY Options , You can also use the following command to detect
1.2, command ( The following three appear MAX It's on )
ls /proc/sys/fs/inotify
max_queued_events max_user_instances max_user_watches
1.3, install inotify-tools
tar -zxf inotify-tools-3.14.gz
cd inotify-tools-3.14
./confifure
Make && make install
1.4, inotifywait Several parameters of
-m namely –monitor, Indicates that the event listening state is always maintained .
-r namely –recursive, Represents a recursive query directory .
-q namely –quiet, Indicates that the monitoring event is printed out .
-e namely –event, This parameter allows you to specify the event to be monitored , Common events are modify、delete、create、attrib etc.
–timefmt: The output format of the specified time
–format: Specify the details of the change file
2, Write real-time monitoring script
vim /root/rsync.sh
#!/bin/bash
UNISON=ps -ef |grep -v grep|grep -c inotifywait
if [ ${UNISON} -lt 1 ];then
HOST1=192.168.21.132
SRC=/home/tongbu
DES1=web1
USER1=tongbu
/usr/local/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f' -e modify,delete,create,attrib ${SRC} |
while read file
do
rsync -vzrtopg --delete --progress ${SRC} ${USER1}@${HOST1}::${DES1} --password-file=/etc/tongbu.pwd &&
echo "${file} was rsynced" >> /tmp/rsync.log 2>&1
echo "---------------------------------------------------------------------------"
done
fi
2.1, If you don't need real-time monitoring, you only need to do a scheduled task
30 1 * * * /usr/bin/rsync -vzrtopg --delete --progress /home/tongbu/ [email protected]::web1 --password-file=/etc/tongbu.pwd >/dev/null 2>&1 &
3, Create authentication file
echo “tongbu:Admin123” >> /etc/tongbu.pwd
4, Set permissions
chmod 600 /etc/tongbu.pwd
5, Check the startup
5.1, Syntax check
/usr/bin/bash -n /root/rsync.sh
5.2, Background start
chmod +x /root/rsync.sh
nohup /usr/bin/sh /root/rsync.sh &
6, You can use the command line to test before the script
rsync -vzrtopg --delete --progress /home/tongbu/ [email protected]::web1 --password-file=/etc/tongbu.pwd
When you don’t know what to do, just settle down and study!
边栏推荐
- Refresh, swagger UI theme changes
- Crypto巨头们ALL IN元宇宙,PlatoFarm或能突围
- Power BI Report Server 自定义身份验证
- “山东大学移动互联网开发技术教学网站建设”项目实训日志五
- 改哭了,终于解决了Cannot read properties of undefined (reading ‘parseComponent‘)
- C# 连接 SharepointOnline WebService
- SQL repair duplicate data
- Simple optimization of interesting apps for deep learning (suitable for novices)
- 【go】defer的使用
- 农村品牌建设给年轻人的一些机会
猜你喜欢

day02作业之进程管理

Power BI Report Server 自定义身份验证

Changed crying, and finally solved cannot read properties of undefined (reading 'parsecomponent')

与张小姐的春夏秋冬(2)

量化开发必掌握的30个知识点【什么是分笔逐笔数据】?

Idea using JDBC to connect mysql database personal detailed tutorial

Novice introduction: download from PHP environment to thinkphp6 framework by hand

识变!应变!求变!

Training log 7 of the project "construction of Shandong University mobile Internet development technology teaching website"

“山东大学移动互联网开发技术教学网站建设”项目实训日志三
随机推荐
Markdown语法
C# 判断用户是手机访问还是电脑访问
Fantom (FTM) prices will soar by 20% in the next few days
Machine learning makes character recognition easier: kotlin+mvvm+ Huawei ml Kit
华为2020校招笔试编程题 看这篇就够了(上)
Xsan is highly available - xdfs and San are integrated with new vitality
“山东大学移动互联网开发技术教学网站建设”项目实训日志一
Common prompt pop-up box of uniapp
一文读懂Move2Earn项目——MOVE
Get the number of daffodils
Reporting Services- Web Service
以‘智’提‘质|金融影像平台解决方案
Sports health is deeply rooted in the hearts of the people, and move protocol leads quality life
Idea using JDBC to connect mysql database personal detailed tutorial
数组的基础使用--遍历循环数组求出数组最大值,最小值以及最大值下标,最小值下标
Laravel swagger add access password
The bear market is slow, and bit.store provides stable stacking products to help you get through the bull and bear market
超简单集成HMS ML Kit 人脸检测实现可爱贴纸
Training log 6 of the project "construction of Shandong University mobile Internet development technology teaching website"
SSM integration