Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Rsync configuration

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

I. Introduction

rsync (remote synchronize) is a remote data synchronization tool that can quickly synchronize files between multiple hosts over LAN/WAN, or use Rsync to synchronize different directories on your local hard disk.

Rsync is a tool used to replace rcp. Rsync uses the so-called "Rsync algorithm" to synchronize files between local and remote hosts. This algorithm only transfers different parts of two files, rather than transferring them in whole at a time, so it is quite fast.

Advantages and disadvantages of rsync

Compared with traditional cp and tar backup methods, rsync has the advantages of high security, rapid backup and incremental backup. rsync can solve the data backup requirements with low real-time requirements.

For example, regularly backing up file server data to remote servers, regularly mirroring data to local disks, etc.

However, as the scale of the system continues to expand, the shortcomings of rsync are gradually exposed. First of all, when rsync does data synchronization, it needs to scan all files and compare them, and then carry out differential transmission.

If the file is large, scanning the file is very time consuming, and the file that changes is often a small part, so rsync is a very inefficient way.

Second, rsync cannot monitor and synchronize data in real time. Although it can trigger synchronization through the Linux daemon process, there must be a time difference between the two triggers.

May cause server and client data inconsistencies

Rsync supports most Unix-like systems and is well tested on Linux, Solaris, and BSD. In addition, it also has corresponding versions under the Windows platform, and the more well-known ones are cwRsync and Sync2NAS.

The basic features of rsync are as follows:

1. You can mirror entire directory trees and file systems;

2. It is easy to maintain the original file permissions, time, soft and hard links, etc.;

3. Installation without special permission;

4. Optimized process, high file transfer efficiency;

5. You can use rcp, ssh, etc. to transfer files, of course, you can also use a direct socket connection;

6. Anonymous transfers are supported to facilitate website mirroring.

When using rsync for remote synchronization, there are two ways:

1. Remote Shell mode (ssh recommended, user authentication by ssh)

2. C/S mode (i.e. client connects to remote rsync server, user authentication is the responsibility of rsync server).

rsync copies all files once the first time it runs, whether it synchronizes directories locally or remotely, and copies only the changed files (for new files) or changed parts of the files (for old files) on subsequent runs.

III. Installation and configuration

rsync is installed by default when installing the system

Check if rsync is installed

rpm -qa | grep rsync

manually install

Download address: rsync.samba.org/ftp/rsync/

#tar zxvf rsync-3.0.6.tar.gz

#cd rsync-3.0.6

#./ configure --prefix=/usr/local/rsync

#make

#make install

**** RH is installed normally with RSYNC, and the running file is placed in/usr/bin/rsync.

configured

1) Start rsync

vi /etc/xinetd.d/rsync

service rsync

{

disable = no #Set to no to start rsync

socket_type = stream

flags = IPv4

wait = no

user = root

server = /usr/bin/rsync

server_args = --daemon --config=/etc/rsyncd/rsyncd.conf

log_on_failure += USERID

}

Start rsync with the system

#chkconfig rsync on

[root@lone-centos67 ~]# cd /etc/

Create a directory of rsyncd related profiles

[root@lone-centos67 etc]# mkdir rsyncd

[root@lone-centos67 etc]# cd rsyncd

Manually create the rsyncd.conf configuration file

touch rsyncd.conf //Global parameters and module parameters

touch rsyncd.secrets //synchronize users and passwords non-system users

touch rsyncd.motd //Welcome content

2) Configure rsyncd.conf

[root@lone-centos67 rsyncd]# vi rsyncd.conf

# GLOBAL OPTIONS

uid = root //User running RSYNC daemon

gid = root //Group running RSYNC daemon

port = 873 //listening port

use chroot = no //no chroot

read only = no //not read-only

#limit access to private LANs

hosts allow = 192.168.169.0/24 hosts

#hosts deny = * //host denied

max connections = 5 //max connections = 5

id file = /var/run/rsyncd.pid file location

#lock file = /var/run/rsync.lock //lock file location

#motd file = /etc/rsyncd/rsyncd.motd

#This will give you a separate log file

log file = /var/log/rsync. log//log file location

#This will log every file transferred - up to 85,000+ per user, per sync

transfer logging = yes

log format = %t %a %m %f %b //log format

syslog facility = local3

timeout = 300 //timeout

# MODULE OPTIONS

[test] //module name

path = /var/www/html/test //path

list=yes

ignore errors

auth users = test

comment = test

exclude = important/

secrets file = /etc/rsyncd/rsyncd.secrets

3) Configure password file

#chown root.root rsync.pas

#chmod 600 rsync.secrets

[root@lone-centos67 rsyncd]# vi rsyncd.secrets

test: 11111//non-system username password

4) Configure welcome content

[root@lone-centos67 rsyncd]# vi rsyncd.motd

+++++++++++++++++++++++++++

+ welcome rsyn +

+++++++++++++++++++++++++++

5)Make Configuration Effective

#service xinetd restart

Start rsync server service

#/usr/bin/rsync -daemon

Add rc.local to enable rsync to start automatically when the system starts

Since rc files are stored in different locations on various operating systems, you can modify them to load rsync --daemon when the system boots.

#vi /etc/rc.local

Add the line/usr/bin/rsync --daemon.

rsync check

[root@lone-centos67 rsyncd]# netstat -a | grep rsync

tcp 0 0 *:rsync *:* LISTEN

client configuration

push

[root@lone-centos67 chenwx]# rsync -vzrtopg --progress --password-file=/etc/rsyncd/rsync.secrets /home/chenwx/* test@192.168.169.111::test

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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report