In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
In this article, the editor introduces "how to build a rsync server" in detail, the content is detailed, the steps are clear, and the details are handled properly. I hope this article "how to build a rsync server" can help you solve your doubts.
Rsync, whose full name is remote sync, is a more efficient command that can be synchronized locally or remotely. It is efficient because rsync compares the source and destination progress lines that need to be synchronized, and only synchronizes the changed parts, so it is more efficient than the scp command. But rsync itself is a non-encrypted transmission, and you can use the-e option to set a bearer tool with encryption function to encrypt the transmission.
System environment system platform: CentOS 6rsync version: rsync-3.0.9-2.el6.rfx.x86_64.rpmrsync server: TS-DEV (172.16.1.135) rsync client: TS-CLIENT (172.16.1.136) server side install rsync service
Check if rsync is installed
# rpm-qa | grep rsync
Download the RPM package
# wget http://pkgs.repoforge.org/rsync/rsync-3.0.9-2.el6.rfx.x86_64.rpm
Install rsync
# rpm-ivh rsync-3.0.9-2.el6.rfx.x86_64.rpm configure rsync service
To configure a rsync server
First of all, we should choose the server startup mode for the heavily loaded rsync server, we should use the independent operation mode for the lighter load rsync server, we can use the xinetd operation mode to create the configuration file rsyncd.conf for the rsync server with non-anonymous access, we should also create the authentication password file.
Run the rsync service as xinetd
CentOS runs the rsync service as xinetd by default. The xinetd configuration file for rsync is in / etc/xinetd.d/rsync. To configure a rsync service running as xinetd, you need to execute the following command:
# chkconfig rsync on# service xinetd restart
Run the rsync service independently
The easiest way to run the rsync service independently is to execute the following command:
# / usr/bin/rsync-daemon
You can write the above command to the / etc/rc.local file to run the rsync service each time you start the server.
Profile rsyncd.conf
Rsyncd.conf needs to be configured for both rsync service operation modes. The configuration file rsyncd.conf is in the / etc directory by default. In order to put all files related to rsync services in a separate directory, execute the following command:
# mkdir / etc/rsyncd# touch / etc/rsyncd/rsyncd.conf# ln-s / etc/rsyncd/rsyncd.conf / etc/rsyncd.conf
The configuration file rsyncd.conf consists of a global configuration and several module configurations. The syntax of the configuration file is as follows: the module starts with [module name]. The format of the parameter configuration line is name = value, where value can have two data types: string (which can be delimited without quotation marks) Boolean value (1 pound 0 or yes/no or true/false) with # or; starting behavior comment\ as the continuation character
Global parameter
All configuration lines except [module] in the file are global parameters. Of course, you can also define a module parameter in the global parameters section, where the value of this parameter is the default value of all modules.
Rsync server configuration under CentOS6 rsync server configuration under CentOS6
Module parameters
Module parameters are mainly used to define which directory of the rsync server will be synchronized. The module declaration must be in the form of [module], which is the name you see on the rsync client, similar to the share name provided by the Samba server. The data that the server actually synchronizes is specified through path. You can specify multiple modules according to your needs, and the following parameters can be defined in the module:
a. Basic module parameters
Rsync server configuration under CentOS6 rsync server configuration under CentOS6
b. Module control parameters
c. Module file filter parameters
Rsync server configuration under CentOS6 rsync server configuration under CentOS6
A module can only specify one exclude parameter and one include parameter. Complex exclude/include rules can be defined by combining include and exclude. These parameters are equivalent to the corresponding rsync client command options, except that they work on the server side.
d. Module user authentication parameters
Rsync server configuration under CentOS6 rsync server configuration under CentOS6
The permissions for the rsync authentication password file must be 600, otherwise the client will not be able to connect to the server. Each line in the rsync authentication password file specifies a user name: password pair, in the format: username:passwd. Generally speaking, passwords should not exceed 8 characters. If you configure only anonymously accessed rsync servers, you do not need to set the above parameters.
e. Module access control parameters
Rsync server configuration under CentOS6 rsync server configuration under CentOS6
The customer host list definition can be in the following form: a single IP address. For example: 192.168.0.1 the entire network segment. For example, a single hostname that can be resolved by 192.168.0.0 Universe 24192.168.0.0 Universe 255.255.255.0. For example: all hosts in the centos,centos.bsmart.cn domain. For example: .bsmart.cn "" means all. Multiple list items are separated by spaces.
f. Module log parameters
When the "log file" parameter is set, "% t [% p]" is added at the beginning of each line of the log.
The log format definitions that can be used are as follows:% a-remote IP address% h-remote hostname% l-file length characters% p-PID% o-operation type for this rsync session: "send" or "recv"% f-file name% P-module path% m-module name% t-current Time% u-authenticated user name (null when anonymous)% b-actual number of bytes transferred% c-when sending the file Record the check code of the file
Rsync server application case
Configure rsync services on the server-side TS-DEV
a. Edit configuration file
# vi / etc/rsyncd/rsyncd.conf
# Minimal configuration file for rsync daemon# See rsync (1) and rsyncd.conf (5) man pages for help# This line is required by the / etc/init.d/rsyncd script# GLOBAL OPTIONSuid = root gid = root use chroot = no read only = yes # limit access to private LANshosts allow=172.16. 0.0ax 255.255.0.0 192.168.1.0 10.0.1.0/255.255.255.0hosts deny=* max connections = 5 pid file = / var/run/rsyncd.pid secrets file = / etc/rsyncd/rsyncd.secrets # lock file = / var/run/rsync.lock motd file = / etc/rsyncd/rsyncd.motd # This will give you a separate log filelog file = / var/log/rsync.log # This will log every file transferred-up to 85000 + per user Per synctransfer logging = yes log format =% t% a% m% f% bsyslog facility = local3timeout = 30 years MODULE OPTIONS [davidhome] path = / home/david/ list=yes ignore errors auth users = david Comment = David home exclude = important/ [chinatmp] path = / tmp/china/list=noignore errorsauth users = chinacomment = tmp_china
b. Create / etc/rsyncd/rsyncd.secrets file # vim / etc/rsyncd/rsyncd.secrets
David:asdf # format username: password china:jk # this user is not required to be a system user
c. For the security of the password, we set the permission to 600
# chown root:root / etc/rsyncd/rsyncd.secrets# chmod 600 / etc/rsyncd/rsyncd.secrets
d. Establish the welcome information file / etc/rsyncd/rsyncd.motd # vim / etc/rsyncd/rsyncd.motd seen by the client connecting to the server
+ + David Camp + +
e. Start rsync
# / etc/init.d/xinetd restart
f. Check to see if port 873 is up
# netstat-an | grep 873
If rsync starts successfully, you can see that port 873 is already listening.
g. Server-side file details
Client configuration
a. Client installs rsync
# yum-y install rsync
b. Synchronize data through the rsync client
Scenario 1:
On the client:
# rsync-avzP david@172.16.1.135::davidhome / tmp/david/
Password: enter the password of david here, which is provided by the server. In the previous example, we used asdf, and the password entered is not shown. Enter enter after typing.
Note: this command means that you log in to the server with the david user and synchronize the davidhome data to the local directory / tmp/david/. Of course, you can define the local directory, such as dave; when you are on the client, there is no davidhome directory under the current operation directory, the system will automatically create one for you; when it exists in the davidhome directory, you should pay attention to its write permission.
Description:-a parameter, equivalent to-rlptgoD,-r is recursive-l is a linked file, meaning to copy a linked file;-p means to keep the original permissions of the file;-t to keep the original time of the file;-g to keep the original user group of the file;-o to keep the original owner of the file;-D is equivalent to the block device file;-z is compressed during transfer;-P transfer progress The progress of-v transmission and other information has something to do with-P, try it yourself. You can read the document.
Scenario 2:
# rsync-avzP-- delete david@172.16.1.135::davidhome / tmp/david/
This time we introduce a-delete option, which means that the data on the client side should be exactly the same as the server side, and if there are files in the / tmp/david/ directory that do not exist on the server, delete them. The ultimate goal is to keep the data on the / tmp/david/ directory exactly the same as on the server; be careful when using it, it is best not to use the directory that already has important numbers as a local update directory, otherwise all your data will be deleted
Scenario 3:
# rsync-avzP-- delete-- password-file=/tmp/rsync.password david@172.16.1.135::davidhome / tmp/david/
This time we added an option-password-file=rsync.password, so that when we log in to the rsync server as david to synchronize data, the password will read the file / tmp/rsync.password. The content of this file is only the password of the david user. We need to do the following
# touch / tmp/rsync.password# chmod 600 / tmp/rsync.password# echo "asdf" > / tmp/rsync.password# rsync-avzP-delete-password-file=/tmp/rsync.password david@172.16.1.135::davidhome / tmp/david/
Note: this eliminates the need for a password; in fact, this is more important, because it is necessary for the server to schedule tasks through crond
5.3. The rsync client automatically synchronizes data with the server
Edit crontab # crontab-e to add the following code:
100 * rsync-avzP-- delete-- password-file=/tmp/rsync.password david@172.16.1.135::davidhome / tmp/david/
Indicates that the following commands are executed at 00:10 every day.
After reading this, the article "how to build a rsync server" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself. If you want to know more about related articles, 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.