Rsync Service Usage

Source: Internet
Author: User
Tags website server rsync

This time I used the rsync service for testing, testing, and updating the web front-end website. First, introduce the process and configuration. Www.2cto.com 1. the prerequisite website launch process is too original: frontend R & D provides a test, and an email packages the test files to the test ---> manually upload the files to the test environment, after the test is passed, the test package submission email is sent to O & M ---> O & M for online updates. Manual file update is too cumbersome and long, even if the online operations are automated, however, for R & D and testing in the past, it is also a process that can drive people crazy. Especially when the test task is large. Www.2cto.com 2. Solution 2.1 provides dedicated FTP for frontend R & D. The deployment of the FTP service is not mentioned here. 2.2 deploy the rsync service on the system where the dedicated FTP is located, so that the test environment can automatically synchronize the files on the dedicated FTP. 2.3 deploy the rsync service in the test environment so that files in the test environment can be manually synchronized in the production environment. 2.4 and then perform online tracking testing. 3. environment Description test dedicated FTP: CentOS6.2 192.168.1.167 website test server: CentOS6.2 192.168.1.6 Production Environment website server: CentOS5.8 192.168.64.824. rsync service deployment and automatic synchronization setting 4.1 rsync service deployment can be enabled in the form of a separate process, or you can configure the xinetd daemon to enable it automatically. 4.1.1 installation is very simple. you can install yum install-y rsync 4.1.2 to create the configuration file and password file touch/etc/rsyncd. conf touch/etc/rsyncd. pwd chmod 600/etc/rsyncd. pwd # it must be changed to the owner's read and write permissions. Otherwise, password verification cannot be performed. The following is/etc/rsyncd in this example. conf file and/etc/rsyncd. content of the pwd File: test the rsyncd on the dedicated FTP server: 192.168.1.167. conf configuration: port = 873 uid = root gid = root pid file =/var/run/rsyncd. pid lock file =/var/run/rsyncd. lock log file =/var/log/rsyncd. log [web_update] # Instance name uid = root # Use root User Permissions, you can customize the System user gid = root # Use the root user group permission path =/home/data01/website/# host allow = 192.168.1.6 # allow connection to this service host, specify that only the test server is allowed to synchronize read only = true # true read-only permission, false read and write permission auth users = rsync # secrets file =/etc/rsyncd for users who are allowed to transfer files. pwd # specify the location of the password verification file to test the dedicated FTP server: rsyncd on 192.168.1.167. pwd configuration: rsync: yourpassword167 # The colon is preceded by the user rysnc specified by auth users, followed by a custom password. # The password must be readable, that is, the password cannot contain special characters. Website test server: rsyncd on 192.168.1.6. conf configuration: port = 873 uid = root gid = root pid file =/var/run/rsyncd. pid lock file =/var/run/rsyncd. lock log file =/var/log/rsyncd. log [web_cms] uid = root gid = root path =/home/htdocs/host allow = 192.168.64.82 # specify to allow only servers in the production environment to synchronize read only = true auth users = rsync secrets file =/etc/rsyncd. pwd website test server: rsyncd on 192.168.1.6. pwd configuration: rsync: yourpassword6 4.1. 3. Start and configure boot/usr/bin/rsync -- daemon # Start echo '/usr/bin/rsync -- daemon' in the form of a service>/etc/rc. local # The old configuration method for starting 4.2 automatic synchronization at startup: script + crontab is actually a patchwork of several commands. For security purposes, you can make a judgment to determine under what circumstances the synchronization is not performed, or send an email or SMS alarm when an error occurs during synchronization. If you are lazy and don't make a judgment, don't trigger an alarm. Sync directly !! The content is as follows: synchronization script on website test server: 192.168.1.6 :#! /Bin/bash DATE = 'date + "% Y % m % d % H % M" 'echo "################ ######################################## ">/data01/log/rsync. log echo '##################################### ##################'>/data01/log/rsync. log/usr/bin/rsync-vzrtopglP -- delete rsync@192.168.1.167: web_update/home/htdocs/-- password-file =/root/scripts/rsyncd. pwd>/data01/log/rsync. log # -- password-file =/root/scripts/rsyncd. p In wd, the/root/scripts/rsyncd. pwd File specifies the file for obtaining the password. The content is on 192.168.1.167, And the rsync user password only writes the password yourpassword167, # the user and the colon cannot be written. The File Permission is also the Master read/write (600 ). Echo "@ The sync job was done on $ DATE !!! @ ">/Data01/log/rsync. regular execution of log crontab: crontab-e */5 *****/bin/bash/root/scripts/auto_sync_data.sh # auto_sync_data.sh is the file name production environment of the script file. Website Server: synchronization script on 192.168.64.82 :#! /Bin/bash DATE = 'date + "% Y % m % d % H % M" 'tar-czvf/home/backup/htdocs_1_date.tar.gz/home/htdocs/>/dev/ null 2> & 1 # back up the online file rsync-azvP -- delete rsync@192.168.1.6:: web_cms // home/htdocs/-- password-file =/home/scripts/rsyncd. pwd>/home/rsync. log # synchronize the files in the test environment. Note:/home/scripts/rsyncd. the content and permissions of the pwd File. Echo "#########$ DATE #######">/home/rsync. log manually performs online operations. It is recommended that you do not perform scheduled operations unless it is controllable. 5. Such a process and configuration can only be used for non-application services, such as website page files, images, and flash resources. Do not use it on application-oriented services. Because application-oriented services such as java and php involve changes to configuration files in different environments, it is absolutely impossible to perform silly synchronization. For automatic deployment and update of application-oriented services, I use a continuous integration environment such as Tomcat + Jenkins/hudson + ant + SVN. Rsync command details:-v, -- verbose detailed mode output-q, -- quiet simplified output mode-c, -- checksum open verification switch, force the file transfer Validation-, -- archive mode: Transfers files recursively and keeps all file attributes. equals to-rlptgoD-r, -- recursive processes subdirectories in recursive mode-R, -- relative uses relative path information-B, -- backup to create a backup, that is, if the object already has the same file name, rename the old file ~ Filename. You can use the -- suffix option to specify different backup file prefixes. -- Backup-dir: backs up files (for example ~ Filename) is stored in the directory. -Suffix = SUFFIX defines the backup file prefix-u. -- update only performs updates, that is, skipping all files that already exist in DST and whose file time is later than the backup time. (Do not overwrite the updated file)-l, -- links retains the soft link-L, -- copy-links: process soft links like regular files -- copy-unsafe-links: only copies links other than the SRC path directory tree -- safe-links ignores the directory tree pointing to the SRC path other links-H, -- hard-links keep hard links-p, -- perms keep File permissions-o, -- owner keep file owner information-g, -- group keep file group information-D, -- devices: Keep Device File Information-t, -- times: Keep file time information-S, -- sparse performs special processing on sparse files to save DST space-n, -- dry-run which files will be transmitted-W, -- whole-file to copy files without incremental detection-x, -- one-file-system: Do not span the file system boundary-B. -- block-size = SIZE indicates the block size used by the algorithm. The default value is 700 bytes-e, -- rsh = COMMAND specifies to use rsh and ssh for Data Synchronization -- rsync-path = PATH specifies the path of the rsync COMMAND on the remote server-C, -- cvs-exclude automatically ignores files in the same way as CVS to exclude files that do not want to be transmitted. -- existing only updates files that already exist in DST, instead of backing up those new files -- delete those files that are not in the dst src -- delete-excluded also delete the files that are excluded by this option at the receiving end -- after the delete-after transmission ends delete -- ignore-errors and delete it when I/o errors occur in a timely manner -- max-delete = NUM delete a maximum of NUM files -- partial keep those files that are not completely transmitted for any reason, to accelerate the subsequent re-transmission -- force the deletion of directories, even if it is not blank -- numeric-ids does not match the number user and group ID as the user name and group name -- timeout = time ip timeout TIME, in seconds-I, -- ignore-times does not skip files with the same time and length -- size-only. when determining whether to back up a file, only check the file size, regardless of the file time -- modify-window = NUM determines whether the file is time-stamped, the default value is 0-T -- temp-dir = DIR. Create a temporary file in DIR -- compare-dest = DIR and compare the files in DIR to determine whether to back up-P is equivalent to -- partial -- progress displays the backup process-z, -- compress compresses the backup files during transmission -- exclude = PATTERN specifies to exclude the file mode that does not need to be transmitted -- include = PATTERN specifies the file mode to be transmitted without exclusion -- exclude- from = FILE exclude files in the specified mode -- include-from = FILE do not exclude files in the specified mode of FILE -- version print version information -- address bound to a specific address -- config = FILE specify other configuration files, do not use the default rsyncd. conf file -- port = PORT specify other rsync service ports -- blocking-io for remote shell use blocking IO-stats to give the transmission status of some files -- progress actual transmission process -- log -format = formAT specify the log file format -- password-FILE = FILE get the password from the file -- bwlimit = KBPS limit I/O bandwidth, KBytes per second-h, -- help displays help information

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.