First, download, install rsync
Normal when the RH is installed with rsync, run files on the/usr/bin/rsync
#tar ZXVF rsync-2.6.9.tar.gz
#cd rsync-2.6.9
#./configure--prefix=/usr/local/rsync
#make
#make Install
Second, configure Rsync server
1. Start rsync
#vi/etc/xinetd.d/rsync
Change disable's original 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
}
Start rsync with System
#chkconfig rsync on
2. Configure/etc/rsyncd.conf (manual generation required)
Rsyncd.conf's parameter is written on the top of the global parameter and is written in the module is the module parameter
#vi/etc/rsyncd.conf
Global parameters
UID = root #运行RSYNC守护进程的用户
GID = root #运行RSYNC守护进程的组
Use chroot = no #不使用chroot
Max connections = 4 # Maximum number of connections is 4
Strict modes =yes #是否检查口令文件的权限
Port = 873 #默认端口873
Module parameters
[Backup] #这里是认证的模块名, the client side needs to specify
Path =/home/backup/#需要做镜像的目录, indispensable.
Comment = This is a test #这个模块的注释信息
Ignore Errors #可以忽略一些无关的IO错误
Read Only = yes # reading only
List = no #不允许列文件
Auth users = hening #认证的用户名, if this line does not indicate anonymity, this user is not related to the system
Secrets file =/etc/rsyncd.pw #密码和用户名对比表, password files are generated themselves
Hosts allow = 192.168.1.1,10.10.10.10 #允许主机
Hosts deny = 0.0.0.0/0 #禁止主机
#transfer logging = yes
Note: The following green files are files that are automatically generated after you install the Rsync service
PID file =/var/run/rsyncd.pid #pid文件的存放位置
Lock file =/var/run/rsyncd.lock #锁文件的存放位置
Log file =/var/log/rsyncd.log #日志记录文件的存放位置
============== instance ====================
UID = nobody
GID = Nobody
Use chroot = no
Max connections = 4
stirict modes = yes
Port = 873
PID file =/var/run/rsyncd.pid
Lock file =/var/run/rsyncd.lock
Log file =/var/log/rsyncd.log
[HTML]
Path =/home/html/
Comment = This is a HTML
Ignore errors
Read Only = no
List = no
Hosts allow = 192.168.152.155,10.10.10.10
Hosts Deny = 0.0.0.0/0
Auth users = Devilzy
Secrets File =/etc/rsyncd.pw
[Index]
Path =/home/index/
Comment = This is a index
Ignore errors
Read Only = no
List = no
Hosts allow = 192.168.152.155
Hosts Deny = 0.0.0.0/0
Auth users = Devilzy
Secrets File =/etc/rsyncd.pw
============== instance ====================
3, configure the rsync password (in the top of the configuration file has been written in the path)/ETC/RSYNCD.PW (name casually write, as long as the same as the above configuration file), format (a line of users)
Account Number: Password
#vi/ETC/RSYNCD.PW
Example:
hening:111111
Permissions: Because RSYNCD.PW stores the user name and password for the rsync service, it is important. To set the RSYNCD.PW to root, and the permission is 600.
#cd/etc
#chown Root.root RSYNCD.PW
#chmod RSYNCD.PW
3.RSYNCD.MOTD (Configuration welcome information, optional)
# VI/ETC/RSYNCD.MOTD
RSYNCD.MOTD records the welcome information for the Rsync service, where you can enter any textual information, such as:
Welcome to use the rsync services!
4, let the configuration effective
#service xinetd Restart
=============== problems occur ================================
1.xinetd:unrecognized Service
Perform the following actions:
Yum-y Install xinetd
=============== problems occur ================================
Third, start rsync server
Two ways to start an rsync server
1, start rsync Server (Independent launch)
#/usr/bin/rsync--daemon
2, Start rsync server (with XINETD super process startup)
#/etc/rc.d/init.d/xinetd Reload
3. Restart method: Kill-9 rsync
Four: Join rc.local
In various operating systems, RC file storage location is not the same, you can modify the system to start when the rsync--daemon loaded in.
#vi/etc/rc.local
Join a line/usr/bin/rsync--daemon
Five Check rsync
#netstat-A | grep rsync
TCP 0 0 0.0.0.0:873 0.0.0.0:* LISTEN
Six, open the port iptables
Iptables-a input-p tcp-s! 192.168.152.155--dport 873-j DROP
So, only 11.22.33.44 this client IP can access this rsync server.
Seven Configure Rsync Client
1, set the password
#vi/ETC/RSYNCD.PW
111111
Modify Permissions
#cd/etc
#chown Root.root RSYNCD.PW
#chmod RSYNCD.PW
2. Client Connection Server
Fetching files from the server
/USR/BIN/RSYNC-VZRTOPG--progress--delete Devilzy@192.168.152.154::index/home/index--password-file=/etc/ Rsyncd.pw
/USR/BIN/RSYNC-VZRTOPG--progress--delete devilzy@192.168.152.154::html/home/html--PASSWORD-FILE=/ETC/RSYNCD.PW
Uploading files to the server side
/USR/BIN/RSYNC-VZRTOPG--progress--password-file=/root/rsyncd.pw/home/index Devilzy@192.168.152.154::index
/USR/BIN/RSYNC-VZRTOPG--progress--password-file=/root/rsyncd.pw/home/html devilzy@192.168.152.154::html
This command backs up all files (including subdirectories) in the local machine/home/backup directory to the set backup directory of the backup module of the rsync SERVER (172.20.0.6).
Note that if the path ends with a "/", it means that the contents of the directory are backed up, but the directory is not created, such as without "/".
Rsync usage:
rsync [OPTION] ... [user@] HOST::SRC [DEST] #从RSYNC server backup files to local machine
rsync [OPTION] ... src [src] ... [user@] HOST::D est #从本地机器备份文件到RSYNC SERVER
3. Automatic operation
1) vi/usr/local/rsync/time.sh//Making script files
Copy the contents below.
#!/bin/bash
/USR/BIN/RSYNC-VZRTOPG--progress--delete Devilzy@192.168.152.154::index/home/index--password-file=/etc/ Rsyncd.pw
/USR/BIN/RSYNC-VZRTOPG--progress--delete devilzy@192.168.152.154::html/home/html--PASSWORD-FILE=/ETC/RSYNCD.PW
#chmod +x/usr/local/rsync/time.sh
2) crontab-e
Join * * * * * * * */usr/local/rsync/time.sh///Every minute of time.sh script file
Join the * * * * * * * * * * */usr/local/rsync/time.sh/////time.sh script file (run once every one hours) every 55 minutes of an hour
Command introduction:-rvlhpogdts
rsync command Parameters
-V indicates verbose detail display
-Z indicates compression
-R indicates recursive recursion
-T indicates keeping the original file creation time
-O indicates retention of original file owner
-P indicates keeping parameters of the original file
-G to maintain the group that the original file belongs to
-A archive mode
-P represents an option feature that replaces-partial and-progress
-e SSH establishes an encrypted connection.
--partial prevents rsync from deleting the copied portion of a transmission outage (if the transfer is interrupted during the copying of the file, the default action for Rsync is to undo the previous action, that is, from the target
Deletes part of a file that has been copied. )
--progress means showing detailed progress.
--delete means that if the server side deletes this file, then the client also deletes the file accordingly, maintaining true consistency.
--exclude does not contain/ins directory
--size-only This parameter is used in two folders only if there are some new files in the source folder, there are no duplicate files and have been modified, because the file may be skipped because the content is modified to the same size. This parameter can greatly improve the efficiency of synchronization because it does not need to check that the contents of the file with the same name are the same.
--password-file to specify a password file that contains the password for the server-side specified authenticated user.
This allows you to use it in a script without having to enter the authentication password interactively, but note that this password file permission attribute must be set to only the master readable.
Hening@192.168.0.217::backup
Hening refers to the server-side designated authenticated user
192.168.0.217 refers to the server-side IP
:: Backup indicates the name of the module on the server side that needs to be synchronized;
/home/quack/backup/$DATE is the synchronized file refers to the directory address that is stored on this computer.
/var/log/rsync. $DATE is the directory address that is stored on the local computer after the synchronized log file.
Attention
Do not put/then the directory name also contains mirror, put/then only the contents of the things mirror
Example Summary process:
1. Configure the main control side
# vim/etc/rsyncd.conf
###################################
UID = nobody
GID = Nobody
Use chroot = no
Max connections = 4
stirict modes = yes
Port = 873
[HTML]
Path =/home/html
Comment = This is a HTML
Ignore errors
Read Only = False
List = no
Hosts allow = 192.168.152.*
Hosts Deny = 0.0.0.0/0
Auth users = Devilzy
Secrets File =/etc/rsyncd.pw
PID file =/var/run/rsyncd.pid
Lock file =/var/run/rsyncd.lock
Log file =/var/log/rsyncd.log
[Index]
Path =/home/index
Comment = This is a index
Ignore errors
Read Only = False
List = no
Hosts allow = 192.168.152.*
Hosts Deny = 0.0.0.0/0
Auth users = Devilzy
Secrets File =/etc/rsyncd.pw
PID file =/var/run/rsyncd.pid
Lock file =/var/run/rsyncd.lock
Log file =/var/log/rsyncd.log
###################################
# VIM/ETC/RSYNCD.PW
###################################
devilzy:123456
###################################
# CD/ETC
# chown Root.root RSYNCD.PW
# chmod RSYNCD.PW
Start Rsync Server
# rsync--daemon
See if Port 873 is open
Join start
# echo "Rsync--daemon" >>/etc/rc.local
Write permissions to the/usr/local/test directory
# Chown-r Nobody.nobody/usr/local/test
# Chmod-r 770/usr/local/test
Master configuration Complete
2. Client Configuration
# VIM/ETC/RSYNCD.PW
####################################
123456
####################################
# chown ROOT.ROOT/ETC/RSYNCD.PW
# chmod 600/ETC/RSYNCD.PW
Using the command to update to the server data file directly does not require a password
/USR/BIN/RSYNC-VZRTOPG--progress--password-file=/root/rsyncd.pw/home/index Devilzy@192.168.152.154::index
/USR/BIN/RSYNC-VZRTOPG--progress--password-file=/root/rsyncd.pw/home/html devilzy@192.168.152.154::html
Attention:
1. Here the index name for the main control conf configuration inside [index], must have the same name
2.devilzy Devilzy in the main control conf configuration, can be arbitrarily named, not the system user
================== encountered problems and solutions ========================================
1. @ERROR: ChDir failed
Rsync Error:error starting Client-server Protocol (code 5) at MAIN.C (1296) [receiver=2.6.8]
Reasons and Solutions:
SELinux;
Setsebool-p Rsync_disable_trans on
================== encountered problems and solutions ========================================
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.