How to configure Rsync to synchronize backup storage in linux

Source: Internet
Author: User
Article Title: linux Rsync synchronization backup storage configuration tutorial. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.

Master server: 192.168.0.220 (CentOS 4.4)

Slave server: 192.168.0.248 (CentOS 5)

============================ 1> install rsync on both hosts ======================================

Installed by default.

1 2 [root @ office ~] # Rpm-qa | grep rsync rsync-2.6.3-1

If it is not installed, use yum install rsync for installation. Normally, the installation is completed soon, And the rsync server is easy to set up. After installing rsync, the configuration file and rsync server startup program are not found, because each administrator may have different purposes for rsync, so the general release version is just to install the software, the administrator can set up rsync servers based on their own purposes and methods.

===============================2> rsync server configuration ==== ======================================

Create an rsyncd directory under the/etc directory, which is used to store rsyncd. conf, rsyncd. secrets and rsyncd. motd file; rsyncd. conf is the main configuration file of the rsync server; rsyncd. secrets is the user password file; rsyncd. configure some service welcome and description information for motd;

A> Create and modify rsyncd. conf

Rsyncd. conf is the main configuration file of the rsync server. Let's take a simple example. For example, we want to back up the/tmp/directory on the server, in/tmp, I want to set the test directory and test. PHP files excluded;

1 2 3 4 [root @ office ~] # Cd/etc [root @ office ~] # Mkdir rsyncd [root @ office ~] # Cd rsyncd [root @ office ~] # Vi rsyncd. conf

Write (ensure that there is no space in each line of the file ):

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 28 29 30 31 32 33 34 35 36 38 39 40 41pid file =/var/run/rsyncd. pid port = 873 address = 192.168.0.220 # uid = nobody # gid = nobody uid = root gid = root use chroot = yes read only = yes # limit access to private LANs # Set accessible host: multiple ip addresses are separated by spaces: 192.168.0.3 192.168.0.4 192.168.0.5 or set the interval 192.168.0.3/5 hosts allow = 192.168.0.0/24 hosts deny = * max connections = 5 motd file =/etc/rsyncd. motd # This will give you a separate log file =/var/log/rsync. log # This will log every file transferred-up to 85,000 + per user, per sync transfer logging = yes log format = % t % a % m % f % B syslog facility = local3 timeout = 300 # Set the module name in square brackets [linuxsirhome] # synchronize servers path =/backup list = yes ignore errors # auth users is a real system user that must exist on the server, if you want to use multiple users, separate them with commas (,). For example, auth users = ljzhou, rsyncsir auth users = ljzhou # access the required password file secrets file from the server =/etc/rsyncd. secrets comment = linuxsir tmp # Set non-synchronous directories or files to be separated by spaces. exclude = test/test. php

B> Create and modify the password file rsyncd. secrets

1 2 [root @ office ~] # Cd/etc/rsyncd [root @ office ~] # Vi rsyncd. secrets

Write: ljzhou: 123456 exit save. Modify the permission of the password file:

1 [root @ office ~] # Chmod 600 rsyncd. secrets

C> Create and modify the rsync. motd File

Rsyncd. motd defines the rysnc server information, that is, the user login information. For example, let the user know who provided the server. For example, when logging on to an ftp server, we see linuxsir.org ftp ....... Of course, this is not necessary for global definition of variables. You can use # To note or delete them. For example:

1 [root @ office ~] # Vi rsyncd. motd

Write: welcome!

===============================3> Start the rsync service ====== ======================================

1 [root @ office ~] #/Usr/bin/rsync -- daemon -- config =/etc/rsyncd. conf

1

=================================4> rsync has been configured on the master server! Next we set the slave server ================

You only need to install rsync on the slave server, and then run:

1 [root @ devel ~] #/Usr/bin/rsync-vzrtopg -- progress ljzhou@192.168.0.220: linuxsirhome/tmp

# Because no password file is specified, You need to manually enter the password set on the master server and enter the password: 123456 ljzhou is the user name in the specified password file: linuxsirhome indicates that the password is stored in rsyncd. the module name/tmp set in conf is from the server directory (192.168.0.248/tmp) till now, between the two hosts of rsync (192.168.0.220/tmp and 192.168.0.248/tmp) rsync synchronization has been configured. You only need to execute the above command on the slave server and enter the password to synchronize.

========================================= 5> set automatic synchronization for the master-slave server at a scheduled time = ==================================

The cron service on the slave server is used for automatic synchronization. for cron introduction, see: linux scheduled execution system. We create two rsyncs under the/tmp directory of the slave server 192.168.0.248. sh file and rsync. secrets file. The rsync. sh file is the script file to be executed by cron. Rsync. secrets is the file that saves the master server password.

A> Create an rsync. sh File

1 2 [root @ devel ~] # Cd/tmp [root @ devel ~] # Vi rsync. sh

Write:/usr/bin/rsync-vzrtopg-progress ljzhou@192.168.0.220: linuxsirhome/tmp-password-file =/tmp/rsync. secrets

Exit and save.

B> Create the rsync. secrets Password File

1 [root @ devel ~] # Vi rsync. secrets

Write: 123456

Exit save and modify permissions:

1 [root @ devel ~] # Chmod 600 rsync. secrets

C> Configure the cron Service

1 [root @ devel ~] # Crontab-e

Add a row: */1 *****/web/www/rsync. sh // exit and save every minute, rsync. sh files are stored in a safe place. Do not disclose the password.

After the configuration is complete, the master server/tmp directory will be updated to the slave server/tmp every minute.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.