In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article shows you what is rsync remote synchronization, the content is concise and easy to understand, can definitely brighten your eyes, through the detailed introduction of this article, I hope you can get something.
About rsync
A fast incremental backup tool
Remote Sync, remote synchronization
Support local replication or synchronize with other SSH or rsync hosts
Official website: http://rsync.samba.org
Configure the rsync source server
Configure the rsync source server
The remote server of the backup operation, also known as the backup source
Configure rsync Feed
Configure rsync Feed
Set up rsync.conf configuration files, independent account files
Enable rsync-- daemon mode
Application example
User backuper, which allows downlink synchronization
The directory of the operation is / var/www/html
Profile rsyncd.conf
It needs to be established manually. The syntax is similar to Samba configuration.
Auth users,secrets file is configured for authentication. If not added, it will be anonymous.
Rsync account file
Adopt the record format of "user name: password", with one user record per line
Independent account data, not dependent on system account
Enable the rsync service
Provide services alone through-- daemon
Execute kill $(cat / var/run/rsync.pid) to shut down the rsync service
Use the rsync backup tool
The usage of rsync command
Rsync [option] original location target location
Common option
-a: archive mode, recursive merge to retain object attributes, etc., for-rlptgoD
-v: displays the details of the synchronization process
-z: compress the file when transferring it
-H: keep hard connection files
-A: keep ACL attribute information
-- delete: delete files that exist in the target location but not in the original location
-- checksum: determines whether to skip files based on the checksum of the object
Two representations of configuration sources
Format 1: user name @ host address:: shared module name
Format 2:rsync:// user name @ host address / shared module name
Rsync real-time synchronization
The deficiency of periodic synchronization
The time of performing backup is fixed, the delay is obvious, and the real-time performance is poor.
When the synchronization source remains unchanged for a long time, intensive periodic tasks are unnecessary.
Advantages of real-time synchronization
Start the backup as soon as the synchronization source changes
As long as there is no change in the synchronization source, no backup is performed.
Experimental environment
Rsyncd:192.168.52.134
Client:192.168.52.148
Modify the configuration file on the rsyncd server
[root@rsyncd ~] # rpm-Q rsync # # check if rsync is installed, not with yum
Rsync-3.0.9-18.el7.x86_64
[root@rsyncd ~] # vim / etc/rsyncd.conf
Uid = nobody # # Anonymous user
Gid = nobody
Use chroot = yes # # imprison home directory
Pid file = / var/run/rsyncd.pid # # pid file
Address = 192.168.13.128 # # listening address
Port = 873 # # listener port number
Log file = / var/log/rsyncd.log # # Log file path
Hosts allow = 192.168.13.0and24 # # allow address range access
Dont compress = .gz .tgz .zip .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
Read only = yes # # enable read-only
Auth users = backuper # # Authentication user name
Secrets file = / etc/rsyncd_users.db # # password file
[root@rsyncd ~] # vim / etc/rsyncd_users.db # # create a password file
Backuper:abc123 # # user name: password
[root@rsyncd ~] # chmod 600 / etc/rsyncd_users.db # # give root users read and write permissions
[root@rsyncd ~] # rsync-- daemon # # enable rsync service
[root@rsyncd ~] # netstat-ntap | grep rsync # # View port
Tcp 0 192.168.52.134VR 873 0.0.0.0 * LISTEN 15471/rsync
[root@rsyncd ~] # systemctl stop firewalld.service # # turn off the firewall
[root@rsyncd ~] # setenforce 0
[root@rsyncd ~] # yum install httpd-y # # install the 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 to facilitate any user to operate
[root@rsyncd www] # ll # # View permissions
Total dosage 0
Drwxr-xr-x. 2 root root 6 August 8 19:42 cgi-bin
Drwxrwxrwx. 2 root root 24 December 13 15:11 html
[root@rsyncd www] #
On the client server, pull the synchronization source rsyncd
[root@client ~] # rpm-Q rsync # # check whether the rsync service is installed
Rsync-3.0.9-18.el7.x86_64
[root@client ~] # systemctl stop firewalld.service # # turn off the firewall
[root@client ~] # setenforce 0
[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] # ls-l # # check where to go first
Total dosage 0
Drwxr-xr-x. 2 root root 6 August 8 19:42 cgi-bin
Drwxrwxrwx. 2 root root 6 August 8 19:42 html
# # synchronization format 1:
[root@client www] # rsync-avz backuper@192.168.52.134::wwwroot / var/www/html/
# # pulling sharing Module
Password: # # enter password
. /
Index.html
Sent 83 bytes received 172 bytes 46.36 bytes/sec
Total size is 17 speedup is 0.07
[root@client www] # ls
Cgi-bin html
[root@client www] # cd html/
[root@client html] # ls
Index.html
[root@client html] # cat index.html # # View synchronization
This is test web
[root@client html] #
[root@client www] # cat html/index.html
This is test web
# # synchronization format 2:
[root@client html] # rm-rf index.html # # Delete synchronized files
[root@client html] # ls
[root@client html] # rsync-avz rsync://backuper@192.168.52.134/wwwroot / var/www/html/
# # pulling sharing Module
Password: # # enter password
Receiving incremental file list
. /
Index.html
Sent 83 bytes received 172 bytes 72.86 bytes/sec
Total size is 17 speedup is 0.07
[root@client html] # ls
Index.html
[root@client html] # cat index.html # # View synchronization
This is test web
[root@client html] #
# # No interaction synchronization:
[root@client html] # rm-rf index.html # # Delete synchronized files
[root@client html] # touch abc.html # # create an abc.html file in the directory
[root@client html] # ls
Abc.html
[root@client html] #
[root@client html] # vim / etc/server.pass # # create a local password file
Abc123
[root@client html] # chmod 600 / etc/server.pass # # give permission
[root@client html] #
[root@client html] # rsync-avz-delete-password-file=/etc/server.pass backuper@192.168.52.134::wwwroot / var/www/html/
# # specify local password files and delete files that exist in the target location but not in the original location to achieve interaction-free
Receiving incremental file list
Deleting abc.html
. /
Index.html
Sent 83 bytes received 172 bytes 170.00 bytes/sec
Total size is 17 speedup is 0.07
[root@client html] # ls # # you can see that abc.html has been deleted because the-- delete option has been added
Index.html
[root@client html] # cat index.html
This is test web
[root@client html] #
Install inotify monitoring on the client
[root@client html] # cd.. /
[root@client www] # vim / etc/sysctl.conf # # modify kernel parameter file
Fs.inotify.max_queued_events = 16384 # # queue
Fs.inotify.max_user_instances = 1024 # # number of instances in each queue
Fs.inotify.max_user_watches = 1048576 # # number of files per instance
[root@client www] # sysctl-p # # load
Fs.inotify.max_queued_events = 16384
Fs.inotify.max_user_instances = 1024
Fs.inotify.max_user_watches = 1048576
[root@client www] # mount.cifs / / 192.168.100.100/tools / mnt/tools/ # # Mount
Password for root@//192.168.100.100/tools:
[root@client www] # cd / mnt/tools/inotify/
[root@client inotify] # tar xf inotify-tools-3.14.tar.gz-C / opt/ # # decompress inotify to / opt
[root@client inotify] # cd / opt/inotify-tools-3.14/
[root@client inotify-tools-3.14] # yum install gcc gcc-c++ make-y # # necessary components for the installation environment
[root@client inotify-tools-3.14] #. / configure # # configuration
[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/
# # Monitoring
# # restart the terminal that opens a client
[root@client ~] # cd / var/www/html/
[root@client html] # ls
Index.html
[root@client html] # touch abc
[root@client html] # rm-rf abc
[root@client html] #
# # View on the client on the monitoring
/ var/www/html/ CREATE abc
/ var/www/html/ DELETE abc
Create a script on the client and trigger the rsync synchronization operation script through inotifywait
[root@client inotify-tools-3.14] # cd / opt/
[root@client opt] # vim inotify.sh
#! / bin/bash
INOTIFY_CMD= "inotifywait-mrq-e modify,create,move,delete / var/www/html/"
RSYNC_CMD= "rsync-azH-delete-password-file=/etc/server.pass / var/www/html/ backuper@192.168.52.134::wwwroot/"
$INOTIFY_CMD | while read DIRECTORY EVENT FILE
Do
If [$(pgrep rsync | wc-l)-le 0]; then
$RSYNC_CMD
Fi
Done
[root@client opt] # chmod + x inotify.sh # # give execution permission
# # ensure that the permissions of both the server and the client are maximum
Modify the configuration file on the rsyncd server
[root@rsyncd www] # vim / etc/rsyncd.conf
Read only = no # # turn off read only
[root@rsyncd www] # pkill-9 rsync # # off
[root@rsyncd www] # netstat-ntap | grep rsync
[root@rsyncd www] #
[root@rsyncd www] # rm-rf / var/run/rsyncd.pid # # Delete the pid file
[root@rsyncd www] # rsync-- daemon # # enable rsync service
[root@rsyncd www] # netstat-ntap | grep rsync
Tcp 0 192.168.52.134VR 873 0.0.0.0 * LISTEN 50571/rsync
[root@rsyncd www] #
Execute the inotify script file on the client
# # client execution script
[root@client opt] #. / inotify.sh
# # entering Monitoring status
# # restart a client terminal
[root@client ~] # cd / var/www/html/
[root@client html] # ls
Index.html
[root@client html] # echo "this is test" > test.txt # # add text
# # viewing Monitoring Service Information
[root@client opt] #. / inotify.sh
Rsync: failed to set times on "/." (in wwwroot): Operation not permitted (1)
Rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c (1052) [sender=3.0.9]
# # View on rsync server
[root@rsyncd www] # cd html/
[root@rsyncd html] # ls
Index.html test.txt # # synchronization completed
# # in the newly opened client terminal
[root@client html] # rm-rf test.txt
[root@client html] # ls
Index.html
[root@client html] #
# # View on rsync server
[root@rsyncd html] # ls
Index.html
[root@rsyncd html] #
# # deletion is also synchronized
What is the above content of rsync remote synchronization? have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.