"Tutorial topic": rsync
"Course recording": Gen E
"Main Content"
"1" rsync introduction
rsync (remote Synchronize) is a long-distance data synchronization tool that allows Multiple hosts to be synchronized quickly via Lan/wan, andrsync uses the " Rsync algorithm "to synchronize between the local host and the remote host, the algorithm is not every time the entire transfer, it only transmits two computers to back up the different parts of the data, so the speed is quite fast.
The advantages of Rsync are as follows:
1, can be mirrored to save the entire directory tree and file system.
2, can easily do to maintain the original file permissions, time, soft links and so on.
3, without special Envoy permission to install.
4, has the optimized process, the file transfer efficiency is high.
5, can use Rsh,SSH and other means to transfer files, of course, can also be directly connected through the Socket .
6, support anonymous transmission.
in addition, with SCP The transfer speed is not a hierarchical level. We often use rsync and SCP to transfer large amounts of Mysql data on LAN and find rsync at least than SCP Fast - times more so everyone if needed in Linux/unix a huge amount of data is transmitted between servers, Rsync is a very good choice.
"2" rsync service-side mode
First check whether rsync is installed:
Rpm–q rsync
rsync-2.6.8-3.1
Indicates that rsync is installed, and if the prompt appears package rsync was not installed then this software report does not install you can use Yum to install
Also, turn off the firewall and SELinux because it is in the intranet, so these are not necessary
Service iptables stop && chkconfig iptables off
Setenforce 0
Configuration file/etc/rsyncd.conf. This file is defined by itself, not created by the system, of course, you can also call a different name, followed by a detailed comment.
UID = nobody
GID = Nobody
User Chroot = No
Max connections = 200
Timeout = 600
PID file =/var/run/rsyncd.pid
Lock file =/var/run/rsyncd.lock
Log file =/var/log/rsyncd.log
[Backup]
path=/backup/
Ignore errors
Read Only = no
List = no
Hosts allow = 192.168.0.0/255.255.255.0
Auth users = Test
Secrets file =/etc/rsyncd.password
Comments:
UID = nobody
The user who made the backup, nobody for any user
GID = Nobody
Groups to be backed up, nobody to any group
Use chroot = no
If use chroot is specified as true, rsync first chroot to the directory specified by the path parameter before transferring the file. The reason for this is to implement additional security, but the disadvantage is that you need root permissions, and you cannot back up the directory files that point to external symbolic connections. By default, the Chroot value is true. But this is generally not necessary, I choose no or false
List = no
Column list not allowed
Max connections = 200
Maximum number of connections
Timeout = 600
Overrides the client-specified IP timeout, which means that the rsync server does not wait forever for a crashed client.
Pidfile =/var/run/rsyncd.pid
Where to store the PID file
Lock file =/var/run/rsync.lock
Where to store the lock file
Log file =/var/log/rsyncd.log
Where log files are stored
[Backup]
This is the name of the authentication module, which, like Samba syntax, is published externally
Path =/backup/
Here is the directory that participates in synchronization
Ignore errors
Some unrelated IO errors can be ignored
Read Only = no
Allow readable writable
List = no
Column list not allowed
Hosts allow = 192.168.1.0/255.255.255.0
This is the same syntax as Samba, allowing only the 192.168.21.0/24 network segment to be synchronized, rejecting everything else.
Auth users = Test
Authenticated user name
Secrets file =/etc/rsyncd.password
Password file storage address
Attention:
1. [Backup] authentication module name and path =/backup/Directory participating in synchronization
Here's path everyone to remember, here do not casually set up directly to finish, you know here is the authentication module, later from the client backup data will be stored here.
2. Auth users = Redhat authenticated user name
This name is the server side of the real user, we do not go directly with the steps but ignore this. If the server side less this, I guess your data synchronization will not be realized, we have to remember.
3. Path =/backup/The directory participating in synchronization
This needs to be built on your own in the root directory later
CD/
mkdir Backup
Chmod–r 777/backup
echo "Test:test" >/etc/rsync.password
(Here I set the user name and password consistent)
For security reasons, I set his permission to 600.
chmod 600/etc/rsync.password
Startup configuration
[Email protected] rsync-3.0.4]# Vim/etc/xinetd.d/rsync
Configurationrsync Servervi/etc/xinetd.d/rsync
WillDisable=yesinsteadNo
Service rsync
{
Disable = no
Socket_type = Stream
wait = no
user = root
Server =/usr/bin/rsync
Server_args =--daemon
Log_on_failure + = USERID
}
[Email protected] home]#/etc/init.d/xinetd restart
stopping xinetd: [OK]
Starting xinetd: [OK]
Ifxinetdif not, you need to install it.
[Email protected] home]# yum-y install xinetd
Rsynctwo methods for server-side startup:
StartrsyncService side (standalone boot)
[Email protected] home]#/usr/bin/rsync--daemon on
Start the rsync server (with xinetd Super process boot)
[Email protected] home]#/etc/init.d/xinetd Reload
Configuring rsync Auto-start
[[email protected] etc]# chkconfig rsync on
[Email protected] etc]# chkconfig rsync--list
Rsync
Join rc.local
In various operating systems, theRC file storage location is different, can be modified to enable the system to load the rsync--daemon .
[Email protected] home]# vi/etc/rc.local
/usr/local/rsync–daemon # Join a row
Client Configuration:
echo "Test" >/etc/rsyncd.password
This is just a password, no user required, so you need to manually interact when syncing
chmod 600/etc/rsync.password
Test : The following delete represents a command to delete a file where the destination exists and the source directory does not exist
Rsync-vzrtop--delete/home/ce [Email protected]::backup--password-file=/etc/rsyncd.password
Downloading files from the Server A: package,V: details,z - compression
Rsync-avz--password-file=/etc/rsyncd.password [Email protected]::backup/home/
Upload it locally to the server.
Rsync-avz--password-file=/etc/rsyncd.password/home [Email protected]::backup
"3" rsync client mode
Freq used:rsync-av
Download:rsync [ parameters ] remote file (remote path) local directory
Upload:rsync [ parameter ] local file remote directory
rsync Common Parameters
If you do not need interactive operation,rsync can also work as SCP , the following are commonly used rsync parameters.
Example: rsync-av [email protected]:/home/test/3.txt.
Indicates that the /home/test/3.txt file for the service 192.168.1.122 is copied to the current directory of this customer degree. "represents the current directory
-A,--archive archive mode, which means to transfer files recursively and keep all file attributes equal to -rlptgod
-V--verbose: Verbose mode output
-R--recursive: The subdirectory is processed in return mode.
-P--perms: Keep file Permissions
-O--owner: Keep file owner Information
-G--group: Keep Filegroup information
-T--times: Keep file time information
--delete: Delete whichDSTexist in andSRCfiles or directories that do not exist in the
--delete-excluded: Also delete the receiving end which this option formulates the drained file
-Z--compress: Compress the backed-up files as they are transferred
--exclude=pattern: Develop files that do not need to be transferred
--include=pattern: Do not exclude files that need to be transferred
--exclude-from=file: ExcludeFILEfiles in the development mode
--include-from=file: Not excludedFILEto develop a pattern matching file in the
----------------------------------------------------------------------
Description: Theoretically this is the line, because any server can be remotely connected, then as long as the IP, user name, password, you can go to the server, you can view the server files
This of course can be copied down, and then another server can log in, so the most primitive can copy the source server files to local, and then upload to another server, rsync, equivalent to skip the middle step
is to directly upload the source server files to another server, of course, there are two ways to configure the
The first: Server mode, need to configure a server as a server (pretending to be a server, in fact, two are servers), and then configure a bakup file, configure a user name and password, specifically used to be remotely connected
If the professional point, backup is called the authentication module, the user name and password file is called the authentication file, and then the client, also need to configure a key is the source server corresponding to the user's password, and then in the process of transmission
In the set of users, IP parameters, the equivalent of the source server user name, password, IP has, so you can transfer the
The rsync configuration of Linux for remote transfer of large amounts of data between servers