test

ultrasound의 이미지

리눅스
rsync 사용하기수홍이야2008.05.15 16:52:56 678http://dmoz.emato.net/?document_srl=301rsync란 서로 다른 두 컴퓨터에 들어 있는 정보를 서로 동기화 시킬때 사용한다. 동일한 소스가 두군데 존재하고 한쪽을 편집했을때, 다른 한쪽에 편집한 부분을 업데이트 시켜줘야한다. 이때 모든 소스를 옮기게 되면 시간적으로 많은 낭비가 있기 때문에 rsync는 수정된 부분만 비교해서 옮겨 주게 된다. 그리고 anonymous 서버로도 설정할 수 있는등 많은 유용한 기능들이 들어있다.

rsh이나 ssh을 이용하여 전송하기
이것은 원격지의 호스트에 계정이 있고 rsync의 서버 데몬이 설정되어 있지 않을 경우 사용한다. 간단히 로컬에서도 cp 대신 사용할 수도 있다. ssh를 이용하면 안전하게 복사할 수 있다. 아래의 방법대로 하면 간단히 원격지로 복사할 수 있다.

shell> rsync -arvu -e ssh /from/directory/ to.hostname.com:/to/direcotry
여기서 디렉토리를 써 줄경우 마지막 부분의 /가 중요한 의미를 가진다. 마직막에 /가 있을 경우는 그 디렉토리 내의 모든 파일을 의미하고 /가 없을 경우는 그 디렉토리 자체를 말하는 것이다. -arvu는 아래 부분을 참조하기 바란다.

원격지 서버 설정하기
먼저 리눅스 최신본을 설치하면 기본적으로 rsync가 설치된다. 그러나 xinetd를 이용하여 서버로 설정은 되어 있지 않기 때문에 서버로 사용할 수 있도록 설정을 해 주어야 한다.

xinetd.d에 rsync파일 추가하기
/etc/xinetd.d디렉토리에 rsync라는 파일을 만들고, 아래와 같은 내용을 입력한뒤, 저장한다.

service rsync
{
disable = no
socket_type = stream
wait = no
user = root
server = /usr/bin/rsync
server_args = --daemon
log_on_failure += USERID
}
/etc/services파일에도 아래와 갈은 내용이 없으면 추가해 주도록 한다.

rsync 873/tcp # rsync
rsync 873/udp # rsync
그리고 /etc/rc.d/init.d/디렉토리에서 xinetd를 restart 시켜준다.

shell> /etc/rc.d/init.d/xinetd restart
rsyncd.conf 파일 생성
/etc디렉토리에 rsync.conf라는 파일을 생성한다.

#motd = /etc/rsync.motd # file : message of the day
uid = nobody
gid = nobody
use chroot = no
max connections = 4
syslog facility = local5
pid file = /var/run/rsyncd.pid

[www.wangsy]
path = /somewhere/in/remote/host
comment = www.wangsy.com homepage
read only = false
uid = apache
gid = apache
auth users = wangsy
secrets file = /etc/rsyncd.secrets
위 파일과 함께 /etc디렉토리에 rsyncd.secrets파일도 함께 생성한다.

name:password
그리고 /etc/rsyncd.secrets파일의 permission을 rw-------로 해주는 것을 잊지 말도록 한다.

client에서 접근하기
서버 내용 내려받기
다음 명령을 통해서 서버의 내용을 다운 받을 수 있다.

shell> rsync -avz home.inzoo.co.kr::www.wangsy target_dir/
그리고 아래 명령을 통해서 로컬에서 수정된 파일을 서버에 반영할 수 있다.

shell> rsync -avz target_dir/ home.inzoo.co.kr::www.wangsy
위에서 -avz의 의미는 각각 다음과 같다. 자세한 사항은 rsync 홈페이지의 메뉴얼에서 확인할 수 있다.

