Rsync It is an application software under Unix/linux, it can keep multiple server data synchronization consistency, rsync will copy the whole content on the first synchronization, but only the modified files are transmitted the next time.
Rsync in the process of transmitting data, it is possible to compress and Unzip operation, so you can use less bandwidth. can easily do to keep the original file permissions, time, soft and hard links. Rsync has two synchronization methods, one based on SSH synchronization does not need to configure, a need for their own key synchronization needs to file configuration. The following is the way I use my own secret key: The majority of enterprises
Rsync installation
Experiment two virtual machines: Server 192.168.2.222, client 192.168.2.183
Easy to experiment, I use Yum installation method here: Yum Install rsync-y
I am here to customize the rsync configuration directory mkdir/home/lijq/.rsync/-p; Create configuration file Add the following VI rsyncd.conf;
UID = nobody
GID = Nobody
Use chroot = no
Max connections = 30
PID file =/home/lijq/.rsync/rsyncd.pid
Lock file =/home/lijq/.rsync/rsyncd.lock
Log file =/home/lijq/.rsync/rsyncd.log
Transfer logging = yes
Log format =%t%a%m%f%b
Syslog facility = Local3
Timeout = 300
[Test1]
Read Only = no
Path =/data/www
Comment = www
Auth users = Test
Secrets file =/home/lijq/.rsync/rsync.pas
Hosts allow = 192.168.2.183
Cd/home/lijq/.rsync; Create Rsync.pas key file test:123456 and give permissions chmod 666 Rsync.pas
Then start the service, I am here to customize the configuration path and port all start commands for the following:
/usr/bin/rsync--daemon--config=/home/lijq/.rsync/rsyncd.conf--port 7001
Using Ps-ef | grep rsync to view service startup conditions
Client configuration, only need to create Rsync.pas password file content 123456 under cd/home/lijq/.rsync/and give 600 permissions
Then create the server-side synchronization directory, the above configuration file is defined by the/data/www
Client execution Rsync-ap--delete [email protected]:: TEST1/ROOT/LIJQ--port=7001--password-file=/home/lijq/.rsy Nc/rsync.pas
The above command is the contents of the client Synchronization server file,/ROOT/LIJQ for the client directory can be defined by itself, the port is my own definition, test1 is my service-side definition of the synchronization module name
If error @error:auth failed on module test1 Please check the key profile, if error: rsync:failed to connect to 192.168.2.222:no the route to host (113) Please check Firewalls and selinux, bloggers suffer
After the synchronization command executes, it is found that the/data/www/files on the server are synchronized to the client/ROOT/LIJQ below, and the done
Two. The above client performs the command synchronization is the server directory file synchronization to the client to the equivalent of backup, and many enterprises are from the client to update the data to the service side therefore: You can execute the following command on the client.
/usr/bin/rsync-avzp--progress--delete--password-file=rsyncd1.pas--port=7001/root/lijq/ [email protected] :: Test1 Rsyncd1.pas is a key file that I created in the current directory, or it can be written as the previous path.
If the error is rsync Error:some files/attrs were not transferred (see previous errors) (code) at MAIN.C (1039) [sender=3.0.6] Check the service End Directory Permissions other users should have write permission Oh, done
Script Implementation synchronization: Here the script is the client data synchronization to the server side, the other can be defined by themselves:
#!/bin/bash#use for:sh 33.sh test serversysuser=testexport mokuai=test1export port=7001src_dir=/root/lijq/serverip= 192.168.2.222serverno=$1case "$" intest) echo ${rsyncsource%/*};; Server)/usr/bin/rsync-avzp--progress--delete--password-file=rsyncd1.pas--port=${port $SRC _dir [email protected]$ ServerIP:: $MOKUAI;; Esac
Done
Follow-up research continues to update
This article is from the "Fluffy Duck" blog, please be sure to keep this source http://woshitieren.blog.51cto.com/2466034/1679226
Rsync Synchronization Service installation configuration and script usage