当前位置:网站首页>Rsync and inotify remote synchronization
Rsync and inotify remote synchronization
2022-04-22 08:19:00 【Old man, take you 1v5】
Catalog
(2) experiment : Remote Replication ( Downlink replication )
2、inotifywait( Command to continuously monitor and output monitoring results in real time )
One 、rsync
1、rsync Introduce
rsync It's an open source 、 fast 、 Multifunctional 、 It is an excellent tool to realize full and incremental local or remote data synchronous backup . And the attribute information of the original data can not be changed , Realize the backup and migration of data .
rsync The software is suitable for unix/linux/windows And so on
rsync It is a fast and very convenient file copying tool . It can reproduce locally , Remote Replication , Or remote daemon replication , It provides a large number of parameters to control all aspects of its behavior , It also allows very flexible ways to realize file transfer and replication
With its delta-transfer Algorithm famous .
rsync Listening port :873
rsync Operation mode :C/S
2、 Synchronization mode
Full volume backup :
All the original data is transmitted
Send the original document and the new document together
Copy in full , Low efficiency
Incremental backup
Before transmitting data, compare the data you have with the data I have through some algorithms , Transmit different data through the network ( Incremental replication , Efficient )
3、rsync command
| Constant option | explain |
| -r | Recursive mode , Contains all the files in the directory and subdirectories |
| -l | For symbolic link files, still copy as symbolic link files |
| -v | Show details of the synchronization process |
| -z | Compress when transferring files goD |
| -p | Keep the permission tag of the file |
| -a | Archiving mode , Recurse and keep object properties , Equate to -rlpt |
| -t | Keep the time stamp of the file |
| -g | Keep the group tag of the file ( For super users only ) |
| -o | Keep the owner tag of the file ( For super users only ) |
| -H | Keep hard link files |
| -A | Retain ACL Attribute information |
| -D | Keep equipment files and other special files |
| --delete | Delete files that exist in the target location but not in the original location |
| --checksum | Decide whether to skip files based on the checksums of objects |
4、rsync experiment
(1)rsync Local replication
Rsync 192.168.182.135
Client 192.168.182.160



(2) experiment : Remote Replication ( Downlink replication )
Rsync 192.168.182.135
Client 192.168.182.160
Basic environment configuration
systemctl stop firewalld.service
setenforce 0
# To configure rsync The source server
rpm -q rsync
yum -y install rsync

# establish /etc/rsyncd.conf The configuration file
vim /etc/rsyncd.conf # Add the following configuration
uid = nobody #root
gid = nobody #root
use chroot = yes # Locked in the source directory
address = 192.168.184.50 # Monitor address
port 873 # Listening port tcp/udp 873, It can be done by cat /etc/services | grep rsync see
log file = /var/log/rsyncd.log # Log file location
pid file = /var/run/rsyncd.pid # Store process ID File location of
hosts allow = 192.168.184.0/24 # The client address allowed to access
[wwwroot]
path = /var/www/html # The actual path to the source directory
comment = Document Root of www.ljm.com
read only = yes # Is it read-only
dont comperss = *.gz *.bz2 *.tgz *.zip *.rar *.z # File types that are no longer compressed during synchronization
auth users = backuper # Authorized account , Multiple accounts are separated by spaces
secrets file = /etc/rsyncd_users.db # Data file for storing account information
--------------------------------------------
uid = nobody
gid = nobody
use chroot = yes
address = 192.168.184.50
port 873
log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid
hosts allow = 192.168.184.0/24
[wwwroot]
path = /var/www/html
comment = Document Root of www.ljm.com
read only = yes
dont comperss = *.gz *.bz2 *.tgz *.zip *.rar *.z
auth users = backuper
secrets file = /etc/user.db
# Such as anonymity , Just put one of them “auth users” and “secrets file The configuration item can be removed

# Create data file for backup account
vim /etc/user.db
backuper:123456 # There is no need to establish a system user with the same name

chmod 600 /etc/user.db
# Ensure that all users have access to the source directory /var/www/html Have read permission
mkdir -p /var/www/html
chmod +r /var/www/html/
ls -ld /var/www/html/

# start-up rsync Service program
rsync --daemon
netstat -natp | grep rsync

close rsync service
kill $(cat /var/run/rsyncd.pid)
rm -rf /var/run/rsyncd.pid

Client synchronization

Secret free interaction

--delete
Two 、inotify
1、 brief introduction
You can monitor changes in the file system , And make notification response adjustment
inotify Kernel parameters ( Optimize )
/etc/sysctl.conf( Kernel parameter configuration file )
inotifywait: For continuous monitoring , Real time output results
inotifywatch: For short-term monitoring , Output the results after the task is completed
max_queue_events 3 Monitor event queue size
max_user_instances The maximum number of monitoring instances
max user watches The maximum number of monitoring files per instance
2、inotifywait( Command to continuously monitor and output monitoring results in real time )
Format : inotifywait[ Parameters ]
| Common parameters | explain |
| -m | Continuous monitoring |
| -r | Recursively monitor all child objects |
| -q |
Simplify the output |
| -e | Specify which event types to monitor |
3、 experiment
Server side : modify rsync The configuration file
vim /etc/rsyncd.conf
uid = root
gid = root
read only = no # Turn off read-only , Uplink synchronization requires writable permissions

