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

Rsync remote synchronization-(actual combat! )

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

About Remote Sync, a fast incremental backup tool for rsync, remote synchronization supports local replication, or synchronizes with other SSH,rsync hosts to configure rsync source server rsync synchronization source refers to the remote server for backup operation, also known as backup source

Basic idea of configuring rsync source to set up rsync.conf configuration file, independent account file enable rsync-- daemon mode application sample user backuper, the directory that allows the following synchronization operation is / var/www/html configuration file rsyncd.conf needs to be established manually, the syntax is similar to Samba configuration authentication configuration auth users,secrets file, and the anonymous rsync account file is recorded in the format of "user name: password" if not added. One user per line records independent account data, independent of system account enabling rsync service via-- daemon provides services alone to execute kill $(cat / var/run/rsync.pid) turn off rsync service using rsync backup tool rsync command usage rsync [options] original location target location common options-a: archive mode, recursive and retain object attributes And so on-rlptgoD-v: display details of the synchronization process-z: compress files when transferring files-H: keep hard connection files-A: retain ACL attribute information-delete: delete files that are present in the target location but not in the original location-- checksum: two representations of the file configuration source format 1: user name @ host address:: share based on the checksum of the object Module name format 2:rsync:// user name @ host address / shared module name rsync real-time synchronization deficiency of regular synchronization time for backup is fixed Obvious delay, poor real-time performance when the synchronization source does not change for a long time, intensive periodic tasks are unnecessary real-time synchronization advantages. Once the synchronization source changes, immediately start the backup as long as the synchronization source does not change, then do not perform backup about inotify (installed on the initiator) Inotify is a Linux feature that monitors file system operations, such as read, write and create. Inotify is responsive, easy to use, and much more efficient than the busy polling of cron tasks. Can monitor changes in the file system and make a notification response; auxiliary software: inotify-tools

