How to Use Linux Rsync Command for Multi-Server Mirror Synchronization

How to Use Linux rsync Command for Multi-Server Mirror Synchronization

 
 
Functionality: When a user creates, modifies, or deletes directories or files, or changes file/directory attributes within a specific directory on the local client, simply executing the same shell script will trigger rsync to automatically identify the changed or deleted data and transfer it to the servers. This ensures that the data within a specific directory on the Linux server remains consistent with the data in the corresponding directory on the local client.


鈽匨ethod 1:
1. Server Side (e.g., 10.0.0.1*):
1. Create User and Group
  groupadd www -g 48
  useradd -u 48 -g www www
  mkdir -p /opt/htdocs
  chmod +w /opt/htdocs
  chown www:www /opt/htdocs
  2. Edit the rsync Configuration File
  vi /etc/rsyncd.conf
  Enter the following content:
  uid=www
  gid=www
  max connections=10
  use chroot=no
  log file=/var/log/rsyncd.log
  pid file=/var/run/rsyncd.pid
  lock file=/var/run/rsyncd.lock
  [zhangyan]
  path=/opt/htdocs
  comment = my htdocs
  ignore errors
  read only = no
  hosts allow=10.0.0.21 10.0.0.22
  3. Start the rsync Server Daemon
  /usr/bin/rsync –daemon
  2. Client Side (e.g., 10.0.0.21 and 10.0.0.22):
  1. Create a shell script push.sh
  vi push.sh
  Enter the following content (10.0.0.1* represents the target server to push to, and zhangyan is the module name defined in the server’s rsyncd.conf configuration file):
  Quote
  #!/bin/sh
  /usr/bin/rsync -vzrtopg –delete $1 10.0.0.10::zhangyan/
  /usr/bin/rsync -vzrtopg –delete $1 10.0.0.11::zhangyan/
  /usr/bin/rsync -vzrtopg –delete $1 10.0.0.16::zhangyan/
  /usr/bin/rsync -vzrtopg –delete $1 10.0.0.19::zhangyan/
  Note: Since the transfer occurs within an internal local area network, no password is configured here…

For details, please refer to the document:
https://

Leave a Comment

Your email address will not be published.