Linuxrsync server file synchronization

Source: Internet
Author: User
Tags rsync

[Root @ zqtsx] # rpm-qa | grep rsync # Check whether the rsync package is installed in the system
Rsync-2.6.8-3.1
[Root @ zqtsx] # rpm-ivh rsync-2.6.8-3.1.i386.rpm # Install Manually If Not Installed

Or install

Yum install rsync for installation (the required software rsync will be compiled by default during system compilation)

[Root @ test zqtsx] # vim/etc/xinetd. d/rsync

1 configure rsync servervi/etc/xinetd. d/rsync

Vim/etc/xinetd. d/rsync

Change disable = yes to no


Service rsync
{
Disable = no
Socket_type = stream
Wait = no
User = root
Server =/usr/bin/rsync
Server_args = -- daemon
Log_on_failure + = USERID
}

2 configure rsync to start automatically
[Root @ zqtsx etc] # chkconfig rsync on
[Root @ zqtsx etc] # chkconfig rsync -- list
Rsync on

3. Configure rsyncd. conf
[Root @ test etc] # vim/etc/rsyncd. conf (this file does not exist by default. If it does not exist, manually add it)

Uid = zqtsx (sync authorized login user account)
Gid = zqtsx (sync authorized logon to the Working Group of the user account)
Use chroot = no
Max connections = 4 (max connections)
Strict modes = yes
Port = 873 (rsync logon link port)
Pid file =/var/run/rsyncd. pid (pid Startup file Storage path, which is omitted due to the following explanation)
Lock file =/var/run/rsync. lock
Log file =/var/log/rsyncd. log (sync log storage directory)

[Backup] (the backup module can be freely named, but it must be the same as the following login module)
Path =/home/var/www (the directory for Synchronizing files on the server)
Comment = This is test
Auth users = zqtsx (rsync authorizes automatic logon to account zqtsx, please leave the uid = uid value in zqtsx below to be consistent)
Uid = zqtsx
Gid = zqtsx
Secrets file =/home/rsync. ps (rsync account password stores the file path. The file Password format is username: pwd. Use line breaks to separate multiple accounts)
Read only = no
List = no

4. Make sure that the rsync port number in etc/services is correct.
[Root @ zqtsx etc] # vim/etc/services
Rsync 873/tcp # rsync (the 873 port number must be the same as the above port = 873 port number; otherwise, a permission error will be reported or you cannot connect to rsync)
Rsync 873/udp # rsync

5. Configure the rsync password (the path has been written in the preceding configuration file)/home/rsync. ps (name can be written at will, as long as it is consistent with the above configuration file, be sure not to have extra spaces or blank lines, otherwise there will be an account password verification error), format (one row per user)
[Root @ zqtsx etc] # vi/home/rsync. ps
Zqtsx: zqtsxpwd

6. Configure rsync Password File Permissions
[Root @ zqtsx home] # chown root. root rsync. ps (during the security period, the password file belongs to the root account, because we are in the zqtsx account group)
[Root @ zqtsx home] # chmod 400 rsync. ps (add permission settings during security)

7 STARTUP configuration
[Root @ zqtsx home] #/etc/init. d/xinetd restart
Stopping xinetd: [OK]
Starting xinetd: [OK]

8. If xinetd does not exist, install it.
[Root @ zqtsx home] # yum-y install xinetd

Start rsync server
Two Methods for RSYNC server startup
9. Start the rsync server (independently started)

[Root @ zqtsx home] #/Usr/bin/rsync -- daemon

Note: add the path of the configuration file for the first startup:

[Root @ zqtsx home] #/usr/bin/rsync -- daemon -- config =/etc/rsyncd. conf &

Or you can start it as follows:

[Root @ zqtsx home] # rsync -- daemon -- config =/etc/rsyncd. conf &

[5] 9182 (the startup is successful if this line is similar)
[4] Done/usr/bin/rsync -- daemon -- config =/etc/rsyncd. conf)

Run the command to check whether rsync is successfully started.

[Root @ zqtsx home] # ps auxf | grep 'rsync'

If the following information is displayed, the startup is successful (especially in the second line, the first line can only prove that rsync is successfully installed. It does not mean that the configuration file has been successfully loaded and started, the second line of information must appear before it can be used properly)
Root 9185 0.0 0.0 103252 864 pts/0 S + \ _ grep rsync
Root 8137 0.0 0.0 107620 668? Ss rsync -- daemon -- config =/etc/rsyncd. conf

To disable rsync, run the ps auxf | grep 'rsync' command to check the running process Number of rsync and then run "kill-9 8137" (8137 is the rsync process number, restart again and use the old method to start it.

10. Start the rsync server (xinetd superprocess started)
[Root @ test home] #/etc/init. d/xinetd reload

11 add rc. local
In various operating systems, rc files are stored in different locations and can be modified so that rsync-daemon can be loaded during system startup.
[Root @ test home] # vi/etc/rc. local
/Usr/bin/rsync -- daemon # Add a row

12. Check whether rsync is enabled.
[Root @ zqtsx home] # lsof-I: 873
COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME

Xinetd 4396 root 5u IPv4 633387 TCP *: rsync (LISTEN)

Client Configuration
1. Configure three processes.
1.1 SET Password File
1.2 test the rsync execution command
1.3 put the rsync command into the Job Schedule (crontab)
[Root @ zqtsxkhd home] # vi/etc/xinetd. d/rsync

# Default: off
# Description: The rsync server is a good addition to an ftp server, as it \
# Allows crc checksumming etc.
Service rsync
{
Disable = yes
Socket_type = stream
Wait = no
User = root
Server =/usr/bin/rsync
Server_args = -- daemon
Log_on_failure + = USERID
}

1.1 configure the password file (NOTE: For security purposes, set the attribute of the password file to 600. /Home/rsync. ps password must be the same as the password in Rsync Server password setting)

/Home/rsync. the password in ps must be the same as the password in the rsyns account on the server, that is, the password in the zqtsx account on the server. Note that the password is written here. No account is written and no additional line breaks or spaces are allowed.

[Root @ zqtsxkhd home] # vi/home/rsync. ps
Zqtsxpwd
[Root @ zqtsxkhd home] # chown root. root. rsync. ps # grant permissions
[Root @ zqtsxkhd home] # chmod 600. rsync. ps # The permission must be modified.

1.2 download files from the server (download the specified file directory from the backup module to the local/home Directory)
[Root @ zqtsxkhd rsync-3.0.4] # rsync-avz -- password-file =/home/rsync. ps zqtsx@192.168.0.206: backup/home/

Upload from local to server

Rsync-avz -- password-file =/home/rsync. ps local upload directory rsync account @ Server IP Address: rsync synchronization configuration module name (I .e./etc/rsync. name the backup module in the module [backup] "[]" in the conf file

[Root @ zqtsxkhd rsync-3.0.4] # rsync-avz -- password-file =/home/rsync. ps/var/www zqtsx@192.168.0.206: backup (example: Upload the local/var/www directory to the directory specified by the backup module on the server)

Related Article

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.