I. Introduction of RSYNC
rsync (remote sync) is the next magical data mirroring backup software for UNIX and Unix-like platforms, unlike FTP or other file transfer services that require full backup, and rsync can make differential (incremental) backups based on data changes. This reduces data traffic and increases productivity. You can use it for local data or remote data replication, and rsync can use SSH secure tunneling for encrypted data transfer. The rsync server defines the source data, and the Rsync client will actually replicate the data from the server only after the source data has changed, and if the source data is deleted on the server side, the client data is also deleted to ensure that the data between the hosts is synchronized. Rsync uses TCP 873 ports.
Rsync is divided into server-side, client-side, server-building than the client hard (and very simple).
The rsync server is the server that runs the rsync service in Deamon mode and needs to open the Rsync deamon and start the xinetd service. Default Port 873.
The rsync client is the server that initiates the rsync connection and installs rsync.
After the Rsync client initiates the connection, the Rsync server checks that the Rsync client submits the user name and password built into the rsync server correctly, and if the authentication is detected, the file transfer is started, and the transfer process is based on the requirements of the file size, attributes, permissions, MD5 values, etc. If the file information on both ends is inconsistent, synchronize the difference blocks of the file as required.
rsync Command Detailed: Http://man.linuxde.net/rsync
II. Experimental Environment of rsync
- Client: 10.30.2.39 (in China)
- Server: 172.30.53.30 (in USA)
- Server-side Linux version: CentOS release 5.11 (Final) [old server, now the latest version is already cent OS 7.5 version]
- Client Linux version: CentOS release 6.9 (Final)
Third, rsync server configuration
Note: The server is located in US 172.30.53.30 machine, because the server's Linux version is low, some configuration on the reference network is based on cent os6,cent Os7. It's been a long time without success. The final configuration is successful on Cent OS 5. the following records are all configured based on Cent OS 5, which can be cumbersome over cent OS 6,7, but also for Cent OS 6 and 7.
1. View and uninstall the system's own rsync
>rpm-qa | grep rsync
>rpm-e rsync***
[Delete your own rsync and install the desired version using the source code later]
2. Download the latest version and install the source code
"Rsync Source link, you can choose your favorite version of the source code installation: https://rsync.samba.org/ftp/rsync/src/"
>wget http://rsync.samba.org/ftp/rsync/src/rsync-3.0.7.tar.gz
>tar xvfz rsync-3.0.7.tar.gz
>CD rsync-3.0.7
>./configure--prefix=/usr/local/rsync
> Make&& make install
3. Create the configuration file (default does not exist, new):/etc/rsyncd.conf
>vim/etc/rsyncd.conf
Uid=nobodygid=nobodymax connections=36000use chroot=nolog file=/var/log/rsyncd.logpid file=/var/run/rsyncd.pidlock File=/var/run/rsyncd.lockport = 873[builds]comment= Backup Buildspath=/var/www/html/pub/va/buildsignore errorsread only = Yeshost allow = *host deny=*secrets File=/etc/rsyncd.passwdauth users=root
The configuration file is simply explained as follows:
port=873 specified port (recommended must be added)
What follows [builds] is primarily the setting of the folders and properties that define the server side to be synchronized
Secrets file=/etc/rsyncd.passwd
Auth Users=root
These two configurations note that you have specified a file to access users and Accounts (step 4 creates this file).
4. Create/ETC/RSYNCD.PASSWD (default does not exist)
>vim/etc/rsyncd.passwd
Add account password as follows: Format (USER:PWD)
root:123456
5. Permission modification (important step, not omitted)
>chmod 600/etc/rsyncd.conf
>chmod 600/etc/rsyncd.passwd
6. Start the server side
>/usr/local/rsync/bin/rsync--daemon--config=/etc/rsyncd.conf
Iv. rsync Client Configuration
The configuration of the client is simple, just install rsync. Clients can use their own rsync or use yum install rsync*. After the client has ensured that the Rsync command is available, the following configuration continues:
1. Create a file (/ETC/RSYNCD.PASSWD)
>vim/etc/rsyncd.passwd
123456
The content is the root password, refer to the server side of the/etc/rsyncd.passwd file settings.
2. Modify File Permissions
>chmod 600/etc/rsyncd.passwd
3. Perform synchronization commands
>rsync-vzrtopg--progress [email protected]::builds/builds--password-file=/etc/rsyncd.passwd
can also be executed backstage >rsync-vzrtopg--progress [email protected]::builds/builds--password-file=/etc/rsyncd.passwd &
The command will show the execution process, the actual server side of a lot of T data, Backup to the Chinese server takes a long time. So we recommend running in the background.
4. Check the folder for client synchronization to see that the server-side files and content are increasing.
5. Set up Scheduled tasks:
This step can be performed using Linux crontab or Jenkins timed synchronization tasks, here is an unknown solution. can refer to my article, Jenkins's timed tasks.
V. Higher order: Build your own CentOS Mirror station via rsync 1. It takes three steps to build a mirror station: Find a faster domestic source, install Tomcat and configure it, and synchronize the target source data. 2. Domestic sources
Domestic source is also synchronous foreign official server, we need to find support rsync domestic source, can Baidu search keyword "CentOS mirror station" or with my recommendation Tsinghua Open-source software mirror station https:// mirrors4.tuna.tsinghua.edu.cn/centos/.
3.tomcat Installation and Configuration installation
>wget http://mirrors.hust.edu.cn/apache/tomcat/tomcat-8/v8.5.24/bin/apache-tomcat-8.5.24-fulldocs.tar.gz
>tar-zxvf apache-tomcat-8.5.24-fulldocs.tar.gz
Configuration
Set the specified directory as the resource directory
Set tomcat display soft Connect directory
Tomcat installation directory/CONF directory: Context.xml file, add allowlinking= "true" attribute on it.
Set up Tomcat directory browsing
Website address: https://tomcat.apache.org/
Link address: http://mirrors.hust.edu.cn/apache/tomcat/tomcat-8/v8.5.24/bin/apache-tomcat-8.5.24-fulldocs.tar.gz sync source
Synchronization source
is to synchronize the data of the domestic mirror station to the native CentOS. The process is as follows:
? Create a folder first: CentOS base source directory CentOS Epel Source directory
? Synchronizing with Rsync
? Set up Scheduled Tasks
1. Create a folder
>mkdir-p/data/centos
>mkdir-p/data/epel
2. Sync:
>rsync-avrt rsync://mirrors4.tuna.tsinghua.edu.cn/centos//data/centos/
>rsync-avrt rsync://mirrors4.tuna.tsinghua.edu.cn/epel//data/epel/
3. Scheduled Tasks:
Write the two line synchronization statements to the script Yum_rsync.sh,vi/etc/crontab #在最后一行添加以下代码
0 1 * * * root/home/crontab/yum_rsync.sh #
Set the execution script to start 1 o'clock in the morning every day: wq! #保存退出
[Linux] Rsync Server and client configuration under Linux