-a, --archive archive mode
-v, --verbose increase verbosity
-z, --compress compress file data
-u, --update update only (don't overwrite newer files)
약간의 문제
client의 ip와 hostname이 lookup되지 않으면 remote호스트에서 접근을 허용하지 않는 문제가 있다. 이는 ADSL로 접속할 경우 연결이 되지 않게 되는 문제가 발생한다. 서버로 바로 접속하는 것 보다는 위 처음 방식인 ssh를 통한 접속 방법이 좀더 보안상 안전하기 때문에 이방법을 이용하는것이 좋을듯 하다.

로컬 호스트 시스템을 백업하는 방법으로는 tar 아카이브를 이용하여 묶거나 압축하는 방법이 있고, cpio, dump, dd 유틸리티를 이용하여 하드 디스크를 백업하는 방법이 있다.
이번호에서는 이러한 유틸리티를 사용하지 않고, 미러링(Mirroring) 기능을 이용하여 로컬시스템 또는 원격서버의 데이터를 그대로 복사하여 백업하는 방법에 대해서 알아봅니다......

# 1. 미러링(Mirroring)

레드햇 리눅스 사이트의 다운로드 페이지에 보면 FTP 미러 사이트들이 많이 링크되어 있
음을 발견할 수 있다. 미러 사이트는 주 사이트의 데이터를 그대로 옮겨와 주 사이트와 똑
같은 서비스를 제공하는 것이다. 원격 서버의 데이터를 원본 그대로 복사해 와서 원격 서
버와 똑같은 데이터 상태를 유지시키는 것을 미러링(Mirroring) 이라 하는데 다른 표현으로
는 서버 동기화(server syncronization)라고도 한다.
미러링에 의해서 원격 서버의 데이터가 변하면 미러링 서버도 그에 따라서 변하게 되며
항상 미러링 서버는 원격 서버의 동일한 데이터 상태를 유지하게 된다. 미러링은 로컬 시스
템의 데이터를 백업할 때도 적용할 수 있으며 서버마다 동일한 데이터 구조를 유지하고자
할 때 이 방법이 사용된다.

# 2. 미러링 도구(rsync)

여러대의 서버를 분산하여 서버를 동기화하는데 rsync 유틸리티가 많이 사용된다.
rsync는 루트의 권한없이 서버로부터 데이터로 빠르게 전송받을 수 있으며, 원격 서버와
미러 서버와 전송 데이터를 비교하여 변화된 데이터를 저장할 수 있다.
또한 SSH를 이용하면 rsync 서버가 구축되어 있지 않아도 미러링을 할 수 있는 이점이 있
다.

# 3. rsync 설치

레드햇 리눅스 9에서는 최신 버전의 rsync RPM 패키지를 지원하므로 간단히 RPM 패키지
를 설치하여 사용한다. 그러면 우선, rsync 패키지가 설치되어 있는지를 확인해 본다...
[root@localhost root]# rpm -qa | grep rsync
rsync-2.5.5-4
[root@localhost root]# _ ----->대기중인 커서를 의미함.

상기 화면과는 달리 아무런 rsync 버전 정보가 표시되지 않는다면 rsync가 시스템에 설치
되어 있지 않는 것이므로, rsync-2.5.5-4.i386.rpm 패키지를 구해 다음과 같이 설치한다.
설치전에 반드시 미리 구한 패키지가 있는 디렉토리로 들어간후 설치하는것을 잊지 말자.
[root@localhost RPMS]# rpm -ivh rsync-2.5.5-4.i386.rpm
준비 중... ############################ [100%]
1 : rsync ############################ [100%]
[root@localhost RPMS]# _
@ [참고사항] - rsync RPM 패키지 설치시 의존성 오류가 나올때
rsync RPM 패키지는 redhat-lsb 패키지와 의존성을 가지므로, 설치시
의존성 오류가 나올 때는 redhat-lsb-1.3-1.i386.rpm을 먼저 설치한 후
에 rsync 패키지를 설치한다.

# 4. SSH를 이용한 원격 서버 데이터 미러링

rsync 서버를 구축하지 않은 상태에서 rsync로 SSH를 이용하여 데이터를 백업하는 방법
은 다음과 같다. rsync 사용법에 관한 자세한 것은 잠시 후에 살펴보기로 하자...

rsync -avzr --delete -e ssh 원격서버:데이터경로 백업경로

그러면 192.168.1.13 클라이언트에서 192.168.1.1 원격 서버의 FTP 데이터를 SSH를 이용
하여 미러링하는 방법은 다음과 같다...
[root@localhost root]# rsync -avz --delete -e ssh 192.168.1.1:/ftp/pub/redhat9/
/mirror/redhat9
root's password:
receiving file list ... done
./
shrike-i386-disc1.iso
shrike-i386-disc2.iso
shrike-i386-disc3.iso
wrote 64 bytes read 1855717755 bytes 2449792.50 bytes/sec
total size is 1855094784 speedup is 1.00
[root@localhost root]# _

원격 서버의 주소와 미러링하고자 하는 데이터의 경로를 지정한 후에 -e ssh 옵션을
사용하여 원격 서버에 접속을 하게 되면 패스워드를 묻게 되는데, 원격 서버의 루트 패스
워드를 입력한다. 만일 일반 사용자 계정으로 이 명령을 수행한다면 원격 서버에도 동일한
계정이 존재하여야 하며, 원격 서버의 계정 패스워드를 입력한다.
SSH로 원격 서버에 접속이 이뤄지면 rsync에 의해서 원격 서버의 데이터를 미러링 서버
의 지정된 경로로 다운로드됨을 볼 수 있다.
@ [ 참고사항 ] - SSH를 이용한 rsync 데이터 동기화를 위한 원격 서버의 환경
클라이언트에서 rsync로 SSH를 이용하여 원격 서버에 접속하기 전에
원격 서버는 반드시 SSH 서버가 작동하고 있어야 접속이 가능하다.
즉, /etc/init.d/sshd restart를 실행하여 클라이언트가 SSH 서버에 접
속할 수 있도록 미리 준비해 놓고 있어야 한다는 예기다....

# 5. rsync 서버 설정(/etc/rsyncd.conf)
앞서 SSH를 이용하여 미러링을 하는 방법에 대해 알아보았다. SSH 서버가 구축되지 않은
원격 서버에서는 클라이언트가 미러링할 수 있도록 rsync 서버를 구축해야 한다. rsync 서
버의 설정 파일은 /etc/rsyncd.conf 파일인데, 이 파일은 자동으로 생성되지 않으므로 사
용자가 직접 만들어 사용해야 한다. 이 파일의 설정 형식은 다음과 같다.

[rsync 서비스명]
comment = rsync서버에 대한 설명
path = 미러링될 데이터의 경로
uid = 사용자 ID
gid = 그룹 ID
use chroot = yes / no
read only = yes /no
host allow = 아이피주소
max connections = 최대접속횟수
timeout = 초단위의 시간

① [rsync 서비스명] : rsync 서비스의 이름(모듈명)이다. 사용자가 원하는 형태로 서비스명
을 지정할 수 있다. 예) rh90
② comment : rsync 서비스에 대한 설명이다. 예) Red Hat Linux 9.0 Mirror
③ path : 미러링 서비스 될 데이터의 경로를 지정한다. 예) /data/linux90
④ uid, gid : 각각 파일 전송하는 사용자와 그룹의 아이디로, 익명 접속이 가능하도록 기본값
은 nobody로 설정되어 있으므로 이 값을 그대로 사용한다.
⑤ use chroot : path로 지정된 경로를 root 상위 디렉토리로 사용한다. 사용자가 다른 상위
디렉토리로 접근하지 못하도록 하기 위해서 보안상 필요로 하므로 yes로 설
정한다.
⑥ read only : 클라이언트가 서버에서 데이터만 다운로드 하는 경우에는 이 옵션을 yes로 설
정하여 읽기 전용 권한을 부여해야 한다. 만일 업로드가 가능하도록 하려면
no로 설정하지만 특별한 경우가 아니라면 yes로 설정한다.
⑦ host allow : 접속 호스트를 제한하지 않으면 누구나 데이터를 가져갈 수 있기 때문에 익
명의 FTP 미러 서버가 아니라면 보안상 rsync 서버에 접속 가능한 호스트의
아이피를 지정하는 것이 안전하다.
⑧ max connections : 동시에 접속 가능한 접속횟수를 설정한다. 무제한은 0으로 설정한다.
⑨ timeout : 클라이언트의 접속이 idle 상태에 있을 때 접속을 끊어버릴 시간을 설정한다.
기본값은 60초이다.

