서버 동기화 · 8 min read · Feb 09, 2026
Debian 8 (Jessie)에서 두 서버 간의 Unison 파일 동기화 설정
이 튜토리얼은 Unison을 사용하여 두 개의 Debian 8 서버 간의 파일 동기화를 설정하는 방법을 보여줍니다. Unison은 rsync와 유사한 파일 동기화 도구로, 큰 차이점은 양방향으로 변경 사항을 추적/동기화한다는 것입니다. 즉, server1에서 변경된 파일은 server2에 복제되고 그 반대도 마찬가지입니다.
1 사전 노트
이 튜토리얼에서는 다음 두 개의 Debian 서버를 사용할 것입니다:
- server1.example.com, IP 주소 192.168.1.101
- server2.example.com, IP 주소 192.168.1.102
저는 두 서버 간에 /var/www 디렉토리를 동기화하고자 합니다. 이 튜토리얼에서는 Unison이 사용자 및 그룹 권한을 동기화할 수 있도록 루트 사용자로 실행할 것입니다.
이 튜토리얼의 모든 명령은 루트 사용자로 실행됩니다. 두 서버에 루트로 로그인하고 2단계 “ Unison 설치하기 “부터 시작하세요.
2 Unison 설치하기
server1/server2:
Unison은 server1과 server2에 설치되어야 합니다. server1에서 server2로 SSH를 통해 연결하므로 SSH 패키지도 필요하며, 셸에서 파일 편집을 위해 nano 편집기를 설치하겠습니다. 이는 다음과 같이 수행할 수 있습니다:
apt-get -y install unison openssh-server ssh nano3 server1에서 개인/공개 키 쌍 생성하기
server1:
이제 server1.example.com에서 개인/공개 키 쌍을 생성합니다:
ssh-keygen -t dsaroot@server1:~# ssh-keygen -t dsa
Generating public/private dsa key pair.
Enter file in which to save the key (/root/.ssh/id_dsa): <– ENTER
Created directory ‘/root/.ssh’.
Enter passphrase (empty for no passphrase): <– ENTER
Enter same passphrase again: <– ENTER
Your identification has been saved in /root/.ssh/id_dsa.
Your public key has been saved in /root/.ssh/id_dsa.pub.
The key fingerprint is:
ba:82:e1:a1:42:9b:d4:c8:99:c8:bd:8b:7d:4d:d4:66 root@server1
The key’s randomart image is:
+—[DSA 1024]—-+
| |
| |
| . |
| . E |
|+ * . S |
|.Ooo o |
|ooo+. + |
|oo=… o |
|.. oo.. |
+—————–+
root@server1:~#
중요한 점은 패스프레이즈를 입력하지 않아야 한다는 것입니다. 그렇지 않으면 미러링이 사람의 상호작용 없이 작동하지 않으므로 ENTER 키를 누르세요!
다음으로, 우리의 공개 키를 server2.example.com으로 복사합니다:
ssh-copy-id -i $HOME/.ssh/id_dsa.pub [email protected]# ssh-copy-id -i $HOME/.ssh/id_dsa.pub [email protected]The authenticity of host '192.168.1.102 (192.168.1.102)' can't be established.
ECDSA key fingerprint is 51:7f:b4:ed:bd:e3:fc:16:2f:55:5c:e1:2c:d7:3d:a9.
Are you sure you want to continue connecting (yes/no)? <-- yes (이것은 server2에 처음 연결할 때만 표시됩니다)
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
[email protected]'s password: <-- server2 root passwordNumber of key(s) added: 1Now try logging into the machine, with: "ssh '[email protected]'"
and check to make sure that only the key(s) you wanted were added.이제 server2에서 server1의 공개 키가 올바르게 전송되었는지 확인합니다:
server2:
cat $HOME/.ssh/authorized_keysroot@server2:/home/administrator# cat $HOME/.ssh/authorized_keys
ssh-dss AAAAB3NzaC1kc3MAAACBAKHLdAztIr8muZIlQYuE/4f75kmgTwWqJRZJ1dTqHDnHWsy48emDU8v85hxAPg43k9aF7/zAwpA0MNNNk5T9Tx/DyUkK/KcyVP2f4p8tvovrkUvoxsZACkTUmFqKdq2x6/AGfjsCRmkpLhZuad7r5rKEXHRh8KYGHqD1Id8wcpy5AAAAFQCww3OekKcKMshMAwBK3XQmmYEGUwAAAIEAgjztlwh8OFYxwQve/RrhI2sceCXwS/yjQyH7q0zdWB9Fr4s/16T2PLBT+7M3vb+JlPDO3JRqgaYbel1kS2F2iKrY0EX0FI3/9fVDfWoz3mhCscPLriqy5AcsHitxQNfiZgA5wDiSjWpk1v+FbIC+VuqbKdQuE4MBKj19N9YALIUAAACABQ4NDsa2UBc8jsxvghjoLhUWF7HChaCksXQcL6i98VNRcemtPC6wpIri75iR4Uhv1666bDOBAdmIBX9Qf7A/+czPKPaj4CGI1hVy1pgYMa3btnEvoSnH/ONtjpOz9q+3up1OOOn+5fud7xjJn+Fq8WoGROgarBpCbQU3w2GUUnM= root@server14 Unison 실행하기
server1:
이제 두 서버에서 /var/www 디렉토리를 동기화하기 위해 Unison을 처음 실행할 수 있습니다. server1에서 실행하세요:
unison /var/www ssh://192.168.1.102//var/www출력은 다음과 유사할 것입니다 - Unison이 처음 실행되므로 몇 가지 질문에 답해야 할 수도 있습니다:
root@server1:/var/www# unison /var/www ssh://192.168.1.102//var/www
Contacting server...
Connected [//server1//var/www -> //server2//var/www]
Looking for changes
Warning: No archive files were found for these roots, whose canonical names are:
/var/www
//server2//var/www
This can happen either
because this is the first time you have synchronized these roots,
or because you have upgraded Unison to a new version with a different
archive format.Update detection may take a while on this run if the replicas are
large.Unison will assume that the 'last synchronized state' of both replicas
was completely empty. This means that any files that are different
will be reported as conflicts, and any files that exist only on one
replica will be judged as new and propagated to the other replica.
If the two replicas are identical, then no changes will be reported.If you see this message repeatedly, it may be because one of your machines
is getting its address from DHCP, which is causing its host name to change
between synchronizations. See the documentation for the UNISONLOCALHOSTNAME
environment variable for advice on how to correct this.Donations to the Unison project are gratefully accepted:
http://www.cis.upenn.edu/~bcpierce/unisonPress return to continue.[] <-- Press Enter Waiting for changes from server
Reconciling changeslocal server2
dir ----> example.com [f] <-- Press Enter
dir ----> example.de [f] <-- Press EnterProceed with propagating updates? [] <-- Enter "y"
Propagating updates
UNISON 2.40.102 started propagating changes at 10:17:17.94 on 25 Sep 2015
[BGN] Copying example.com from /var/www to //server2//var/www
[BGN] Copying example.de from /var/www to //server2//var/www
Shortcut: copied /var/www/example.de/web/index.html from local file /var/www/.unison.example.com.d3783bddaaf59b9ba4d2ed0433f9db63.unison.tmp/web/index.html
[END] Copying example.de
[END] Copying example.com
UNISON 2.40.102 finished propagating changes at 10:17:17.94 on 25 Sep 2015
Saving synchronizer state
Synchronization complete at 10:17:17 (2 items transferred, 0 skipped, 0 failed)이제 server1과 server2의 /var/www 디렉토리를 확인하면 동기화되어 있어야 합니다.
물론, Unison을 대화식으로 실행하고 싶지 않으므로, 명령줄에서 지정해야 할 모든 설정을 포함하는 기본 설정 파일(/root/.unison/default.prf)을 생성할 수 있습니다:
nano /root/.unison/default.prf# Roots of the synchronization
root = /var/www
root = ssh://192.168.1.102//var/www
# Paths to synchronize
#path = current
#path = common
#path = .netscape/bookmarks.html
# Some regexps specifying names and paths to ignore
#ignore = Path stats ## ignores /var/www/stats
#ignore = Path stats/* ## ignores /var/www/stats/*
#ignore = Path */stats ## ignores /var/www/somedir/stats, but not /var/www/a/b/c/stats
#ignore = Name *stats ## ignores all files/directories that end with "stats"
#ignore = Name stats* ## ignores all files/directories that begin with "stats"
#ignore = Name *.tmp ## ignores all files with the extension .tmp
# When set to true, this flag causes the user interface to skip
# asking for confirmations on non-conflicting changes. (More
# precisely, when the user interface is done setting the
# propagation direction for one entry and is about to move to the
# next, it will skip over all non-conflicting entries and go
# directly to the next conflict.)
auto=true
# When this is set to true, the user interface will ask no
# questions at all. Non-conflicting changes will be propagated;
# conflicts will be skipped.
batch=true
# !When this is set to true, Unison will request an extra
# confirmation if it appears that the entire replica has been
# deleted, before propagating the change. If the batch flag is
# also set, synchronization will be aborted. When the path
# preference is used, the same confirmation will be requested for
# top-level paths. (At the moment, this flag only affects the
# text user interface.) See also the mountpoint preference.
confirmbigdel=true
# When this preference is set to true, Unison will use the
# modification time and length of a file as a `pseudo inode
# number' when scanning replicas for updates, instead of reading
# the full contents of every file. Under Windows, this may cause
# Unison to miss propagating an update if the modification time
# and length of the file are both unchanged by the update.
# However, Unison will never overwrite such an update with a
# change from the other replica, since it always does a safe
# check for updates just before propagating a change. Thus, it is
# reasonable to use this switch under Windows most of the time
# and occasionally run Unison once with fastcheck set to false,
# if you are worried that Unison may have overlooked an update.
# The default value of the preference is auto, which causes
# Unison to use fast checking on Unix replicas (where it is safe)
# and slow checking on Windows replicas. For backward
# compatibility, yes, no, and default can be used in place of
# true, false, and auto. See the section "Fast Checking" for more
# information.
fastcheck=true
# When this flag is set to true, the group attributes of the
# files are synchronized. Whether the group names or the group
# identifiers are synchronizeddepends on the preference numerids.
group=true
# When this flag is set to true, the owner attributes of the
# files are synchronized. Whether the owner names or the owner
# identifiers are synchronizeddepends on the preference
# extttnumerids.
owner=true
# Including the preference -prefer root causes Unison always to
# resolve conflicts in favor of root, rather than asking for
# guidance from the user. (The syntax of root is the same as for
# the root preference, plus the special values newer and older.)
# This preference is overridden by the preferpartial preference.
# This preference should be used only if you are sure you know
# what you are doing!
prefer=newer
# When this preference is set to true, the textual user interface
# will print nothing at all, except in the case of errors.
# Setting silent to true automatically sets the batch preference
# to true.
silent=true
# When this flag is set to true, file modification times (but not
# directory modtimes) are propagated.
times=true주석이 파일을 자가 설명하도록 만들어야 하며, 경로 지시문을 제외하고는 모두 이해할 수 있어야 합니다. 경로 지시문을 지정하지 않으면 루트 지시문에 있는 디렉토리가 동기화됩니다. 경로 지시문을 지정하면 경로는 루트 경로에 상대적입니다(예: root = /var/www 및 path = current는 /var/www/current로 변환됨) 그리고 이러한 하위 디렉토리만 동기화되며 루트 지시문에 지정된 전체 디렉토리는 동기화되지 않습니다.
사용 가능한 옵션에 대한 자세한 내용은 Unison의 매뉴얼 페이지를 참조하세요:
man unison이제 모든 설정을 기본 설정 파일에 넣었으므로(특히 루트(및 선택적으로 경로) 지시문), 인수 없이 Unison을 실행할 수 있습니다:
unison5 Unison을 위한 Cron 작업 생성하기
server1:
우리는 동기화를 자동화하고자 하므로 server1.example.com에 대한 cron 작업을 생성합니다:
crontab -e*/5 * * * * /usr/bin/unison &> /dev/null이렇게 하면 Unison이 5분마다 실행됩니다. 필요에 맞게 조정하세요(자세한 내용은
man 5 crontab). 여기서 Unison의 전체 경로(/usr/bin/unison)를 사용하는 이유는 cron이 Unison을 찾을 수 있도록 하기 위함입니다. Unison의 위치는 다를 수 있습니다. 다음 명령을 실행하여 자신의 위치를 찾으세요:
which unison6 Unison 테스트하기
이제 Unison의 양방향 동기화를 테스트하여 설정이 완전히 작동하는지 확인하겠습니다.
server1에서 다음 명령을 실행하여 “Test 1”이라는 내용을 가진 테스트 파일을 생성합니다:
echo "Test 1" > /var/www/test.txt이제 최소 5분을 기다립니다(5분마다 한 번 실행되는 cron 작업을 생성했으므로). 그런 다음 server2에서 다음을 실행합니다:
cat /var/www/test.txttest.txt 파일의 내용을 화면에 표시합니다. 출력은 다음 스크린샷과 유사해야 합니다.

이제 server2에서 다음 명령을 실행하여 테스트 파일의 내용을 “Test 2”로 업데이트합니다:
echo "Test 2" > /var/www/test.txt그리고 최소 5분을 기다립니다. 그런 다음 server1에서 cat 명령을 실행합니다:
cat /var/www/test.txt출력은 스크린샷에 표시된 것과 같아야 합니다.

7 링크
- Unison: http://www.cis.upenn.edu/~bcpierce/unison/
- Debian: http://www.debian.org/
새 게시물을 받은 편지함에서 받기
스팸은 없습니다. 언제든지 구독 해지 가능합니다.