unison双向同步
安装
Linux下通过源码包编译安装Unison时,需要用到Objective Caml compiler 1
2
3
4
5
6wget http://caml.inria.fr/pub/distrib/ocaml-4.06/ocaml-4.06.0.tar.gz
tar -zxvf ocaml-4.06.0.tar.gz
cd ocaml-4.06.0
./configure
make world opt
make install
编译安装Unison 1
2
3
4
5
6wget https://github.com/bcpierce00/unison/archive/v2.51.2.tar.gz
tar -zxvf v2.51.2.tar.gz
cd unison-2.51.2/src
make UISTYLE=text
cp ./unison /usr/local/bin
make install
设置免密登陆
2台服务器操作相同 1
2
3useradd -m unison
su - unison
ssh-keygen -t rsa
将生成的/home/unison/.ssh/id_rsa.pub复制到另一台服务器,然后写入认证文件中 1
cat ~/id_rsa.pub >> ~/.ssh/authorized_keys
如果没有.ssh文件夹 1
2mkdir ~/.ssh
chmod 700 ~/.ssh
重启ssh服务 1
systemctl restart sshd
测试连接 1
ssh unison@xxx.com -i ~/.ssh/id_rsa
同步配置
修改~/.unison/default.prf文件 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35root = /unison/test
root = ssh://unison@10.124.5.215//unison/test
#force =/unison/test
servercmd=/usr/local/bin/unison
#ignore =/tmp/test_1/a
batch = true
#repeat = 1
#retry = 3
owner = true
group = true
perms = -1
#fastcheck = false
#rsync = false
sshargs = -C
#xferbycopying = true
confirmbigdel=false
log = true
logfile = /home/unison/.unison/unison.log
配置解读
1 | 两个root表示需要同步的文件夹。 |
测试
1 | su unison |
加入crontab定时任务
1 | su unison |