Linux rsync Installation Configuration example detailed _linux shell

Source: Internet
Author: User
Tags auth chmod set time time and date ssh file permissions iptables rsync

Install rsync in Redhat

1, first on the server and the client are installed rsync, my RHEL5 by default has been installed. When installing REDHAT5, you can see it in the "basic system" in software Customization-"basic" optional packages: rsync-2.6.8 is installed by default

2, can also be checked through the command line is installed:

Or: Rpm–q rsync

3, if you start installing Redhat, use the default choice of RYSNC software, but now want to use a newer version of rsync, you can uninstall the RYSNC, and then install a later version of the software:

4, uninstall the 2.6.8 version of the RYSNC, the following to install a later version of Rsync (3.0.9):



Configuring the Rsync server Side

5. Modify the configuration file for rsync

You can see that the RYSNC service is turned off (disable = yes), open it here and change the disable value to No

6. Create rsync server configuration file/etc/rsyncd.conf

[Root@hyj etc]# vim/etc/rsyncd.conf
uid = root
gid = root Port
  = 873                #    Specifies the running port, the default is 873, you can specify
it yourself Hosts allow = 192.168.0.204, 192.168.1.205     # Allow access to client
#hosts deny = 0.0.0.0/32           #拒绝访问的 use
chroot = 
max connections = 
timeout=

# # These green files are files that are automatically generated after you install the Rsync service, and of course you can manually configure to the specified path

pid file =/var/run/ Rsyncd.pid   # #pid文件的存放
lock file =/var/run/rsync.lock   # #锁文件的存放位置
log file =/var/log/rsyncd.log   # #日志记录文件的存放
#motd file =/etc/rsyncd.motd   #欢迎
# # above This section is global configuration, the following module can have
  [test]          # # module name, Name
  Path =/home/hyj/workspace/test        #指定文件目录所在位置, which is required to specify 
  comment = rsync files             # # comments
Ignore Errors                 # #忽略IO
Read Only = yes 
  list = no                   # # Whether the directory that provides synchronized data on the rsync server is displayed in the
  following line, the account used to synchronize the verification, If this is not an anonymous synchronization, client synchronization can be synchronized without the user name.
  Auth users = rsync
Secrets file =/etc/rsync.passwd       # Specify authentication files

7, and then create the certification file:

[Root@hyj etc]# vim/etc/rsync.passwd
Rsync:hyl # Username: password. Note that this is not a system user, but an rsync user.

So don't useradd.

(name casually written, as long as the "auth users" parameter in the top configuration file), format (one user on a line)

Account Number: Password

(2), change the password file permissions to 600

[Root@hyj etc]# chmod 600/etc/rsync.passwd # can only be read by owner, otherwise the error

8, if you specify the welcome information in the configuration file, create the RSYNCD.MOTD under/etc, and set the Welcome information:

[Root@hyj etc]# VIM/ETC/RSYNCD.MOTD
Welcome the rsync services!

Start Rsyn

9, before starting, you can first look at Rsync has started running: lsof or nestat can be


Displays the state as listen, indicating that the status is waiting for the link to be accepted, indicating that Rsync has started.

Now kill the rsync process, before killing for the previous figure, after the kill, execute Netstat–anp|grep 873 or lsof–i:873 again, the result is null:


10, Firewall settings:

If a firewall is installed on the server, set the iptables on the server to open the 837 port.

[Root@hyj ~]# iptables-a input-p tcp--dport 873-j ACCEPT

11. If the rsync process is not running, start rsync on the server side:

(1), Start rsync service side (in the form of daemon, independent boot)

#/usr/bin/rsync–daemon

The description starts successfully.

(Remember: The end of the command line startup is daemon, not deamon, otherwise the following error is returned:

Rsync:--deamon:unknown option

Rsync Error:syntax or usage error (code 1) at MAIN.C (1231) [client=2.6.8])

(2), Start rsync service side (with XINETD super process boot)

#/etc/rc.d/init.d/xinetd Reload (Reload is the online version, but I tried to make an error, start can)
Or:/etc/rc.d/init.d/xinetd Reload (Reload is an online statement, but I tried to error, start can)

Demonstrate:

12, set the automatic start:

Redhat in the local installation of Rsync is already started automatically, the two methods on the Web, the configuration file did not find the appropriate configuration, by using the Chkconfig command to view and modify the boot service.
[Root@hyj ~]# Chkconfig

(The result is partially omitted) to see that rsync is on.

Configuring the Rsync Client

13, install the server side of the way to install rsync.

14, start rsync, if reported as the following error, because in etc, there is no rsyncd.conf configuration file:


15, [Root@hyj etc]# vi/etc/rsyncd.conf

The contents of the file are empty. Then start rsync, and you can start:

Commands and instances

