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

Method of real-time synchronization of sersync data in Linux

2025-04-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

This article mainly introduces the method of real-time synchronization of sersync data in Linux, which has a certain reference value. Interested friends can refer to it. I hope you will gain a lot after reading this article.

Sersync actually uses inotify and rsync software technology to achieve real-time data synchronization. Inotify is used to monitor the changes of files on the server where sersync is located, combined with rsync software to synchronize data, and synchronize the data to the client server in real time.

Work process: open sersync on the synchronization master server, responsible for listening for changes in the file system, and then call the rsync command to synchronize the updated files to the target server, install sersync software on the master server, and install rsync service on the target server.

1. Client configuration

[root@localhost2 ~] # cat / etc/rsyncd.conf # created by cai at 2018-2-24uid=rsyncgid=rsyncuse chroot = nomax connections = 200timeout = 300pid file = / var/run/rsyncd.pidlock file = / var/run/rsync.locklog file = / var/log/ rsyncd.log [data] path = / data/ignore errorsread only = falselist = falsehosts allow = 192.168.181.128:52000/24hosts deny = 0.0.0.0/32auth users = rsync_bodysecrets file = / etc/rsync.password [root@localhost2 ~] # ls-ld / data/drwxrwxrwx. 3 rsync rsync 4096 Feb 24 16:58 / data/ [root@localhost2 ~] # cat / etc/rsync.password rsync_body: admin [root @ localhost2 ~] # ls-ld / etc/rsync.password-rw-. 1 root root 17 Feb 24 16:26 / etc/rsync.password # 600permission [root@localhost2 ~] # netstat-lntup | grep "rsync" tcp 00 0.0.0.0etc/rsync.password 873 0.0.0.0etc/rsync.password * LISTEN 1497/rsync tcp 00: 873:: * LISTEN 1497/rsync

2. Master server configuration

[root@localhost1 ~] # cat / etc/rsync.password admin [root@localhost1 ~] # ls-ld / etc/rsync.password-rw- 1 root root 6 Feb 24 03:54 / etc/rsync.password

3. Install the sersync service

Using inotify to monitor files, when monitoring files have changed, it will call rsync to achieve trigger real-time synchronization!

Install sersync (note that sersync works on the source server of rsync, that is, on the client)

[root@salt-client01 ~] # cd / usr/local/src/ [root@salt-client01 src] # tar-zxvf sersync2.5.4_64bit_binary_stable_final.tar.gz-C / usr/local/GNU-Linux-x86/GNU-Linux-x86/sersync2GNU-Linux-x86/confxml.xml [root@salt-client01 src] # cd / usr/local/ [root@salt-client01 local] # mv GNU-Linux-x86 sersync [root@salt-client01 local] # cd sersync/ [root@ Salt-client01sersync] # mkdir conf bin log [root@salt-client01sersync] # mv confxml.xml conf [root@salt-client01sersync] # mv sersync2 bin/sersync

Modify the configuration file

* * Line 30 starts * * #-the parameter when artuz is rsync synchronization * * * Line 36 * * * Note: if you have multiple directory backups, you can add multiple configuration files in the-o parameter at startup to [root@salt-client01 conf] # diff confxml.xml confxml.xml.bak24,25c24,25.

< #data就是本地需要同步的文件夹到服务器端的目录< #data (server的模块名)是rsync 服务端的文件夹,也就是推送到服务器端的目标文件夹,可以配置多个,--->

> 31c31

< #true 才能生效,rsync_body同步时候虚拟账号,后面是密码文件--->

33c33

< #true 才能生效--->

36c36

< #检测rsync进程判断,没有自动启--->

Start sersync

