Article Title: Set up an rsync server in linux. 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.
1. What is rsync?
Rsync, remote synchronize is a software that implements remote synchronization. It can keep the permissions, time, soft and hard links, and other additional information of the original file while Synchronizing files. Rsync uses the "rsync algorithm" to provide a fast way to synchronize files between clients and remote file servers. It can also transmit files through ssh, which ensures high confidentiality, in addition, it is free software.
Rsync includes the following features:
Update the entire directory and tree and file system;
Optional maintenance of symbolic chains, hard links, files belonging to, permissions, devices, and time;
No special permission requirements are required for installation;
For multiple files, the internal pipeline reduces the latency of file waiting;
You can use rsh, ssh, or direct port as the transfer port;
Supports anonymous rsync file synchronization and is an ideal image tool;
2. Set up an rsync server
Setting up an rsync server is relatively simple. Write a configuration file rsyncd. conf. There are also rules for writing files. We can refer to the documents on rsync.samba.org. Of course, we need to install the rsync software first;
A. Install rsync;
Obtain rsync
Rysnc Official Website: http://rsync.samba.org/you can get the latest version from above. The latest version is 3.05. Of course, because rsync is such a useful software, many Linux releases include it.
Software Package Installation
# Sudo apt-get install rsync Note: Online installation methods such as debian and ubuntu;
# Yum install rsync Note: Online installation methods such as Fedora and Redhat;
# Rpm-ivh rsync Note: Install rpm packages such as Fedora and Redhat;
For other Linux distributions, use the corresponding software package management method.
Source code package installation
Tar xvf rsync-xxx.tar.gz
Cd rsync-xxx
./Configure? Prefix =/usr; make install Note: Before compiling and installing with the source code package, you must install gcc and compile and issue it;
B. Configuration File
Rsync mainly includes the following three configuration files: rsyncd. conf (main configuration file), rsyncd. secrets (password file), rsyncd. motd (rysnc Server Information)
Server configuration file (/etc/rsyncd. conf). This file does not exist by default. Please create it.
The procedure is as follows:
# Touch/etc/rsyncd. conf # create rsyncd. conf, which is the configuration file of the rsync server.
# Touch/etc/rsyncd. secrets # create rsyncd. secrets, which is the user password file.
# Chmod 600/etc/rsyncd. secrets # Set the File Attribute of the rsyncd. secrets password file to root and set the permission to 600. Otherwise, the backup will fail!
# Touch/etc/rsyncd. motd
The next step is to modify the rsyncd. conf and rsyncd. secrets and rsyncd. motd files.
Set/etc/rsyncd. conf
Rsyncd. conf is the main configuration file of the rsync server. Let's take a simple example. The functions are described in detail later.
For example, if we want to back up/home And/opt on the server, I want to exclude the easylife and samba directories in/home;
# Distributed under the terms of the GNU General Public License v2
# Minimal configuration file for rsync daemon
# See rsync (1) and rsyncd. conf (5) man pages for help
# This line is required by the/etc/init. d/rsyncd script
Pid file =/var/run/rsyncd. pid
Port = 873
Address = 192.168.1.171
# Uid = nobody
# Gid = nobody
Uid = root
Gid = root
Use chroot = yes
Read only = yes
# Limit access to private LANs
Hosts allow = 192.168.1.0/255.255.255.0 10.0.1.0/255.255.255.0
Hosts deny = *
Max connections = 5
Motd file =/etc/rsyncd. motd
# This will give you a separate log file
# 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
[Rhel4home]
Path =/home
List = yes
Ignore errors
Auth users = root
Secrets file =/etc/rsyncd. secrets
Comment = This is RHEL 4 data
Exclude = easylife/samba/
[Rhel4opt]
Path =/opt
List = no
Ignore errors
Comment = This is RHEL 4 opt
Auth users = easylife
Secrets file =/etc/rsyncd. secrets
Note: auth users is a real system user that must exist on the server. If you want to separate multiple users with commas (,), for example, auth users = easylife, root