다음은 지금까지 살펴본 설정을 가지고 작성한 /etc/rsyncd.conf 예제 설정 파일이다.
[root@localhost /]# cat > /etc/rsyncd.conf
[rh9iso]
comment = Red Hat Linux 9 ISO Mirror
path = /data/ftp/pub/redhat9
uid = nobody
gid = nobody
use chroot = yes
read only = yes
host allow = 192.168.1.13
max connections = 5
timeout = 60

[root@localhost /]# _

# 6. /etc/xinetd.d/rsync 설정

rsync 서비스는 슈퍼데몬 xinetd에 의해서 작동하기 때문에 /etc/xinetd.d/rsync 파일을
설정해 주어야 한다. RPM 패키지 설치시 이 파일이 제공되므로 이 파일 가운데에서 다음
화면과 같이 disable = yes를 disable = no로 변경한다.

-------------------------------------------------------------------------------
root@localhost:/
-------------------------------------------------------------------------------
service rsync
{
disable = no
socket_type = stream
wait = no
user = root
server = /usr/bin/rsync
log_on_failure += USER ID
}
_ ----->대기중인 커서를 의미함.
~

[영어][완성][두벌식] 11,0-1 모두
--------------------------------------------------------------------------------
그런 다음 xinetd 슈퍼 데몬을 다시 실행하여 rsync서비스가 작동될 수 있도록 한다.
[root@localhost /]# /etc/init.d/xinetd restart
xinetd 를 정지함 : [ 확인 ]
xinetd (을)를 시작합니다 : [ 확인 ]
[root@localhost /]# _