[root@salt-client01 src] # echo 'export PATH=$PATH:/usr/local/sersync/bin' > > / etc/profile # declare the environment variable [root@salt-client01 src] # source / etc/profile [root@salt-client01 src] # sersync2-r-d-o / usr/local/sersync/conf/confxml.xml # launch set the system paramexecute:echo 50000000 > / proc/sys/fs/inotify/max_user_watchesexecute:echo 327679 > / proc/sys/fs/inotify/max_queued_eventsparse The command paramoption:-r rsync all the local files to the remote servers before the sersync workoption:-d run as a daemonoption:-o config xml name: / usr/local/sersync/conf/confxml.xmldaemon thread num: 10parse xml config filehost ip: localhost host port: 8008daemon start Sersync run behind the consoleuse rsync password-file: user is rsync_bodypasswordfile is / etc/rsync.passwordconfig xml parse successplease set / etc/rsyncd.conf max connections=0 Manuallysersync working thread 12 = 1 (primary thread) + 1 (fail retry thread) + 10 (daemon sub threads) Max threads numbers is: 22 = 12 (Thread pool nums) + 10 (Sub threads) please according your cpu Use-n param to adjust the cpu rate--rsync the directory recursivly to the remote servers onceworking please wait...execute command: cd / data & & rsync-artuz-R-- delete. /-- timeout=100 rsync_body@192.168.91.166::data-- password-file=/etc/rsync.password > / dev/null 2 > & 1run The sersync:watch path is: / data # at this point, you can see that sersync has successfully started the # detection script [root@salt-client01 log] # pwd/usr/local/sersync/log [root@salt-client01 log] # vim rsync_fail_ log.sh [root @ salt-client01 log] # chmod + x rsync_fail_ log.sh [root @ salt-client01 ~] # cat / usr _ rsync_fail_ Whether it is alive#Author: cai meng zhiSERSYNC= "/ usr/local/sersync/bin/sersync2" CONF_FILE= "/ usr/local/sersync/conf/confxml.xml" STATUS=$ (ps aux | grep' sersync2' | grep-v 'grep' | wc-l) if [$STATUS-eq 0] Then $SERSYNC-d-r-o $CONF_FILE & else exit 0 After the fi script is written, Add to the scheduled task * / 1 * / bin/bash / usr/local/sersync/log/rsync_fail_log.sh > / dev/null 2 > & 1 Test synchronization: add a new file on the client side [root@salt-client01 data] # cp / etc/passwd 192.168.91.156.passwd [root@salt-client01 data] # lltotal 4mura RW Murray-1 root root 1928 Nov 10 18:15 192.168.91.156. Passwd-rw-r--r-- 1 root root 0 Nov 10 17:27 3 server detection [root@salt-master data] # cd / data/ [root@salt-master data] # lltotal 8 Murray Rkashi Ruki-1 root root 1928 Nov 10 18:15 192.168.91.156.passwd # description has been synchronized-rw-r--r-- 1 root root 0 Nov 10 17:27 3drwxr-xr-x 2 root root 4096 Nov 10 17:27 data guest Delete [root@salt-client01 data] # rm rf 192.168.91.156.passwd rm: cannot remove `rf': No such file or directoryrm: remove regular file `192.168.91.156.passwdflowers? Y [root@salt-client01 data] # lltotal 0 root root Nov 10 17:27 3 [root@salt-client01 data] # Server side: [root@salt-master data] # lltotal 4 RWMui RWMui-1 root root 0 Nov 10 17:27 3 # indicates that drwxr-xr-x 2 root root 4096 Nov 10 17:27 data has been deleted

4. Summary of common errors

Error 1: @ ERROR: auth failed on module xxxxxrsync: connection unexpectedly closed (90 bytes read so far) rsync error: error in rsync protocoldata stream (code 12) at io.c (150): this is because the password is set incorrectly and cannot be logged in successfully. Check rsync.pwd to see if the customer service matches. This can also happen if the rsync service is not started on the server side. Error 2: password file must not beother-accessiblecontinuing without password filePassword: note: this is because the permissions of rsyncd.pwdrsyncd.sec are incorrect and should be set to 600. For example, chmod600 rsyncd.pwd error 3: @ ERROR: chroot failedrsync: connection unexpectedly closed (75 bytes read so far) rsync error: error in rsync protocoldata stream (code 12) at io.c (150) Note: this is because the path path you set in rsync.conf does not exist It is necessary to create a new directory to enable synchronization error 4: rsync: failed to connect to218.107.243.2: No route to host (113) rsync error: error in socket IO (code10) at clientserver.c (104) [receiver=2.6.9]: firewall problems lead to, it is best to completely shut down the firewall first. This is the basic law for sorting errors, whether S or C. There are also ignore errors option problems that can also lead to error 5: @ ERROR: access denied to www fromunknown (192.168.1.123) rsync: connection unexpectedly closed (0 bytes received so far) [receiver] rsync error: error in rsync protocoldata stream (code 12) at io.c (359). It is obvious that this problem is caused by the configuration option hostallow. Beginners like to allow a segment to be configured, and then the module is the same again. Cause error 6: rsync error: received SIGINT,SIGTERM, or SIGHUP (code 20) at rsync.c (244) [generator=2.6.9] rsync error: received SIGUSR1 (code19) at main.c (1182) [receiver=2.6.9] description: this problem is mostly caused by the server service not being started normally, go to the server to check whether the service is started, and then check whether the / var/run/rsync.pid file exists The most straightforward way is to kill the service that has been started, and then start the service again or add the script to the system startup service level and then shutdown-r now server error 7: rsync: read error: Connection resetby peer (104) rsync error: error in rsync protocoldata stream (code 12) at io.c [sender=2.6.9] description: there is no data in the original data directory. Thank you for reading this article carefully. I hope the article "the method of real-time synchronization of sersync data in Linux" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

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: 231

*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

Servers

Wechat

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

12
Report