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

How to install rsync for Linux

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

Editor to share with you how to install the Linux version of rsync, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

Installation of rsync for Linux

2 Server installation steps

2.1 install Rsync

[root@localhost /] # cd / opt/install

[root@localhost install] # tar zxvf rsync-3.0.7.tar.gz

[root@localhost install] # cd rsync-3.0.7

[root@localhost rsync-3.0.7] #. / configure-prefix=/opt/software/rsync

[root@localhost rsync-3.0.7] # make

[root@localhost rsync-3.0.7] # make install

After the installation is complete, all the installed files are included in / opt/software/rsync

2.2 modify the configuration file

Add the conf directory to the / opt/software/rsync directory, and then add the rsyncd.conf file to this directory, as follows:

Uid = 0

Gid = 0

# listening port (default is 873, no need to modify it)

Port = 52326

# IP of clients allowed to connect

# hosts allow=192.168.0.0/24

# IP of clients denied access

# hosts deny=0.0.0.0/32

# do not use chroot

Use chroot=no

# the maximum number of connections is 100

Max connections=100

# Welcome information file name and location (this file is not available, you can add it yourself)

# motd file=/opt/software/rsync/conf/rsyncd.motd

# specify the pid file of rsync

Pid file=/var/run/rsyncd.pid

# specify the lock file that supports the max connections parameter. The default is / var/run/rsyncd.lock

Lock file=/var/run/rsync.lock

# specify the log file for rsync instead of sending the log to syslog

Log file=/var/log/rsyncd.log

# here is the configuration of each module that needs to be synchronized

# the name of the module that needs to be synchronized, which needs to be specified when the client synchronizes, and modified according to the actual need

[main]

# directories that need to be synchronized (modified according to the actual situation, here is just an example)

Path=/srv/www/app/cms/main

Comment=rsync files

# ignore extraneous IO errors

Ignore errors

# read only

Read only=yes

# column files are not allowed

List=no

# authenticated user name. If there is no such line, it is anonymous and separated by a user.

# auth users=thinkive

# authenticated user file name

Secrets file=/opt/software/rsync/conf/rsyncd.pas

# the name of the second module of synchronization, which needs to be specified when the client synchronizes, and can be modified according to the actual needs

[upload]

# directories that need to be synchronized (modified according to the actual situation, here is just an example)

Path=/srv/www/app/cms/upload

Comment=rsync files

# ignore extraneous IO errors

Ignore errors

# read only

Read only=yes

# column files are not allowed

List=no

# authenticated user name. If there is no such line, it is anonymous and separated by a user.

# auth users=thinkive

# authenticated user file name

Secrets file=/opt/software/rsync/conf/rsyncd.pas

2.3 configure password authentication file

Create a rsyncd.pas file in the / opt/software/rsync/conf directory

Then add the following to the file:

Thinkive:thinkive

2.4 start the server

[root@localhost /] # cd / opt/software/rsync/bin/

[root@localhost bin] # / rsync-- daemon-- config=/opt/software/rsync/conf/rsyncd.conf

[root@localhost bin] # ps-ef | grep rsync

Check whether the service has been started

Start as a server on port 52326 (default is port 873, if no profile path is specified, the default profile is read from / etc/rsyncd.conf)

If you want to start multiple synchronization service processes on a single machine, you can give different-- config-- port.

To start at random, you can add this code to / etc/rc.local

/ opt/software/rsync/bin/rsync-daemon-config=/opt/software/rsync/conf/rsyncd.conf

3 client installation steps

3.1 install Rsync

[root@localhost /] # cd / opt/install

[root@localhost install] # tar zxvf rsync-3.0.7.tar.gz

[root@localhost install] # cd rsync-3.0.7

[root@localhost rsync-3.0.7] #. / configure-prefix=/opt/software/rsync

[root@localhost rsync-3.0.7] # make

[root@localhost rsync-3.0.7] # make install

After the installation is complete, all the installed files are included in / opt/software/rsync

3.2 configure password authentication file

