Linux cross server file synchronization

Angryshark_ one hundred and twenty-eight 2022-06-24 07:14:53 阅读数:129

linuxcrossserverfilesynchronization

The source server & Destination server

Whether to install rsync

# Most have been installed , See if it is installed
> rpm -qa |grep rsync

 Insert picture description here

The source server

Is installation supported inotify

> ll /proc/sys/fs/inotify

 Insert picture description here

install inotify

> tar -xf inotify-tools-3.14.tar
> ./configure
> make
> mae install

 Insert picture description here

Configure password file

# Password customization , But always communicate with the destination server
> echo "123456">/etc/rsyncd.secrets

Script synchronization

> vi stat2master.sh
#!/bin/sh
##################
# Synchronize files and directories in real time #
##################
# Destination server IP
host=*.*.*.*
# Source server directory
src=/data/grid/
# Configuration module name , Custom, but always with the destination server
des=stat
# Destination server user name
user=oidd
# Start monitoring and log format
/usr/local/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 -zrtopg --delete --progress --password-file=/etc/rsyncd.secrets $src [email protected]$host::$des
echo "${files} was rsynced" > /data02/grid/logs/rsyncd.log 2>&1
done

Destination server

Configure password file

> echo "oidd:123456" /etc/rsyncd.secrets

Configure startup files

> vi /etc/rsyncd.conf
uid = root
gid = root
use chroot = yes
# Native address
address = *.*.*.*
# Listening port
#port 873
log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid
# The client address allowed to access
hosts allow = *.*.*.*
# Module name
[stat]
# Project path
path = /sftp/stat
# Project description
comment = Web File
# read-only
read only = no
# Files that are no longer compressed during synchronization
dont compress = *.gz *.bz2 *.tgz *.zip *.rar *.z
# User authentication information
auth users = hh
# The path where the user authentication information is stored
secrets file = /etc/rsyncd.secrets

root User start

> /usr/bin/rsync --daemon --config=/etc/rsyncd.conf

/etc/rsyncd.conf Must be root:root Belong to

test

The source server

Start the synchronization script

> ./stat2master.sh

Create a new file in the synchronization Directory

> cd /data/grid/
> touch 1

Destination server

View remote directory

> ls
1
copyright:author[Angryshark_ one hundred and twenty-eight],Please bring the original link to reprint, thank you. https://en.javamana.com/2022/175/202206240050386262.html