Lab environment rsyncd server 192.168.13.128client server 192.168.13.1291 Modify the configuration file [root@rsyncd ~] # rpm-Q rsyncrsync-3.0.9-18.el7.x86_64 [root@rsyncd ~] # vim / etc/rsyncd.confuid = nobody # # anonymous user gid = nobodyuse chroot = yes # # locked home directory pid file = / var/run/rsyncd.pid # # pid file address = 192.168.13.128 # # listening address port = 873 # # port number log on the rsyncd server File = / var/log/rsyncd.log # # Log file path hosts allow = 192.168.13.0 take 24 # # allow address fields to access dont compress = * .gz * .tgz * .zip * .z * .Z * .rpm * .deb * .bz2 # # types that do not require compression [wwwroot] # # shared module name path = / var/www/html # # path comment = www.kgc.com # # definition name Say read only = yes # # read-only auth users = backuper # # Authentication username secrets file = / etc/rsyncd_users.db # # password file [root@rsyncd ~] # vim / etc/rsyncd_users.db # # create a password file backuper:123123 # # username: password [root@rsyncd ~] # chmod 600 / etc/rsyncd_users.db # # give root user read and write access [root@rsyncd ~] # rsync-- daemon # # enable rsync service [root@rsyncd ~] # netstat-ntap | grep rsync # # View port tcp 0 0192.168.13.128 netstat 0.0.0.0 root@rsyncd * LISTEN 36346/rsync [root@rsyncd ~] # systemctl stop firewalld.service # # turn off firewall [root@rsyncd ~] # setenforce 0 [root@rsyncd ~] # yum install httpd-y # # install httpd service [root@rsyncd ~] # cd / Var/www/html/ [root@rsyncd html] # echo "this is test web" > index.html # # create web page information [root@rsyncd html] # cd.. / [root@rsyncd www] # chmod 777 html/ # # give maximum permission Convenient for any user to operate 2, on the client server Pull the synchronization source rsyncd [root@client ~] # systemctl stop firewalld.service # # close the firewall [root@client ~] # setenforce 0 [root@client ~] # rpm-Q rsync # # check if the rsync service rsync-3.0.9-18.el7.x86_64 [root@client ~] # yum install httpd-y # # install the httpd service [root@client ~] # cd / var/www/ [root@client www] # chmod 777 html/ # # Give maximum permission [root@client www] # rsync-avz backuper@192.168.13.128::wwwroot / var/www/html/ # # pull sharing module Password: # # enter password [root@client www] # cat html/index.html # # View synchronization this is test web [root@client www] # rm-rf html/index.html [root@client www] # vim / etc/server.pass # # create a local password File 123123 [root@client www] # chmod / etc/server.pass # # specify the local password file to the permission [root@client www] # rsync-avz-- delete-- password-file=/etc/server.pass backuper@192.168.13.128::wwwroot / var/www/html/ # # Delete files that exist in the target location but not in the original location to achieve interaction-free 3 Install inotify monitoring [root@client www] # vim / etc/sysctl.conf # # modify kernel parameter file fs.inotify.max_queued_events = 16384 # # queue fs.inotify.max_user_instances = 1024 # # instances in each queue fs.inotify.max_user_watches = 1048576 # # number of files in each instance [root@client www] # sysctl-p # # load [root@client www] # Mount.cifs / / 192.168.100.3/LNMP-C7 / mnt/ # # Mount Password for root@//192.168.100.3/LNMP-C7: [root@client www] # cd / mnt/ [root@client mnt] # tar zxvf inotify-tools-3.14.tar.gz-C / opt/ # # decompress inotify to / opt [root@client mnt] # cd / opt/ [root@client opt] # cd inotify-tools-3.14/ [root @ client inotify-tools-3.14] # yum install gcc gcc-c++ make-y # # essential components of the installation environment [root@client inotify-tools-3.14] # / configure # # configure [root@client inotify-tools-3.14] # make & & make install # # compile and install [root@client inotify-tools-3.14] # inotifywait-mrq-e modify Create,move,delete / var/www/html/ # # Monitor # # restart the terminal that opens a client [root@client ~] # cd / var/www/html/ [root@client html] # touch abc [root@client html] # rm-rf abc # # View / var/www/html/ CREATE abc/var/www/html/ DELETE abc4 on the client on the monitor Create a script on the client Trigger the rsync synchronous operation script [root@client inotify-tools-3.14] # cd / opt/ [root@client opt] # vim inotify.shallows synchronization through inotifywait. BINGINOTIFY synchronization CMD = "inotifywait-mrq-e modify,create,move Delete / var/www/html/ "RSYNC_CMD=" rsync-avz-- delete-- password-file=/etc/server.pass / var/www/html/ backuper@192.168.13.128::wwwroot/ "$INOTIFY_CMD | while read DIRECTORY EVENT FILE do if [$(pgrep rsync | wc-l)-le 0] Then $RSYNC_CMD fidone [root@client opt] # chmod + x inotify.sh # # give execution permission # # ensure that the permissions of both the server and the client are up to 5 Modify the configuration file [root@rsyncd www] # vim / etc/rsyncd.confread only = no # # close the read-only [root@rsyncd www] # netstat-natp on the rsyncd server | grep rsynctcp 0 0192.168.13.128vim 873 0.0.0.0vim * LISTEN 36346/rsync [root@rsyncd www] # kill-9 36346 # # close [root@rsyncd www] # netstat-natp | grep rsync [root@rsyncd www ] # rm-rf / var/run/rsyncd.pid # # Delete pid file [root@rsyncd www] # rsync-- daemon # # enable rsync service 6 Execute the inotify script file [root@client opt] #. / inotify.sh## on the client to restart a client terminal [root@client html] # echo "this is test" > test.txt # # add text # # View the monitoring service information [root@client opt] #. / inotify.sh sending incremental file list./rsync: failed to set times on "/." (in wwwroot): Operation not permitted (1) test.txtsent 121 bytes received 30 bytes 302.00 bytes/sectotal size is 30 speedup is 0.20rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c (1052) [sender=3.0.9] sending incremental file listsent 66 bytes received 8 bytes 148.00 bytes/sectotal size is 30 speedup is 0.417 Check [root@rsyncd www] # cd html/ [root@rsyncd html] # lsindex.html test.txt # # synchronous completion # # deletion is also synchronous on the rsync server. Thank you for reading!

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

Servers

Wechat

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

12
Report