Simple file synchronization between Linux

  

Yesterday, mysql synchronization was done well, and today, by the way, the website code synchronization research. Online search for rsync, unison and other software can achieve synchronization. Looked at the vps already installed rsync, then use this. The process of installing rsync is ignored, you can use yum or apt-get to install, you can also download it on the official website: http://rsync.samba.org

The current environment is, two fixed ip Linux server, to achieve a regular synchronization of a directory of server A to server B. So I want to treat A as the rsync server and B as the rsync client.

Configure A first:

A is centos above, use xinetd to run rsync. In general, xinetd is also included in the system, and there is no yum.

Modify the rsync startup file in xinetd: vi /etc/xinetd.d/rsync

Change the disable=yes to disable=no, the complete code is as follows: # default: off # description: The rsync server is a good addition to an ftp server, as it \\# allows crc checksumming etc.service rsync{disable = noflags = IPv4socket_type = streamwait = nouser = rootserver = /usr/bin/rsyncserver_args = --daemonlog_on_failure + = USERID}

Next modify the rsync configuration file, located in /etc/rsyncd.conf, if not, you can create a new one: uid = root # run root as gid = rootuse chroot = nomax connections = 5 # simultaneous connection Number pid file = /var/run/rsyncd.pidlock file = /var/run/rsyncd.locklog file = /var/log/rsyncd.logtransfer logging = yesport = 873 #用港口[www]#module name, just fill the read Only = yes #yes is read only path = /home/www # directory to be synchronized (multiple separated by spaces) comment = www #best as the module name auth users = rsync #allow which users are allowed to synchronize (required later Set) secrets file = /etc/r Sync.pas #userprofile (username+password)hosts allow = 111.111.111.111 #ip address allowed for synchronization exclude = tmp/123/#不sync directory (relative path, multiple spaces separated)

Create a file to store the key, the location of the secrets file above: Username: Password

eg

admin:admin

Start xinetd, see rsync can No, the port 873 is occupied.

You can test it with telnet on server B. If you can configure iptables, you need to open port 873.

The next step is to configure the client. Since it is not a two-way synchronization, just install rsync.

Set the key file (read from inside rsync runtime). My put in /etc/rsync.pas, the content is the password set above.

The following can be performed by synchronizing the rsync command: rsync -avz --password-file=/etc/rsync.pas [email protected]::www /home/www

avz I will not explain these parameters, and the parameters provided by rsync are much better.

--password-file is the above key file, @ is the account set by the server before, @ is the ip of the server, @:www is the module name, sync to the local /home/www directory .

If the command is executed successfully, you can add the above command to the crontab to achieve timed file synchronization.

Copyright © Windows knowledge All Rights Reserved