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 (instance!!)

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

Overview of rsync synchronization: Remote Sync-remote synchronization, support for local replication, or synchronization with other SSH or rsync hosts, is similar to scp, but richer than scp. Official website: http://rsync.samba.orgrsync synchronization features: 1, you can mirror the entire directory tree and file system. 2, it is easy to maintain the permissions, time, soft and hard links of the original file, etc., without special permissions to install. 3. Fast: rsync copies everything the first time it synchronizes, but only transfers the modified files the next time. Rsync can compress and decompress data during transmission, so less bandwidth can be used. 4, security: you can use scp, ssh and other methods to transfer files, of course, you can also use a direct socket connection. 5. Anonymous transmission is supported to facilitate website mirroring.

Example demonstrates the first step: configure rsync source server rsync is included in the system kernel, rpm-Q rsync to view the package, no additional installation. If the installation is minimized, you can install it using yum

1. Modify rsyncd.conf configuration file

[root@server ~] # vim / etc/rsyncd.conf # 7, 8, 9, uid = nobodygid = nobodyuse chroot = yes#11 line, pid file = / var/run/rsyncd.pid#16 line Dont compress = * .gz * .tgz * .zip * .z * .Z * .rpm * .bz2 # append port number port 87quota append log file path log file = / var/log/rsyncd.log# append authorization access address field hosts allow = 192.168.142.0According to add sharing module # module name [wwwroot] # source share directory path path = / var/www/html# website description comment = www.bdqn. Whether cn# is read-only read only = yes# authentication username auth users = backuper# authentication user password file path secrets file = / etc/rsyncd_users.db

two。 Create an authenticated user password file

[root@server ~] # vim / etc/rsyncd_users.db# write authentication username and password backuper:abc123

3. Authorization belongs only to the maximum authority of the master.

[root@server ~] # chmod 600 / etc/rsyncd_users.db

4. Install services for HTTP

[root@server ~] # yum install httpd-y

5. Create shared content

[root@server ~] # cd / var/www/html [root@server html] # echo "this is test web" > index.html

6. Start the service

[root@server html] # rsync-- daemon

7. View service status

[root@server html] # netstat-ntap | grep rsynctcp 0 0 0.0.0 ntap 873 0.0.0.0 LISTEN 60268/rsync tcp6 0 0: 873:: * LISTEN 60268/rsync

8. Turn off firewall and security features

[root@server html] # systemctl stop firewalld.service [root@server html] # setenforce 0 step 2: configure the customer initiator

1. Turn off firewall and security features

[root@localhost ~] # systemctl stop firewalld.service [root@localhost ~] # setenforce 0

two。 Install the http service

[root@localhost ~] # yum install httpd-y

3. Customer initiator configuration mode

# configure source mode 1, user name @ host address:: share module name [root@localhost] # rsync-avz backuper@192.168.142.153::wwwroot / var/www/htmlPassword: # enter user password receiving incremental file list./index.htmlsent 83 bytes received 172 bytes 72.86 bytes/sectotal size is 17 speedup is 0.0configuration to view the shared content [root@localhost ~] # cat / var/www/html/index.html this is test web# configuration source mode 2 Rsync:// username @ host address / sharing module name [root@localhost ~] # rsync-avz rsync://backuper@192.168.142.153/wwwroot / var/www/htmlPassword: receiving incremental file list./index.htmlsent 83 bytes received 172 bytes 56.67 bytes/sectotal size is 17 speedup is 0.0viewing shared content [root@localhost ~] # cat / var/www/html/index.html this is test web

4. Create an interaction-free password file