rsync 서비스는 873 서비스 포트를 이용하므로, 텔넷으로 이 포트로 접속하여 rsyncd 정
보가 나오는지를 확인한다. 만일 접속이 이뤄지지 않는다면 방화벽을 점검하거나
/etc/rsyncd.conf 파일의 설정이 정확한지를 체크한다.

[root@localhost /]# telnet localhost 873
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1)
Escape character is '^]' .
@RSYNCD: 26
_ ----->대기중인 커서를 의미함.

# 7. rsync 사용법

SSH를 이용하여 rsync 미러링하는 방법에서 간단히 명령의 쓰임에 대해서 이미 살펴봤다.
그러면 rsync의 사용법에 대해서 자세히 알아보자.........

rsync [옵션] rsync서버주소::서비스명 미러경로

rsync에서 자주 사용되는 옵션은 -avzr이다. -a 옵션은 아카이브 모드이며, -v 옵션은
처리과정을 화면상에 출력되도록 하는 것이고, -z는 전송시 압축모드이며, -r 옵션은 하위
디렉토리를 의미하는 옵션이다. 그외 자세한 옵션은 man 페이지를 참고하자.
그러면 rsync로 미러링하는 방법을 연습해 보기로 하자....^_^*

7-1. rsync 서비스 모듈(서비스명과 설명) 알아보기

앞서 작성한 /etc/rsyncd.conf 예제 파일을 통하여 원격 rsync 서버에서 어떤 서비스를
현재 제공하는지를 알아보고자 할 때는 다음과 같은 명령을 실행한다.

rsync 서버주소::

[root@localhost root]# rsync 192.168.1.1::
rh9iso Red Hat Linux 9 ISO Mirror
[root@localhost root]# _
이 때 출력되는 것은 /etc/rsyncd.conf 파일에서 서비스명(모듈명)과 comment로 설정
된 메시지이다.

7-2. 로컬 시스템 데이터 백업

rsync를 이용하여 로컬 시스템의 데이터를 백업하려면 다음과 같은 명령을 사용한다.

rsync -avzr --delete 백업소스경로 백업될경로

--delete 옵션은 rsync서버의 백업할 데이터와 클라이언트의 데이터와 비교하여 변경
된 데이터를 추가하거나 삭제하고자 할 때 사용하는 데이터 비교 옵션이다.
그러면 /rh9hwp 디렉토리에 있는 파일을 /mirror/rh9hwp_backup 디렉토리로 백업해
보자.........
[root@localhost root]# rsync -avzr /rh9hwp/ /mirror/rh9hwp_backup
building file list ... done
created directory /mirror/rh9hwp_backup
./
맨드레이크 9.1.hwp
명령어사전 .hwp
제1부설치편 (60-151p).hwp
제2부 (152-731p).hwp
제3부 (732-1115p).hwp
wrote 36854994 bytes read 100 bytes 1890004.82 bytes/sec
total size is 42531514 speedup is 1.15
[root@localhost root]# ls /mirror/rh9hwp_backup
맨드레이크 9.1.hwp 제1부설치편 (60-151p).hwp 제3부 (732-1115p).hwp
명령어사전 .hwp 제2부 (152-731p).hwp
[root@localhost root]# _