16, rsync command format can be the following six kinds:

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::D EST
rsync [OPTION] ... rsync://[user@]host[:P ort]/src [DEST]

17, commonly used for the following two kinds:

(4), rsync [OPTION] ... [user@] HOST::SRC DEST

Copy files to the local machine from a remote rsync server. This mode is started when the SRC path information contains the "::" delimiter.

such as: Rsync-av Root@172.16.78.192::www/databack

(5), rsync [OPTION] ... SRC [user@]host::D EST

Copy files from the local machine to the remote rsync server. This mode is started when the DST path information contains the "::" separator.

such as: Rsync-av/databack root@172.16.78.192::www

18, the following is an example:

Server IP is 192.168.8.126, client IP is 192.168.8.122

19, (1), the contents of the/home/hyj/workspace/test folder on the server back to the client/usr/local/share/rsync_backup:
[Root@hyj ~]#/usr/bin/rsync-vzrtopg--delete--progress rsync@192.168.8.126::test/usr/local/share/rsync_backup

Contents of modules in/etc/rsyncd.conf:

Path =/home/hyj/workspace/test
comment = rsync files
Ignore errors
Read Only = yes
list = no
auth use rs = rsync
Secrets file =/etc/rsync.passwd

The above command line in-VZRTOPG V is verbose,z is compressed, R is RECURSIVE,TOPG is to maintain the original attributes of the file such as the owner, time parameters (can also be used directly with a to replace the RTOPG, a for the--archive archive mode, Represents a recursive transfer of a file and maintains all file attributes, equal to-rlptgod. --progress is the display of detailed progress,--delete means that if the server side to delete the file, then the client also deleted the file, to maintain true consistency.

(2), the above command needs to be in the back of the time required to enter a password, you can create a password file in the command, the password file as a parameter into:

[Root@hyj rsync_backup]# Vim/etc/rsync.pass
You do not need to enter a username in the password file, just enter the password:

This password file permission attribute must be set to only root readable, or it will error, modify attributes:

[Root@hyj rsync_backup]# chmod 600/etc/rsync.pass,

Use the following command to not enter a password:

    /USR/BIN/RSYNC-VZRTOPG--delete--progress rsync@192.168.8.126::test/usr/local/share/rsync_backup--password-file= /etc/rsync.pass

20, with exclude parameters:

Backs up the contents of the/home/hyj/workspace/test folder on the server to the client's/usr/local/share/rsync_backup, but does not include the Res directory and default.properties files:

/USR/BIN/RSYNC-VZRTOPG--delete--exclude "res/"--exclude "default.properties"--progress rsync@192.168.8.126::test/ Usr/local/share/rsync_backup--password-file=/etc/rsync.pass

Exclude/include Rule Instance

Here are some exclude/include examples:--exclude "*.O" would exclude the all filenames matching *.o--exclude
 "/ Foo ' would exclude a file in the base directory called Foo
 --exclude ' foo/' would exclude any directory called />--exclude "/foobar" would exclude any file called Bar two or more levels below a base directory called Foo.
 --include "* *"--include "*.c"--exclude "*" would include all directories and C source files
--include "foo/"--inclu De "foo/bar.c"--exclude "*" would include only foo/bar.c
 (the foo/directory must is explicitly included or it would is excluded by the "*")

21. Back up the contents of the/home/hyj/vitest folder on the client to the/usr/local/share/rsync_backup of the server, execute the following command on the client:

  /USR/BIN/RSYNC-VZRTOPG--delete--progress/home/hyj/vitest Rsync@192.168.8.126::clientdata--password-file=/etc/ Rsync.pass

At this point, the server's configuration file/etc/rsyncd.conf content is:

 UID = root
gid = root
allow = 192.168.8.122, 192.168.8.123
   #hosts deny = 0.0.0.0/32 use
   chroot = no< C5/>max connections = Ten
   pid file =/var/run/rsyncd.pid
   lock file =/var/run/rsync.lock
   log file =/var/log/rs Yncd.log
   timeout=600
[test]
path =/home/hyj/workspace/test
   comment = rsync files
   Ignore Errors
   Read Only = yes
   list = no
   auth users = rsync
   Secrets file =/etc/rsync.passwd
 # in the command above, the client Data backup to the Clientdata module, backed up to the/usr/local/share/rsync_backup folder, read only to no,# # otherwise it will report Error:module is read only error
[ Clientdata]     
path =/usr/local/share/rsync_backup
comment = rsync files
   Ignore errors
   Read Only = no
   list = no
auth users = rsync
   Secrets file =/etc/rsync.passwd

Scheduled scheduled backups

22, if the implementation of the crontab command prompt:

The description has not yet provided crontab for root account. Execute crontab–e to create a crontab:


23, edit crontab, backup every two minutes:

24, two minutes later, view, data has been backed up:

25. Perform RYSNC backup tasks 9 o'clock in the morning 20 every day:

9 * * * */USR/BIN/RSYNC-VZRTOPG--delete--progress rsync@192.168.8.126::test/usr/local/share/rsync_backup--pa Ssword-file=/etc/rsync.pass

26, with TIME settings:

(1), view the current time zone: Date-r
(2), view time and date: date
(3), set time and date:
Set the system date to the August 4, 2012 command: Date-s 08/04/2012
Set the system time to 9:20 P.M. 0 seconds command: date-s 09:20:00
(4), the current time and date written to the BIOS, to avoid restart after failure: hwclock-w

FAQ

27. What ports do I need to open on a fireproof wall to adapt to rsync?

A: Depending on the situation

Rsync can transfer files directly through a TCP connection on port 873, or through 22-port SSH for file delivery, but you can also change its port via the following command:

Rsync--port 8730 otherhost::

Or

Rsync-e ' Ssh-p 2002 ' Otherhost:

28. How do I replicate directory structure through rsync, ignoring files?

A:rsync-av--include ' * * *--exclude ' * ' Source-dir dest-dir

Common errors

29, rsync:failed to connect to 218.107.243.2:no route to host (113)

Rsync error:error in Socket IO (code ten) at CLIENTSERVER.C [receiver=2.6.9]

Solution: The other side did not boot, firewall block, through the network firewall blocked, it is possible. Shutting down the firewall is actually opening the TCP UDP port 873:

WORKAROUND: Open the server 873 port (Rh-firewall-1-input is Rehl 5 with its own chain name, 10 is the last default rule (rejected), modify these two parameters according to the actual situation. In addition, the "-M state--state new-m TCP" parameter is not added.

#iptables-I rh-firewall-1-input 10-p tcp-m State--state new-m TCP--dport 873-j ACCEPT
#iptables-I rh-firewall-1-input 10-p udp-m State--state new-m UDP--dport 873-j

Iptables configuration prior to opening ports:

Note: The last rule (REJECT all--anywhere anywhere reject-with icmp-host-prohibited) indicates that all packets are rejected and the icmp-host-prohibited packets are responded to.

The method passed by the native test opens the server 873 port:

(1), [Root@duoduo ~]# iptables-i input-p TCP--dport 873-j
[Root@duoduo ~]# iptables-i input-p UDP--dport 873-j

(Note to use-I, and can not use-a, with a will add this rule to the end of the iptables chain, but not to this rule is the original last reject, the client can not perform RYSNC backup, with I will be inserted to the front of the chain, The RYSNC backup can be performed properly after testing. In addition, the "-M state--state new-m TCP" parameter can be added.

(2), as mentioned above, insert the rule to the front of the last line:

#iptables-I rh-firewall-1-input 10-p tcp-m State--state new-m TCP--dport 873-j ACCEPT
#iptables-I rh-firewall-1-input 10-p udp-m State--state new-m UDP--dport 873-j

Before inserting:

Insert rule:



After inserting the rule:


On the client side, it can be performed normally.

(3), or shut down the server Iptables:service iptables stop

30. password file must not is other-accessible

Continuing without password file

Password:

Workaround: This is because the Rsyncd.pwd rsyncd.sec permissions are not correct and should be set to 600. such as: chmod rsyncd.pwd

31. @ERROR: Auth failed on module xxxxx

Rsync:connection unexpectedly closed (bytes read so far)
Rsync Error:error in Rsync protocol The data Stream (code) at IO.C (150)

Resolution: This is because the password is set incorrectly, can not login successfully, check the RSYNC.PWD, whether the spectator suit matches. This is also the case with the server-side failure to start the rsync service.

32, @ERROR: Chroot failed

Rsync:connection unexpectedly closed (bytes read so far)
Rsync Error:error in Rsync protocol The data Stream (code) at IO.C (150)

Workaround: This is because the path path you set in rsync.conf does not exist and you want to create a new directory to open synchronization.

33, [Root@hyj rsync_backup]#/usr/bin/rsync-vzrtopg--delete--exclude "res/"--exclude "Default.properties"--progress Rsync@192.168.8.126::test/usr/local/share/rsync_backup--password-file=/etc/rsync.pass
@ERROR: ChDir failed
Rsync Error:error starting Client-server Protocol (code 5) at MAIN.C (1516) [receiver=3.0.9]

Reasons and Solutions:

SELinux (The following command executes on the server side)
Setsebool-p Rsync_disable_trans on

34. Error:module is read only
Rsync:read Error:software caused connection abort (113)
Rsync Error:error in Rsync protocol The data Stream (code) at IO.C (769) [sender=3.0.8]

Workaround: This is because the server-side configuration file rsyncd.conf Read Only = yes, for reading only, that is, do not allow the client to upload files, change to No on it.

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.