Create a password authentication file named / rsync.pas in the / opt directory (the password file path and file name can be modified by yourself), and then add the following user password to this file (which must be consistent with the user password configured on the server side):

Thinkive

Modify the permissions of the file

Chmod 600 rsync.pas

3.3 execute synchronization command

[root@localhost /] # cd / opt/software/rsync/bin

[root@localhost bin] # / rsync-vzrtopgu-- progress-- delete-- password-file=/opt/rsync.pas-- port=52326 thinkive@18.1.20.20::main / srv/www/app/webroot/main

[root@localhost bin] # / rsync-vzrtopgu-- progress-- delete-- password-file=/opt/rsync.pas-- port=52326 thinkive@18.1.20.20::upload / srv/www/app/webroot/upload

Detailed parameter description:

Z is compressed transmission

R is recursive synchronization

Topg is a parameter that keeps the original attributes of the file, such as owner and time.

U is to synchronize only updated files to avoid repeated updates without updating, but pay attention to the synchronization of the clocks of the two machines.

-progress means to show a detailed progress

-delete means that if the server deletes the file, the client deletes the file accordingly to maintain true consistency.

-- port specifies the port to access

In the following thinkive@192.168.1.108::data, the following data is the module name, which is the name customized in rsyncd.conf, and thinkive is the user name specified in the specified module that can be synchronized.

-password-file=/opt/rsync.pas specifies the password file so that it can be used in the script without having to enter the authentication password interactively. It is important to note that the permission attribute of this password file should be set to be readable only by the owner.

/ opt/install_bak is the name of the directory backed up to the local directory, which is filled in according to the specific requirements.

3.4 generate synchronized scripts

The script file location can be customized, which is assumed to be in / opt/rsync.sh

DATE= `date +% Y% m% d`

Cd / opt/software/rsync/bin

. / rsync-vzrtopgu-- progress-- delete-- password-file=/opt/rsync.pas-- port=52326 thinkive@18.1.20.20::main / srv/www/app/webroot/main > > / opt/software/rsync/log/rsync_main.$DATE.log

. / rsync-vzrtopgu-- progress-- delete-- password-file=/opt/rsync.pas-- port=52326 thinkive@18.1.20.20::upload / srv/www/app/webroot/upload > > / opt/software/rsync/log/rsync_upload.$DATE.log

It will generate a log every day.

Grant permissions to chmod 777 / opt/rsync.sh

3.5 add to the timer

Put

* / 1 * root / opt/rsync.sh

Add to / etc/crontab and restart crond using the following command

Service crond restart

The above scheduled task means that the data is synchronized incrementally every minute.

4 pay attention to the problem

The data synchronization software mainly synchronizes the data incrementally according to the time, so the time of the machine between the main server and the client must not be too far apart, otherwise the data may not be synchronized correctly.

5 detailed explanation of Rsync command parameters

Rsync is a very powerful tool, and its command also has many functional options. We will analyze and explain its options one by one below. Rsync commands can be in the following six formats:

Rsync [OPTION]... SRC DEST

Rsync [OPTION]... SRC [USER@] HOST:DEST

Rsync [OPTION]... [USER@] HOST:SRC DEST

Rsync [OPTION]... [USER@] HOST::SRC DEST

Rsync [OPTION]... SRC [USER@] HOST::DEST

Rsync [OPTION]... Rsync:// [USER@] HOST [: PORT] / SRC [DEST]

Rsync has six different modes of operation corresponding to the above six command formats:

1) copy the local file. This mode of operation is started when neither SRC nor DES path information contains a single colon: delimiter. For example: rsync-a / data / backup

2) use a remote shell program (such as rsh, ssh) to copy the contents of the local machine to the remote machine. Start this mode when the DST path address contains a single colon ":" separator. Such as: rsync-avz * .c foo:src

3) use a remote shell program (such as rsh, ssh) to copy the contents of the remote machine to the local machine. Start this mode when the SRC address path contains a single colon ":" separator. For example: rsync-avz foo:src/bar / data

4) copy files from the remote rsync server to the local machine. This mode is started when the SRC path information contains the "::" delimiter. For example: rsync-av root@172.16.78.192::www / databack