/mirror/rh9hwp_backup 디렉토리로 데이터가 백업되고 있음을 확인할 수 있다.

7-3. 원격 서버의 데이터 백업

rsync -avz 서버주소::모듈명(서비스명) 백업될경로

이번에는 원격 서버의 레드햇리눅스9 배포판 이미지 파일을 미러링을 해보자.... 먼저
rsync 서버주소::를 실행하여 모듈명을 확인하여 원격 서버에 접속해 미러링되게 하면
된다.

[root@localhost root]# rsync 192.168.1.1::
rh9iso Red Hat Linux 9 ISO Mirror
[root@localhost root]# rsync -avz 192.168.1.1::rh9iso /mirror/redhat9
receiving file list ... done
./
shrike-i386-disc1.iso
shrike-i386-disc2.iso
shrike-i386-disc3.iso
wrote 118 byets read 1855717775 bytes 4995202.94 bytes/sec
total size is 1855094784 speedup is 1.00
[root@localhost root]# _
이 게시물을..
목록
2008.05.15 16:55:31 수홍이야[home]
path = /home
comment = webservice-dir
uid = root
gid = root
use chroot = yes
read only = yes
hosts allow = 58.120.226.8 58.120.226.142
max connections = 3
timeout = 300

path = /usr/local/mysql
comment = mysqldata-dir
uid = root
gid = root
use chroot = yes
read only = yes
hosts allow = 58.120.226.8 58.120.226.142
max connections = 3
timeout = 300
 
[apache]
path = /usr/local/apache
comment = mysqldata-dir
uid = root
gid = root
use chroot = yes
read only = yes
hosts allow = 58.120.226.8 58.120.226.142
max connections = 3
timeout = 300
 
 
이 댓글을..
 2008.05.15 21:13:15 수홍이야 
write failed on BackUpData/carpr2_public_html3/Dealer/image/program/pcanywhere10.zip : Success
rsync error: error in file IO (code 11) at receiver.c(243)                                    
rsync: connection unexpectedly closed (2034656 bytes read so far)                            
rsync error: error in rsync protocol data stream (code 12) at io.c(150)      
------------------> 용량이 다 차서 더이상 백업을 받지 못함.                
 
[root@CarPR root]# rsync -avz 211.224.128.142::photo /home1/photo/photo/
rsync: server sent "" rather than greeting
rsync error: error starting client-server protocol (code 5) at main.c(924)
------------------> 방화벽 점검... xinit에서 실행하므로 /etc/hosts.allow  /etc/hosts.deny 점검..
 
[root@CarPR root]# rsync -avz 211.224.128.142::photo /home1/photo/photo/
rsync: failed to connect to 211.224.128.142: Connection refused
rsync error: error in socket IO (code 10) at clientserver.c(97)
------------------> 방화벽에 설정확인
 
rsync: read error: Connection reset by peer (104)
rsync error: error in rsync protocol data stream (code 12) at io.c(515)
------------------>  데몬이 돌아가는지 또는 방화벽에 설정확인(hosts.allow)
 
@ERROR: chroot failed
rsync: connection unexpectedly closed (0 bytes received so far) [receiver]
rsync error: error in rsync protocol data stream (code 12) at io.c(420)
------------------>  해당디렉토리에 접근권한 확인,또는 경로가 잘못된 경우 
이 댓글을..
 2008.05.15 21:24:02 수홍이야****************** rsync Error ***[참고]************************************ 
 
failed to connect to 211.113.46.141 - Connection refused 
 
==> rsync 가 실행이 않되던가, 접속이 막혀 있는 경우다. 
 
read error: Connection reset by peer 
rsync error: error in rsync protocol data stream (code 12) at io.c(163) 
 
==> /etc/rsyncd.conf 파일이 없어서 나는 에러다. 
파일명을 잘 확인해 본다.. ^^ 
 
==> 또는 /etc/hosts.allow 에 접속이 허가 되었는지 살핀다. 
추가
sshd : 58.120.226. 
 
 
 
