Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the Linux file synchronization rsync like

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article will explain in detail how Linux file synchronization rsync is, the content of the article is of high quality, so Xiaobian shares it with you as a reference, I hope you have a certain understanding of related knowledge after reading this article.

rsync is a file synchronization and data transfer tool under Linux system. It adopts "rsync" algorithm, which can synchronize files between a client and a remote file server, or backup data from one partition to another on the local system.

rsync Implementation Server File Synchronization Environment Deployment:

Server 1: 192.168.1.169 as client

Server 2: 192.168.1.167 as server

Function: Whenever the file in the 169 server changes, it is synchronized to the 167 server.

Server configuration (i.e. configuration of 167 server):

(1) Software installation yum install rsync xinetd

(2) Edit the configuration file for rsyncd service. By default, there is none. You need to edit vim /etc/rsyncd.conf and write the following contents: uid = root gid = root use chroot = no max connections = 5 timeout = 600 pid file = /var/run/rsyncd.pid lockfile = /var/run/rsyncd.lock log file = /var/log/rsyncd.log [web1] path = /usr/local/nginx/html/hello/ ignore errors = yes read only = no write only = no hosts allow = 192.168.1.169 hosts deny = * list = yes auth users = web secrets file = /etc/web.passwd

(3) Create a directory for file synchronization, the path in the configuration above, if there is no need to create mkdir /usr/local/nginx/html/hello/

(4) Create a password file in the configuration and add permissions: echo "web:123" > /etc/web.passwd chmod 600 /etc/web.passwd

5) Restart service xinetd

Client configuration (i.e. configuration of 169 server):

yum -y install rsync

(2) Create web directory mkdir /usr/local/nginx/html/hello/

(3) Set password and set permissions echo "123"> /tmp/rsync.password chmod 600 /tmp/rsync.password

(4) Close firewall: service iptables stop.

Test on client side (i.e. 169 server): rsync -avzP-delete-password-file=/tmp/rsync.password /usr/local/nginx/html/hello/web@192.168.1.167:: web1

If you see the file syncing past, it means success.

Real-time data synchronization:

Environment: Rsync + Inotify-tools.

download and install

wget https://jaist.dl.sourceforge.net/project/inotify-tools/inotify-tools/3.13/inotify-tools-3.13.tar.gz tar -zxvf inotify-tools-3.13.tar.gz mkdir /usr/local/inotify cd inotify-tools-3.13 ./ configure –prefix=/usr/local/inotify/ make && make install

set the environment variable

vim /etc/profile

Add the following line at the end:

export PATH=$PATH:/usr/local/inotify/bin

To validate a configuration:

source /etc/profile

echo ‘/usr/local/inotify/lib’ >> /etc/ld.so.conf –

Load the library file ldconfig ln -s /usr/local/inotify/include /usr/include/inotify

Test script:

Create a shell file: vim /test.sh Enter the following:

#!/ bin/bash src=/usr/local/nginx/html/hello/ user=web host1=192.168.1.167 dst1=web1 passpath=/tmp/rsync.password /usr/local/inotify/bin/inotifywait \ -mrq --timefmt '%d/%m/%y' \ --format '%T %w%f%e' \ -e modify,delete,create,attrib \ /usr/local/nginx/html/hello/ | while read files do rsync -vzrtopg --delete --progress --passfile=$passfile-path $src $user@$host1::$dst1 echo "${files} was rsyncd" >>/tmp/rsync.log 2>&1 done Set autorun:

chmod test.sh & echo '/data/test/test.sh &'>> /etc/rc.local-Set boot autostart

Extended knowledge:

View installed packages yum list rsync Uninstalling rsync yum remove rsync

Common Mistakes:

Question 1:

rsync: failed to set times on "directory" Operation not permitted (1)

Solution:

Check that the/etc/rsyncd.conf configuration file is correct.

Question 2:

@ERROR: auth failed on module web

rsync error: error starting client-server protocol (code 5) at main.c(1657) [Receiver=3.1.3]

Reason:

The server module (web) needs to verify the username and password, but the client does not provide the correct username and password, and the authentication fails.

Provide the correct username and password to resolve this issue.

Question 3:

inotifywait: error while loading shared libraries: libinotifytools.so.0: cannot open shared object

[root@db zzh]# ll /proc/sys/fs/inotify (inotifytools are supported if the following three are present)

total 0

-rw-r–r– 1 root root 0 Sep 20 16:52 max_queued_events

-rw-r–r– 1 root root 0 Sep 20 16:52 max_user_instances

-rw-r–r– 1 root root 0 Sep 20 16:52 max_user_watches

Solution:

[root@db zzh]# ln -s /usr/local/lib/libinotifytools.so.0 /usr/lib64/libinotifytools.so.0

Question 4:

Wile read command not found

Solution:

Check out sh files, or rewrite them.

rsync configuration file description:

uid = root #-rsync runs as root

gid = root #-rsync runs as root

use chroot = no #-whether to let the process leave the working directory

max connections = 5 #-Maximum number of concurrent connections, 0 is unlimited

timeout = 600 #-timeout

pid file = /var/run/rsyncd.pid #-Specify the path where rsync's pid is stored

lockfile = /var/run/rsyncd.lock #-Specify the lock file storage path for rsync

log file = /var/log/rsyncd.log #-Specify the path where rsync logs are stored

[web1] #-Module name

path = /data/test/src #-The base path where the module stores files

ignore errors = yes #-Ignore unrelated I/O errors

read only = no #-clients can upload

write only = no #-clients can download

hosts allow = 192.168.8.167 #-Client hosts ip allowed to connect

hosts deny = * #-Blacklist, * indicates any host

list = yes

auth users = web #â € "The username that authenticates this module

secrets file = /etc/web.passwd #-Specifies a file that holds the format "username: password"

About Linux file synchronization rsync is how to share here, I hope the above content can be of some help to everyone, you can learn more knowledge. If you think the article is good, you can share it so that more people can see it.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report