5) copy files from the local machine to the remote rsync server. This mode is started when the DST path information contains the "::" delimiter. For example: rsync-av / databack root@172.16.78.192::www

6) list the files of the remote machine. This is similar to rsync transport, except that the local machine information is omitted from the command. Such as: rsync-v rsync://172.16.78.192/www

The rsync parameter is explained as follows:

-v,-- verbose verbose mode output

-Q,-- quiet compact output mode

-c,-- checksum turns on the check switch to force the file transfer to be checked

-a,-- archive archiving mode, which means that files are transferred recursively and all file attributes are maintained, which is equal to-rlptgoD

-r,-- recursive processes subdirectories in recursive mode

-R,-- relative uses relative path information

-b,-- backup creates a backup, that is, rename the old file to ~ filename when the same file name already exists for the destination. You can use the-- suffix option to specify different backup file prefixes.

-- backup-dir stores backup files (such as ~ filename) in a directory.

-suffix=SUFFIX defines the backup file prefix

-u,-- update only updates, that is, skips all files that already exist in DST and the file time is later than the file to be backed up. (do not overwrite updated files)

-l,-- links retains soft links

-L,-- copy-links handles soft links like regular files

-- copy-unsafe-links only copies links that point outside the SRC path directory tree

-- safe-links ignores links that point outside the SRC path directory tree

-H,-- hard-links keeps the hard link-p,-- perms maintains file permissions

-o,-- owner keeps file ownership information-g,-- group keeps file group information

-D,-- devices keep device file information-- t,-- times keep file time information

-S,-- sparse performs special processing on sparse files to save DST space

-n,-- dry-run reality which files will be transferred

-W,-- whole-file copies files without incremental detection

-x,-- one-file-system do not cross file system boundaries

-B,-- the block size used by the block-size=SIZE check algorithm. The default is 700byte.

-e,-- rsh=COMMAND specifies to use rsh and ssh methods for data synchronization

-- rsync-path=PATH specifies the path information where the rsync command is located on the remote server

-C,-- cvs-exclude automatically ignores files using the same method as CVS to exclude files that you don't want to transfer

-- existing updates only those files that already exist in DST, not those newly created files

-- delete deletes files in DST that are not available in SRC

-- delete-excluded also deletes files on the receiver that are specified and excluded by this option

-- delete delete-after after the transfer is finished.

Delete ignore-errors even if there are IO errors.

-- max-delete=NUM deletes a maximum of NUM files

-- partial retains files that were not fully transferred for some reason, thus speeding up subsequent retransfers

-- force forces directory deletion, even if it is not empty

-- numeric-ids does not match numeric user and group ID to username and group name

-- timeout=TIME IP timeout in seconds

-I,-- ignore-times does not skip files of the same time and length

-- size-only when deciding whether to back up a file, only look at the file size without considering the file time

-- the timestamp window used by modify-window=NUM to determine whether the file is at the same time. The default is 0.

-T-- temp-dir=DIR creates temporary files in DIR

-- compare-dest=DIR also compares files in DIR to decide whether a backup is needed

-P equals-- partial

-- progress shows the backup process

-z,-- compress compresses the backed-up files during transfer

-- exclude=PATTERN specifies to exclude files that do not need to be transferred

-- include=PATTERN specifies the file mode that needs to be transferred without exclusion

-- exclude-from=FILE excludes files of the specified pattern in FILE

-- include-from=FILE does not exclude files specified by FILE for pattern matching

-- version print version information

-- address is bound to a specific address

-- config=FILE specifies other configuration files and does not use the default rsyncd.conf file

-- port=PORT specifies other rsync service ports

-- blocking-io uses blocking IO for remote shell

-stats gives the transfer status of some files

-- the actual transmission process of progress during transmission

-- log-format=formAT specifies the log file format

-- password-file=FILE gets the password from FILE

-- bwlimit=KBPS limits the bandwidth of KBytes per second O, KBytes per second-h,-- help displays help information

The above is all the contents of the article "how to install rsync for Linux". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

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