Unison achieves two-way Data Synchronization

Source: Internet
Author: User
Tags rsync ocaml

Unison Introduction: two-way image synchronization tool that supports cross-platform synchronization. Unios can keep the content consistent between the two folders on the local disk and synchronize network data.

Features: cross-platform

1. No special requirements on kernel and User Permissions

2. Unison is bidirectional and can automatically update the two copies without any conflict.

3. Two methods, one is remote shell, completed by SSH

The other is the socket mode, which sends TCP packets for communication.

4. Support incremental Synchronization

Operating System: rhel6.2

System a IP Address: 192.168.5.205

System B IP Address: 192.168.5.206

Directory/ixdba/webdata in system a is synchronized to system B/ixdba/webdata in real time

  1. Install ocaml and unison on system

    1) install ocaml: http://pan.baidu.com/s/1dDGNZ25

    [[Email protected] ~] # Tar jxvf ocaml-3.10.2.tar.bz2
    [[Email protected] ~] # Cd ocaml-3.10.2
    [[Email protected] ocaml-3.10.2] # Make World OPT

    [[Email protected] ocaml-3.10.2] # makeinstall

    2) install the unison http://pan.baidu.com/s/1o6hZJr8

[[Email protected] ~] # Tar zxvf unison-2.32.52.tar.gz

[[Email protected] ~] # Cd unison 2.32.52
[[Email protected] unison-2.32.52] # Make uistyle = text threads = true static = true

Note: uistyle = text threads = true static = true indicates that the command line method is used. It is added to thread support and compiled in static mode.

[[Email protected] unison-2.32.52] # cp unison/usr/local/bin/

Note: ocaml and unison must be installed in system B. The steps are the same as those above.

2. Configure SSH Trust for system A and system B

The following operations must be performed on both system A and system B. Here, system A is used as an example.

1) Log On As A root user

2) Create the. Ssh directory in the root user's home directory and set the correct permissions

[[Email protected] ~] # Mkdir/root/. SSH

[[Email protected] ~] # Chmod 700/root/. SSH

3) use the ssh-keygen command to generate the RSA key for the 2nd version of SSH protocol

[[Email protected] ~] # Ssh-keygen-T RSA

3. Add the key to the authorization key file and run the following command in system:

1)

[[Email protected] ~] # Cd/root/. Ssh/
[[Email protected]. Ssh] # SSH 192.168.5.205 CAT/root/. Ssh/id_rsa.pub> authorized_keys
[[Email protected]. Ssh] # SSH 192.168.5.206 CAT/root/. Ssh/id_rsa.pub> authorized_keys

[[Email protected]. Ssh] # SCP authorized_keys 192.168.5.206: Root/. SSH

[[Email protected]. Ssh] # chmod 600/root/. Ssh/authorized_keys

2) execute the following command in system B:

[[Email protected] ~] # Chmod 600/root/. Ssh/authorized_keys

3) perform the following tests on the two machines respectively. During the first execution, you are required to enter the password information. When you execute the test again, the system date is displayed without entering the password, the SSH mutual trust configuration is successful.

[[Email protected]. Ssh] # SSH 192.168.5.205 date
Wed Sep 24 17:23:50 HKT 2014
[[Email protected]. Ssh] # SSH 192.168.5.206 date
Wed Sep 24 17:24:50 CST 2014

[[Email protected] ~] # SSH 192.168.5.206 date
Wed Sep 24 17:25:20 CST 2014
[[Email protected] ~] # SSH 192.168.5.205 date
Wed Sep 24 17:24:37 HKT 2014

4) test

[[Email protected]. Ssh] # unison/ssh: // 192.168.5.206/-testserver
Contacting server...
Connected [// A // test-> // B // root]

4. Remotely use unison using commands

For example:

Unison/test SSH: // [email protected] // Test

Synchronize the local/test with the remote host/test. Note that you need to press enter and enter y to confirm interaction.

5. Use the unsion through the configuration file

Operating on system

1)/root/. Unison is used to save the unison configuration file. If it is a root user, it is located in/root/. unison

In the/root/. unison directory, if the name of the configuration file is not specified, the default value is default. PRF.

Create/root/. unison/ixdba. PRF

[[Email protected] ~] # Vim/root/. unison/ixdba. PRF
1 root =/ixdba/webdata # indicates the directory to be synchronized from the Local Machine

2 root = SSH: // [email protected] // ixdba/webdata2 # indicates the directory to be synchronized from system B.
3 # force =/ixdba/webdata # force: unison becomes one-way synchronization if it is not commented out.

4 Path = WWW
5 Path = upload
6 ignore = path WEB-INF/tmp # ignore/ixdba/webdata/WEB-INF/tmp directory, that is, this directory is not synchronized during Synchronization

7 # prefer = SSH: // [email protected] // ixdba/webdata
8 batch = true # indicates the full automatic mode. You do not need to enter the carriage return and Y for confirmation.

9 maxthreads = 300 # maximum synchronization thread

10 repeat = 1 # indicates that the new synchronization check starts after one second, and the real-time synchronization in 1 second --

11 # retry = 3 # specify the number of failed retries

12 owner = true # indicates the owner information of the file to be synchronized

13 group = true
14 perms =-1 # indicates that the synchronization file read and write permissions are maintained during synchronization.
15 fastcheck = true # True indicates that files in two locations are compared during File Creation During synchronization.
False indicates comparing the content of files in two locations. It is recommended to set this parameter to true.

16 rsync = false # rsync transmission mode not activated
17 # DEBUG = verbose
18 sshargs =-C # indicates the compression transmission mode using SSH.
19 xferbycopying = true # optimized Transmission Parameters
20 confirmbigdel = false # ensure that when a directory to be synchronized is empty, unison will not stop running
21 log = true # output running information on the terminal
22 logfile =/root/. unison/ixdba_10.10.log # log record

Note:

4 5 specify/ixdba/webdata/WWW and/ixdba/webdata/upload to be synchronized. Other directories under/ixdba/webdata are not synchronized.

5. Run the test in system A to check whether system B/ixdba/webdata has synchronized data of system.

Modify the data of system B/ixdba/webdata, and then run uniosn ixdba on system A to check whether system A/ixdba/webdata is consistent.

[[Email protected] ~] # Unison ixdba

6. Summarize the basic principle of Unison bidirectional synchronization: A synchronizes the changes to B, B synchronizes the changes to a, and finally the content of A and B is the same.



This article is from the "Dream Three Kingdoms" blog and will not be reproduced!

Unison achieves two-way Data Synchronization

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.