client: nothing to do 
 
==> rsyncd.conf 에서 use chroot 랑 erad only 를 제거했다. 이 댓글을..
 2008.05.16 09:43:39 수홍이야## 58.120.226.113
rsync -avz 59.120.226.113::home /home2/113-server/home
rsync -avz 58.120.226.113::mysql /home2/113-server/mysql
rsync -avz 58.120.226.113::apache /home2/113-server/apache
이 댓글을..
 2008.05.19 18:50:49 수홍이야/usr/bin/rsync -avuz 211.***.***.**::etc /home/backup/etc 
rsync: failed to connect to 211.***.***.**: Connection timed out (110) 
rsync error: error in socket IO (code 10) at clientserver.c(94) 
 
일때 
 
 
rsync stream tcp nowait root /usr/bin/rsync rsyncd --daemon 
 
요렇게 데몬에 올려주고나서 성공!!! ㅋㅋㅋㅋ 이 댓글을..
 2008.05.21 17:13:15 수홍이야Chapter 2: How to setup rsync for anonymous mirroring
 
2.1: Compilation
Get and compile the latest rsync from either the authors site <a href="ftp://samba.anu.edu.au/pub/rsync" rel="nofollow">ftp://samba.anu.edu.au/pub/rsync</a> or one of the mirror-sites 
 
 
ftp://sunsite.auc.dk/pub/unix/rsync 
ftp://ftp.sunet.se/pub/unix/admin/rsync 
ftp://ftp.fu-berlin.de/pub/unix/network/rsync 
Or naturally <a href="//samba.anu.edu.au/rsyncftp/" rel="nofollow">rsync://samba.anu.edu.au/rsyncftp/</a> 
 
2.2: Configuration
You should read the rsyncd.conf manual page for more information. 
 
When using rsync in daemon mode, it uses a single configuration file, which is by default /etc/rsyncd.conf, but this can be changed by the command line by option --config FILE. 
 
The config is in the same format as the samba config file. An example follows: 
 
 
motd file = /etc/motd
max connections = 25
syslog facility = local3
 
[ftp]
        comment = ftp area
        path = /pack/ftp
        read only = yes
        list = yes
        uid = nobody
        gid = nobody
[tmp]
	comment = temporary file area
	path = /tmp
	read only = no
	list = yes
	hosts allow = 192.168.2.0/24 127.0.0.0/8 *.anu.edu.au
	auth users = tridge, susan
	secrets file = /etc/rsyncd.secrets           
 
The example shows, that there is a global section at the top followed by definitions for each exported "module". Any non-global option set in the global section changes the default for the option. Each option is explained below: 
 
Global options: 
 
 
motd file: 
Names a text file, message of today, which will be displayed to clients just before the file transfer begins. It should be located in the global section. 
 
max connections: 
Maximum allowed concurrent clients. 
 
lock file: 
Location of the lock file [purpose?] 
 
syslog facility: 
The numeric value of the syslog facility to log connections and statistics to. These values is normally defined in the syslog manual page. 
Local/Module options: 
 
 
 
comment: 
Names the module. If list is set to yes, this name will be showed when the client requests a list of exported modules. 
 
path: 
Defines the root of the file tree, which should be exported. Rsync will chroot to this directory. 
 
read only: 
Defines if the modules should be read only or not. Until authentication is implemented, it is recommended to set this to yes 
 
list: 
Defines if the module should show up, when a client requests a list of modules. 
 
uid: 
The user id rsync will change to after having performed a chroot. For anonymous access, this is often the user id of nobody. 
 
gid: 
The group id rsync will change to after having performed a chroot. For anonymous access, this is often the group id of nobody. 
 
hosts allow: 
List of hosts allowed to connect to this module as either hostnames (with * wildcard) or IP/mask 
 
hosts deny: 
List of hosts denied to connect to this module 
 
auth users: 
List of users who can authenticate 
 