kill `cat /var/run/rsyncd.pid`
netstat -natp | grep rsync
rsync --daemon
netstat -natp | grep rsync
client :inotify Kernel parameters
cat /proc/sys/fs/inotify/max_queued_events
cat /proc/sys/fs/inotify/max_user_instances
cat /proc/sys/fs/inotify/max_user_watches

vim /etc/sysctl.conf
fs.inotify.max_queued_events = 32768 # Monitor the time queue , The default is 16384
fs.inotify.max_user_instances = 1024 # The maximum number of monitoring instances , The default is 128
fs.inotify.max_user_watches = 1048576 # The maximum number of monitoring files per instance , The default is 8192
# When you want to monitor the directory 、 When the amount of file data is large or changes frequently , It is recommended to increase the parameter value

sysctl -p
# Client installation inotify-tools
yum -y install gcc gcc-c++

tar zxvf inotify-tools-3.14.tar.gz -C /opt
cd /opt/inotify-tools-3.14/
./configure

make && make install
# perform “inotifywait” command , Then on the server side, go to /var/www/html Add files to directory 、 Moving files , Tracking screen output
inotifywait -mrq -e modify,create,move,delete /abc
# The server writes the trigger synchronization script
vim /opt/inotify.sh
#!/bin/bash
INOTIFY_CMD="inotifywait -mrq -e create,delete,move,modify,attrib /abc/"
RSYNC_CMD="rsync -apzH --delete --password-file=/etc/server.pass /abc/ [email protected]::wwwroot/"
$INOTIFY_CMD | while read DIRECTORY EVENT FILE
do
if [ $(pgrep rsync | wc -l) -le 0 ] ; then
$RSYNC_CMD
fi
Done

chmod +x /opt/inotify.sh
chmod +x /etc/rc.d/rc.local
echo "/opt/inotify.sh" >> /etc/rc.d/rc.local
verification :
192.168.182.160 client stay /var/www/html Add operation Open the copied 160 The client performs operation command monitoring


Client script It will be executed If inotify Trigger rsync process The script will be triggered to automatically synchronize
here 192.168.182.135 Server side Same directory Automatic backup
版权声明
本文为[Old man, take you 1v5]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220706393571.html
边栏推荐
- 酞菁铂cas:14075-08-2|酞菁锌ZnPc|介孔硅@上转换@ZnPc光敏剂100nm以下发射650nm
- Fluorescently labeled hyaluronic acid
- 实验一、数据科学导论——数据科学认知
- Differences between routing modes
- 网络原理二(上)
- Dual channel optical network with 16 channels of E1 + 2m multi-channel optical transmission equipment
- MYSQL05_ORDR BY排序、LIMIT分组、GROUP BY分组
- [quick link] a necessary calculation tool for Electronic Engineers - square wave circuit aided design form
- 云计算学习1——OpenStack云计算安装部署步骤图文并茂(先电2.2)
- 【软件测试】零基础一文看懂软件测试基础知识
猜你喜欢

LabVIEW 2012中的收藏选板导入到LabVIEW 2013

16 way E1 optical transceiver + 4-way 100M Ethernet optical transceiver PDH optical transceiver 2m integrated service optical transceiver

Unity 透视投影矩阵变换的可视化

【软件测试】零基础一文看懂软件测试基础知识

Dual optical port 1 + 1 backup 8-way E1 + 2-way Gigabit isolation network 4-way 100m isolation PDH optical transceiver

4E1+2路千兆隔离网络+4路百兆物理隔离网络PDH光端机

ER 和 EER 模型

BLDC双闭环(速度PI+电流PI)simulink仿真模型

分布式系统服务熔断

深度确定性策略梯度(DDPG)
随机推荐
OpenFeign调用详细日志展示
软件测试面试题汇总
Wechat applet page routing
Blocking queue
计算机保研面试中,都有哪些令人窒息的问题?
通过OpenFeign传递对象类型参数
信息学奥赛一本通 1317:【例5.2】组合的输出
Android interview
Unity 透视投影矩阵变换的可视化
PDH optical transceiver optical fiber transmission 32-way E1 + 4-way 100m 100m network optical transceiver 2m multi service optical transceiver
MySQL 进阶 视图 -- 视图介绍、视图CRUD语法、检查选项(CASCADED、LOCAL)、视图的更新、视图作用、视图案例
REINFORCE
Hanyuan hi tech 8-way multi service PDH optical transceiver double optical port protection + 8-way E1 + 4-way Gigabit Ethernet + 4-way 100m network electric port
路由模式的区别
深度Q-网络(DQN)
SQL 基础(八)数据更新操作实战演练
Welcoming the era of stable currency 3.0, usdd brings financial innovation
Leprechaun绿精灵魔法来袭
Hanyuan hi tech PDH optical transceiver double optical port protection + 4-way E1 + 4-way Gigabit Network + 4-way 100m network optical transceiver
网络原理二(上)