[Sersync + rsync] centos6.5 Remote File sync deployment records

Source: Internet
Author: User
Tags inotify mysql backup

[Sersync + rsync] centos6.5 Remote File sync deployment records

The local files are automatically synchronized to the remote folder for modifications, which is very useful for remote backup. After studying the mainstream synchronization solutions
Rsync + inotify and rsync + sersync. I use the sersync solution here. Of course, most of them are based on previous experiences. Thank you for your selflessness.

Overview

My purpose here is to remotely synchronize mysql Backup files and synchronize them to another centos host.

When rsync + sersync is used for real-time synchronization, the server used to push files runs the sersync service, and the server used to receive files runs the rsync daemon process, in short, sersync will use the rsync command to push files to the rsync server. In actual online use, sersync is generally used as the master server, and rsync is used as the backup server to implement data synchronization and backup, web images, and other functions.

Therefore, both machines require rsync and have the corresponding data write permission.

Preparation

Operating System centos6.5 x86 rsync yum source sersync2.5 _ 64bit push source A 114.110.1.38 (all ip addresses are lab spoofing) receiver B 114.110.1.37

Synchronize the file changes in A directory on machine A to machine B, and the files on both sides are consistent.
Set the receiver B selinux and iptables. The rsync ports must be configured on both sides. The default value is 873.

Operation Receiver

1. Check whether rsync is installed.

[root@i-nzwxivja xjmysql]# rpm -aq|grep rsyncrsync-3.0.6-4.el5_7.1

If yum install-y rsync is not installed

2. rsync Configuration

[root@i-nzwxivja xjmysql]# cat /etc/rsyncd.confuid = rootgid = rootuse chroot =nolist = nolog file = /var/log/rsyncd.log[rsyncmysql]path=/data/backup/xjmysqlcomment=rsyncmysqlignore errorsread only=nolist=nomax connections=200timeout=600auth users=rsyncsecrets file=/etc/rsync.pashosts allow=*#host deny=0.0.0.0/0

Secrets file: the password file for synchronization configuration. [Rsynctest] This is the name of the configuration synchronization module. The path is used later to configure the synchronization directory hosts allow is the host that allows synchronization. Here, the test does not limit hosts deny to reject synchronization.

3. Create a synchronized user and password file, that is, the file in the secrets file configuration option. /Etc/rsync. passwd. Set the permission of this file to 600

# echo "rsync:123456lzz" >> /etc/rsync.pas# chmod 600 /etc/rsync.pas

4. Create a synchronization Directory: directory in the path configuration option

# mkdir /data/backup/xjmysql

5. Start rsync

# rsync --daemon --config=/etc/rsyncd.conf# ps -ef|grep rsyncroot 17521 1 0 16:39 ? 00:00:00 rsync --daemon --config=/etc/rsyncd.confroot 17529 16947 0 16:39 pts/1 00:00:00 grep rsync

Restart xinetd to make the configuration take effect.

# /etc/init.d/xinetd restart

The xinetd service is used to restart rsync. You do not need to use this method. If not, you can use yum to directly install rsync.

6. Configure startup

# echo "rsync --daemon --config=/etc/rsyncd.conf" >> /etc/rc.d/rc.local
Push Source

1. The address on the official sersync website is no longer available. I found a copy from the Internet and put it on another address. The source code image on github
I downloaded the Binary Package and put it on it.

# wget --no-check-certificate https://raw.githubusercontent.com/orangle/sersync/master/release/sersync2.5.4_64bit_binary_stable_final.tar.gz# mkdir /usr/local/sersync# mkdir /usr/local/sersync/conf# mkdir /usr/local/sersync/bin# mkdir /usr/local/sersync/log# tar zxvf sersync2.5.4_64bit_binary_stable_final.tar.gz# cd GNU-Linux-x86/# cp confxml.xml /usr/local/sersync/conf# cp sersync2 /usr/local/sersync/bin

2. Create a password file, which is the same as that of server B. However, you only need to save a password for this file. Without a user name, the permission is 600.

echo "123456lzz" >> /etc/rsync.paschmod 600 /etc/rsync.pas

3. Configure sersync. The configuration file is the confxml. xml file copied in step 2. The path is in/usr/local/sersync/conf.

 

# Set the local IP address and port # Enable DUBUG Mode # Enable the xfs File System # Ignore the pushed files (regular expressions) during synchronization, Which is disabled by default. # Set the event to be monitored # Directory path for local Synchronization # Remote IP address and rsync Module name # Rsync Command Parameters # Rsync synchronization authentication # Set the remote service port of rsync. You need to enable custom ports for remote non-default ports. # Set timeout # Set rsync + ssh encrypted transmission mode, which is disabled by default. To enable this mode, you must set an SSH encrypted certificate. # Path of the script for failed sersync transmission. The script will be re-executed every 60 days. After the script is executed, it will be automatically cleared. # Set rsync + crontab for scheduled transmission, which is disabled by default # Call the plug-in script specified by name after sersync transmission is set. It is disabled by default. # Plug-in script example # Plug-in script example

4. Create a synchronization directory:

mkdir /home/data

5. Set environment variables:

# echo "export PATH=$PATH:/usr/local/sersync/bin/" >> /etc/profile# source /etc/profile

6. Start sersync

Sersync2-r-d-o/usr/local/sersync/conf/confxml. xml # restart: # killall sersync2 & sersync2-r-d-o/usr/local/sersync/conf/confxml. xml

7. Set startup

# echo "sersync2 -r -d -o /usr/local/sersync/conf/confxml.xml" >> /etc/rc.local
Lab

After the sersync service is started

Sender
[root@MiWiFi-R1D data]# ls /home/data/[root@MiWiFi-R1D data]# touch backup.sql[root@MiWiFi-R1D data]# lsbackup.sql
Receiver
[root@i-nzwxivja xjmysql]# ls /data/backup/xjmysql/[root@i-nzwxivja xjmysql]#[root@i-nzwxivja xjmysql]# lsbackup.sql
Conclusion

We can see that the file is quickly synchronized to a remote machine, and the experiment is successful.

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.