[root@localhost ~] # vim / etc/server.passabc123 [root@localhost ~] # chmod 600 / etc/server.pass# Free Mutual configuration Source method [root@localhost ~] # rsync-avz-delete-- password-file=/etc/server.pass backuper@192.168.142.153::wwwroot / var/www/htmlreceiving incremental file list./index.htmlsent 83 bytes received 172 bytes 510.00 bytes/sectotal size is 17 speedup is 0.01View shared content [root@localhost ~] # cat / var/www/html/index.html this is test web to use with inotify tool Realize rsync real-time synchronization configure rsync real-time synchronization: 1. The shortcomings of periodic synchronization: the time of performing backup is fixed, the details of delay, and poor real-time performance; when the synchronization source remains unchanged for a long time, intensive periodic tasks are unnecessary. The advantage of real-time synchronization: as soon as the synchronization source changes, backup is enabled; as long as the synchronization source does not change, the backup is not performed. Inotify: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. Available from version 2.6.13; can monitor changes in the file system and notify the response; auxiliary software: inotify-tools

Step 1: configure rsync+inotify real-time synchronization

1. Configure rsync source server and modify rsyncd.conf configuration file

[root@server ~] # vim / etc/rsyncd.conf # turn off read-only read only = no

two。 Adjust the client's inotify kernel parameters

[root@client ~] # vim / etc/sysctl.conf# Monitoring queue size fs.inotify.max_queued_events = 1638 "maximum number of monitoring instances fs.inotify.max_user_instances = 102" maximum number of monitoring files per instance fs.inotify.max_user_watches = 1048576

3. Effective kernel parameters

[root@client ~] # sysctl-pfs.inotify.max_queued_events = 16384fs.inotify.max_user_instances = 1024fs.inotify.max_user_watches = 1048576

4. Install the compilation environment

[root@client ~] # yum install-y gcc gcc-c++ make

5. Get the resource package remotely

[root@client ~] # mount.cifs / / 192.168.142.1/inotify / mnt [root@sclient ~] # cd / mnt [root@client mnt] # lsinotify-tools-3.14.tar.gz

6. Decompress the resource package

[root@client mnt] # tar zxvf inotify-tools-3.14.tar.gz-C / opt

7. Configure inotify

[root@client mnt] # cd / opt/inotify-tools-3.14/ [root@client inotify-tools-3.14] #. / configure

8. Compilation and installation

[root@client inotify-tools-3.14] # make & & make install

9. Install inotify-tools accessibility

[root@client inotify-tools-3.14] # inotifywait-mrq-e modify,create,move,delete / var/www/html/#-m indicates continuous monitoring,-r indicates recursive monitoring of all sub-objects,-Q indicates simplified output information, and-e indicates which time types to monitor

10. Reopen a terminal to log in, add and delete files

# create file [root@client html] # touch abc [root@client html] # lsabc index.html# delete file [root@client html] # rm-rf abc [root@client html] # lsindex.html

11. Return to the monitoring side to verify the synchronization effect

[root@client inotify-tools-3.14] # inotifywait-mrq-e modify,create,move,delete / var/www/html//var/www/html/ CREATE abc # create record / var/www/html/ DELETE abc # delete record

twelve。 Trigger rsync synchronization operation script through inotifywait

Vim inotify.shincedbinbinarBash-mrq-e modify,create,attrib,move,delete / var/www/html/ "RSYNCLCMD=" rsyne-azH-- delete-- password-file=/etc/server.pass / var/www/htm1/ backuper@192.168.142.153::wwwroot/ "$INOTIFY_CMD | while read DIRECTORY EVENT FILE# reads the output monitoring record doif [$(pgrep rsync | wc-l)-le 0]; then# starts $RSYNC_CMDfidone immediately if rsync is executed

13. Both the source and the client require the highest authorization of the html directory

[root@server www] # chmod 777 html/ [root@client www] # chmod 777 html/

14. Execute script

[root@client opt] # source inotify.sh

15. Reopen the terminal and cut into the shared directory

[root@client opt] # cd / var/www/html/

16. Write new content

[root@client html] # echo "this is my update" > test.txt step 2: verify real-time synchronization * * 1. Go back to the source side to view the synchronization packet * * [root@server html] # lsindex.html test.txt

two。 View synchronization data

[root@server html] # cat test.txt this is my update 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