secrets file: 
The name of a file containing username:password (the password is in cleartext). 
Remark, that the rsync daemon performs a chroot() system call to the path defined in the config file, so all files served must be contained within the path (no symlinks to outside the path). For anonymous rsync access, a typical use is to let the path be the anonymous ftp root directory. 
 
 
2.3: Launching
The rsync daemon uses a privileged TCP port (for security reasons). For your own convenience, it might be an advantage to add this port to your /etc/services or equivalent file. Add a line like: 
 
 
rsync 873/tcp
The daemon can be launched either via inetd or stand-alone. It checks whether stdin is a socket and if it is then it assumes it was launched via inetd. 
 
The rsync daemon is robust, so it is safe to launch it as a stand-alone server. The code that loops waiting for requests is only a few lines long then it forks a new copy. If the forked process dies then it doesn't harm the main daemon. 
 
The big advantage of running as a daemon will come when the planned directory cache system is implemented. The caching system will probably only be enable when running as a daemon. For this reason, busy sites is recommended to run rsync as a daemon. Also, the daemon mode makes it easy to limit the number of concurrent connections. 
 
You will have to make a startup script, which will run during system boot or you might even consider to launch it from init, if you have that possibility. The details on how this is done is left as an exercise as it is very OS dependent. 
 
 
2.3.1: Launching as stand-alone daemon
Make sure rsync gets started in the boot process by editing /etc/rc.local or making a startup script on SYSV platforms. The script should contain a line like: 
 
 
rsync --daemon
The rsync daemon will fork and continue to run in the background. Each new connection will make rsync fork to handle that request. 
 
 
2.3.2: Launching from inetd
If you choose to launch the rsync daemon from inetd then insert a line similar to this: 
 
 
rsync stream tcp nowait root /usr/bin/rsync rsyncd --daemon
Please notice, that the syntax varies between different vendors. The above line is valid for Solaris. 
 
Some inetd does not require a named port. If this is the case, then you can skip the step of editing /etc/services and just list the port number (default 873) directly in inetd.conf. 
 
After editing the /etc/inetd.conf remember to send a HUP signal to the inetd process. Watch for errors in the /var/adm/messages or similar file. 
 
 
2.4: Testing
Now that the installation is complete, you should test it. At the client end the syntax is nearly the same as normal rsync except that you use :: instead of :. 
 
Start by requesting a list of exported modules like this: 
 
 
bash$ ./rsync localhost::
Welcome to Fjall.
 
ftp             ftp area
tmp             temporary file area
 
The motd is shown followed by a list of available modules and their comments. 
 
Now try to sync a directory within one of the modules. 
 
If you get an error like failed to connect to localhost - Connection refused, then something properly went wrong in the inetd configuration. Watch for error in /var/adm/messages or similar file. Did you remember to reinitialize inetd? 
 
 
2.5: Logging
rsync logs to syslog in the /var/adm/messages file, but it can be configured to use any syslog facility. A typical use is to let it log to an unused facility, like LOCAL3 and then append a line like 
 
 
local3.info          /var/adm/rsync.log
to syslog.conf 
 
 
2.6: Examples on mirroring
When mirroring from a rsync enabled site, the mirroring is as simple as creating a cron job which daily (depending on the subject which are mirrored) launches rsync like this: 
 
 
rsync -a samba.anu.edu.au::sambaftp/ /disk1/mirrors/samba/
The mirroring will be far more efficient in both time and in bytes transfered. Watch the statistics at the end of a mirroring. 
 
 
2.7: Advanced installation
If you are running a busy site, it is worth to consider the impact of rsync daemon. The daemon make a high impact on the server in terms of both CPU and disk I/O. The disk I/O is similar to running a ftp server, but the CPU usage is higher. The CPU usage is due to the nature of rsync, where it will have to open every file and calculate checksums. In most cases, however, it only has to open and calculate checksums if it decides that a sync is necessary. So it will in fact use very little CPU to do a mirror run if no files (or not many files) have changed. 
 
You might take two approaches to control the impact: both limiting the concurrent number of clients and launch the daemon with a lower priority. 
 
To launch the daemon with a lover priority, a straight forward method is to create a wrapper around the real binary, and launch this wrapper instead. Such a wrapper could be as simple at this: 
 
 
#!/bin/sh
exec nice -19 /path/to/real/rsync $*
 
and then save the file and use this as your rsync daemon. This wrapper will work when launched from inetd and stand-alone. 
 
Any busy site should launch the daemon in stand-alone mode to be able to control the maximum number of concurrent clients. 
 
이 댓글을..