In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces "how to configure Centos rsync file synchronization". In daily operation, I believe many people have doubts about how to configure Centos rsync file synchronization. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts of "how to configure Centos rsync file synchronization". Next, please follow the editor to study!
Rsync is a data mirror backup tool in unix-like systems, which can be seen from the naming of the software-- remote sync.
Its features are as follows:
You can mirror and save the entire directory tree and file system.
You can easily maintain the permissions, time, soft and hard links of the original file, and so on.
It can be installed without special permission.
Fast: rsync copies everything the first time it synchronizes, but only transfers modified files the next time. Rsync can compress and decompress data during transmission, so less bandwidth can be used.
Security: you can use scp, ssh, etc., to transfer files, of course, you can also use a direct socket connection.
Anonymous transmission is supported to facilitate website mirroring.
Server-side configuration:
# yum-y install xinetd
# vi / etc/xinetd.d/rsync
The code will be as follows
The copy code is as follows:
Service rsync
{
Disable = yes
Socket_type = stream
Wait = no
User = root
Server = / usr/bin/rsync
Server_args =-daemon
Log_on_failure + = userid
}
Change disable = yes in to disable = no
Then start xinetd
# / etc/init.d/xinetd start or service xinetd restart
Note: if there is a firewall on the server, remember to open the port. The default port is 873.
# telnet 127.0.0.1 873
Trying 127.0.0.1...
Telnet: connect to address 127.0.0.1: connection refused
# iptables-an input-s 192.168.0 accept 255.255.255.0-p tcp-m tcp-- dport 873-j accept
# iptables-an input-p tcp-m tcp-- dport 873-j drop
# vi / etc/rsyncd.conf (if this file does not exist, create it yourself)
# global settings
Uid = root # in what capacity do you run rsync
Gid = root
Use chroot = no # do not use chroot
Max connections = 20 # maximum connections
Secrets file = / etc/rsyncd.secrets # password file location, authentication file settings, user name and password setting
Log file = / var/log/rsyncd.log # specifies the log file for rsync and does not send the log to syslog
Pid file = / var/run/rsyncd.pid # specifies the pid file for rsync
Lock file = / var/run/rsync.lock # specifies the lock file that supports the max connections parameter. The default value is / var/run/rsyncd.lock
Comment = hello world
# motd file = / etc/rsyncd.motd # Welcome information file name and location (this file is not available, you can add it yourself)
[backup] # here is the name of the authentication module, which needs to be specified on the client side
Path = / titan24/www/repos # the directory to be mirrored
Auth users = rsync # authorized account. The authenticated user name, if there is no such line, indicates that it is anonymous, separated by multiple users
Read only = no # yes read-only value means no means readable and writable mode, and data recovery uses no
Hosts allow = 192.168.3.128 # allowed access server ip
Hosts deny = * # blacklist
List = true # allow column files
# ignore errors # you can ignore some extraneous io errors
# exclude = cache/111/ cache/222/ # ignored directories
# vi / etc/rsyncd.secrets (set user name and password for access (authentication))
Rsync:111111 # username: password
Give the file the correct permissions
# chown root:root / etc/rsyncd.secrets
# chmod 600 / etc/rsyncd.secrets # (must be 600)
Second, synchronize on the client side
The client seems to have installed rsync by default. If not, install:
# yum-y install rsync
Perform asynchronous synchronous operations:
/ usr/bin/rsync-avz-- progress rsync@192.168.3.191::backup / www
# crontab-e # (files can be synchronized every three minutes regularly)
* / 3 * rsync-avz-- progress rsync@192.168.3.191::backup / www
The following command is complete:
# vi / etc/rsyncd.pas
Add password
Rsyncofpass
Note that the client password file only requires a password, not a user name!
Change file permissions:
# chmod 0600 / etc/rsyncd.pas
# rsync-vzrtopgu-- progress-- delete-- password-file=/etc/rsyncd.pas rsync_user@192.168.0.2::rsync_module_name1 / www/
The v in-vzrtopg in this command line is verbose
Z is compressed transmission
R is recursive
Topg is a parameter that keeps the original attributes of the file, such as owner and time.
U is to synchronize only updated files to avoid repeated updates without updating, but pay attention to the synchronization of the clocks of the two machines.
-progress means to show a detailed progress
-delete means that if the server deletes the file, the client deletes the file accordingly to maintain true consistency.
In the rear rsync_user@192.168.0.2::rsync_module_name1, the following rsync_module_name1 is the module name, which is the name customized in / etc/rsyncd.conf, and rsync_user is the user name specified in the specified module that can be synchronized.
The last / www is the directory name that is backed up to the local directory.
In this case, an encrypted connection can also be established with the parameter-e ssh.
The password file can be specified with-password-file=/password/path/file so that it can be used in the script without having to enter the authentication password interactively. It is important to note that the permission attribute of this password file should be set to be readable only to the owner.
# / usr/local/rsync/bin/rsync-vzrtopg-progress-delete rsync_user@192.168.0.2::rsync_module_name1 / tmp/
Password:
Or you can make password files.
Since the system crontab execution is required, the password file is read in here.
It was successful at this time.
Synchronization command description:
1 display the contents of the directory
Command
--
A) rsync
B) rsync-r
C) rsync jack@192.168.0.1::
D) rsync ssh_user@192.168.0.1:
Command description
-
A) display the contents of the directory (layer 1)
B) Recursive display of directory contents
C) display remote host directory contents
* Note 1: Port mode, authentication based on rsync users
* Note the directory on 2:rsync server must have the permission of xx7.
D) View the contents of the remote host directory
* Note 1:remote shell mode, authentication based on local users of the system through ssh connections
* Note 2: only a colon (:) is used here, and the user name is the ssh user of the remote host, and the password is also the password of the ssh user.
* Note 3: use "to list the information of the folder itself. To list the contents of a folder, use "/".
Parameter description
-
-r recursively operate on the directory
2 synchronization between local directories
Command
--
A) rsync-av-progress / * * Note (/) * *
B) rsync-av-progress
C) rsync-avu-progress-delete /
D) rsync-av-progress-temp-dir=/tmp /
Command description
-
A) synchronize all files in the src-dir directory to the dst-dir directory
B) synchronize all files in the src-dir directory to the dst-dir/src-dir directory
C) differentially update the contents of the src-dir directory to the dst-dir directory, add and replace if you add / update, and delete if you decrease
D) more-temp-dir=/tmp than a), that is, designate / tmp as the temporary swap area, which avoids the error that files cannot be synchronized due to insufficient target directory space.
Parameter description
-
-an is equivalent to the collection of-rlptgod
-u is equivalent to-update and does not update when the destination file is newer than the source file
-v displays synchronized files
-progress displays the percentage progress and transfer rate of file synchronization
-delete deletes more files in the destination directory than the source directory
3 synchronization between remote hosts
Command
--
A) rsync-avz-progress jack@192.168.0.1::/
B) rsync-avz-progress jack@192.168.0.1::/-password-file=/home/jack/rsync.jack
C) rsync-avuz-progress-delete jack@192.168.0.1::/-password-file=/home/jack/rsync.jack
D) rsync-avz-progress jack@192.168.0.1::/
Command description
-
A) synchronize the contents of the local directory to the directory of the remote host 192.168.0.1, where jack is the rsync database user (see 3. / etc/rsync.secrets)
B) synchronization of non-interactive login files by automatically reading the user's password
C) more-u and-delete than b)
D) synchronize the remote host content to the local directory
At this point, the study on "how to configure Centos rsync file synchronization" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.