In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
It is believed that many inexperienced people don't know what to do about data synchronization and file incremental backup in rsync server erection. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
In order to achieve load balancing among multiple servers, we need to synchronize data among these servers, and rsync software is also competent. Let's introduce how to set up a rsync server to achieve the function of file incremental backup and data synchronization.
What is rsync?
Rsync is a fast incremental file transfer tool that can be used for backup within the same host, and we can also use it as a network backup tool for different hosts. This article is mainly about how to set up a rsync server to realize file transfer, backup and mirroring. Compared with tar and wget, rsync also has its own advantages, such as high speed, security and efficiency.
Installation of rsync
On the CentOS server, we can execute the following command to install
Yum install rsync
For debian, ubuntu servers, the following command
Sudo apt-get install rsync
Configuration file rsyncd.conf for rsync server
Next we will cover three files, rsyncd.conf,rsyncd.secrets and rsyncd.motd.
Rsyncd.conf is the main configuration file for the rsync server.
Rsyncd.secrets is the password file that logs in to the rsync server.
Rsyncd.motd defines the rysnc server information, that is, the user login information.
Let's set up these three files respectively.
Mkdir / etc/rsyncd
Note: create a rsyncd directory under the / etc directory, which we use to store rsyncd.conf and rsyncd.secrets files
Touch / etc/rsyncd/rsyncd.conf
Note: create a rsyncd.conf, which is the configuration file for the rsync server
Touch / etc/rsyncd/rsyncd.secrets
Note: create rsyncd.secrets, which is the user password file
Chmod 600 / etc/rsyncd/rsyncd.secrets
Note: for the security of the password, we set the permission to 600
Touch / etc/rsyncd/rsyncd.motd
Note: create a rsyncd.motd file, which is a file that defines server information.
It's time for us to modify the rsyncd.conf and rsyncd.secrets and rsyncd.motd files next.
Contents of rsyncd.conf file:
The code is as follows:
# 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
Pid file = / var/run/rsyncd.pid
Port = 873
Address = 192.168.1.171
# uid = nobody
# gid = nobody
Uid = root
Gid = root
Use chroot = yes
Read only = yes
# limit access to private LANs
Hosts allow=192.168.1.0/255.255.255.0 10.0.1.0/255.255.255.0
Hosts deny=*
Max connections = 5
Motd file = / etc/rsyncd/rsyncd.motd
# This will give you a separate log file
# log file = / var/log/rsync.log
# This will log every file transferred-up to 85000 + per user, per sync
# transfer logging = yes
Log format =% t% a% m f% b
Syslog facility = local3
Timeout = 300
[linuxsirhome]
Path = / home
List=yes
Ignore errors
Auth users = linuxsir
Secrets file = / etc/rsyncd/rsyncd.secrets
Comment = linuxsir home
Exclude = beinan/ samba/
[beinan]
Path = / opt
List=no
Ignore errors
Comment = optdir
Auth users = beinan
Secrets file = / etc/rsyncd/rsyncd.secrets
Password file: content format of / etc/rsyncd/rsyncd.secrets
User name: password
Linuxsir:222222
Beinan:333333
Note: the password here is worth noting. For the sake of security, you can't write the password of the system user here. For example, your system user's linuxsir password is abcdefg. For security, you can make the linuxsir in rsync to be 222222. This is similar to the password principle of samba user authentication.
Rsyncd.motd file
It defines rysnc server information, that is, user login information. For example, let the user know who provided the server; similar to the jb51.net ftp we see when the ftp server logs in. Of course, this is not necessary when defining variables globally, you can write out or delete it with the # sign; I wrote a rsyncd.motd here as follows:
+ +
+ jb51.net rsync 2002-2007 +
+ +
Rsyncd.conf file code description
Pid file = / var/run/rsyncd.pid
Note: tell the process to write to / var/run/rsyncd.pid file
Port = 873
Note: specify the running port. The default is 873. You can specify it yourself.
Address = 192.168.1.171
Note: specify the server IP address
Uid = nobody
Gid = nobdoy
Note: when transferring files on the server side, which user and user group should be sent for execution? the default is nobody. If you use nobody users and user groups, you may encounter permission problems, and some files cannot be pulled from the server. So I slacked off and used root for convenience. However, you can resolve permissions by specifying users in the modules defined when defining directories to synchronize.
Use chroot = yes
With chroot, the server daemon sends chroot to a directory in the file system before transferring the file, which has the advantage of protecting the system from installation vulnerabilities. The disadvantage is that superuser privileges are required. In addition, symbolic link files will be excluded. That is to say, if you have a symbolic link on the rsync server, when you run the client's synchronization data on the backup server, you will only synchronize the symbolic link name, not the contents of the symbolic link; you need to try this yourself.
Read only = yes
Note: read only is a read-only option, that is, clients are not allowed to upload files to the server. There is also a write only option, try to do what it is for
# limit access to private LANs
Hosts allow=192.168.1.0/255.255.255.0 10.0.1.0/255.255.255.0
Note: you can specify either a single IP or the entire network segment, which can improve security. The format is to be separated by spaces between ip and ip, ip and network segments, and network segments.
Max connections = 5
Note: maximum number of client connections
Motd file = / etc/rsyncd/rsyncd.motd
Note: motd file defines the server information and writes the contents of the rsyncd.motd file by yourself. Users will see this message when they log in.
Log file = / var/log/rsync.log
Note: log of rsync server
Transfer logging = yes
Note: this is the log of the transferred file.
[linuxsirhome]
Note: module, which provides us with the name of a link, where to link to, in this module, link to the / home directory; use [name] form
Path = / home
Note: specify the location of the file directory, which must be specified
Auth users = linuxsir
Note: the authenticated user is linuxsir and must exist on the server.
List=yes
Note: list means to list the directories on the rsync server that provide synchronous data on the server whether the module is displayed or not. The default is yes. If you don't want to list it, no it; if no is more secure, at least others don't know which directories are available on your server. You just need to know it yourself.
Ignore errors
Note: ignore IO error, please check the documentation for details
Secrets file = / etc/rsyncd/rsyncd.secrets
Note: which file does the password exist
Comment = linuxsir home data
Note: comments can be defined by yourself, you can write anything, just write something related.
Exclude = beinan/ samba/
Note: exclude means to exclude, that is, to exclude beinan and samba under the / home directory; there is a space between the beinan/ and samba/ directories
Start the rsync server and firewall settings
Start the rsync server
Starting the rsync server is fairly simple.-daemon is to let rsync run in server mode.
/ usr/bin/rsync-daemon-config=/etc/rsyncd/rsyncd.conf
Rsync servers and firewalls
The Linux firewall uses iptables, so we should at least let your defined rsync server port through on the server side and on the client side.
Iptables-An INPUT-p tcp-m state-- state NEW-m tcp-- dport 873-j ACCEPT
Check to see if the firewall has port 873 open
Iptables-L
Synchronize data through the rsync client
Rsync-avzP linuxsir@jb51.net::linuxsirhome linuxsirhome
Password: enter the password of linuxsir here, which is provided by the server. In the previous example, we used 222222, and the password entered is not shown. Enter enter after typing.
Note: this command means that you log in to the server with the linuxsir user and synchronize the linuxsirhome data to the local directory linuxsirhome. Of course, you can define the local directory, such as linuxsir; when you are on the client, there is no linuxsirhome directory under the current operation directory, the system will automatically create one for you; when it exists in the linuxsirhome 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 compression during transmission
-P transmission progress
The progress of-v transmission and other information has something to do with-P, try it yourself. You can read the document.
Rsync-avzP-- delete linuxsir@jb51.net::linuxsirhome linuxsirhome
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 linuxsirhome directory that do not exist on the server, delete them. The ultimate goal is to keep the data on the linuxsirhome 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
Rsync-avzP-delete-password-file=rsync.password linuxsir@jb51.net::linuxsirhome linuxsirhome
This time we added an option-password-file=rsync.password, which means that when we log in to the rsync server to synchronize data as a linuxsir user, the password will read the rsync.password file. The content of this file is only the password of the linuxsir user. We need to do the following
The code is as follows:
Touch rsync.password
Chmod 600 rsync.password
Echo "222222" > rsync.password
Rsync-avzP-delete-password-file=rsync.password linuxsir@jb51.net::linuxsirhome linuxsirhome
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
Let the rsync client automatically synchronize data with the server
Edit crontab
Crontab-e
Add the following code:
100 * rsync-avzP-delete-password-file=rsync.password linuxsir@jb51.net::linuxsirhome linuxsirhome
Indicates that the following commands are executed at 00:10 every day. For more information on crontab usage, please refer to
After reading the above, have you mastered the method of data synchronization and file incremental backup in the construction of rsync server? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
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.