실시간 데이터 동기화를 위한 sersync와 rsync 설정 가이드

(1). 테스트 환경

원본 호스트: server1 192.168.5.101

대상 호스트: server2 192.168.5.102

목적: 실시간 데이터 동기화

sersync 기본 포트: 874, rsync 기본 포트: 873

(2). 테스트 절차

1)sersync 다운로드

wget https://sersync.googlecode.com/files/sersync2.5.4_64bit_binary_stable_final.tar.gz

또는 Windows에서 다운로드 후 원본 호스트 server1에 업로드합니다.

2)압축 해제

[root@server1 ~]# ls
anaconda-ks.cfg  sersync2.5.4_64bit_binary_stable_final.tar.gz
[root@server1 ~]# tar xvf sersync2.5.4_64bit_binary_stable_final.tar.gz  // 압축 해제
GNU-Linux-x86/
GNU-Linux-x86/sersync2
GNU-Linux-x86/confxml.xml
[root@server1 ~]# ls
anaconda-ks.cfg  GNU-Linux-x86  sersync2.5.4_64bit_binary_stable_final.tar.gz
[root@server1 ~]# mv GNU-Linux-x86 sersync  // 이름 변경
[root@server1 ~]# ls
anaconda-ks.cfg  sersync  sersync2.5.4_64bit_binary_stable_final.tar.gz

3)대상 호스트 server2에서 /etc/rsyncd.conf 설정 파일 및 비밀번호 파일 수정

[root@server2 ~]# cat /etc/rsyncd.conf 
uid = root
gid = root
address = 192.168.5.102
port = 873
hosts allow = 192.168.5.101/24
use chroot = yes
max connections = 5
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
motd file = /etc/rsyncd.motd
[data_backup]
path = /backup/data/web
comment = backup /data/web/
read only = false
list = yes
auth users = sync_user
secrets file = /etc/rsync.secret
[root@server2 ~]# cat /etc/rsync.secret 
sync_user:202202
[root@server2 ~]# chmod 600 /etc/rsync.secret

지정된 설정 파일로 rsync 데몬 프로세스 시작

[root@server2 ~]# rsync --daemon --config=/etc/rsyncd.conf
[root@server2 ~]# ps aux | grep rsync
root       1478  0.0  0.0 114740   564 ?        Ss   11:10   0:00 rsync --daemon --config=/etc/rsyncd.conf
root       1485  0.0  0.0 112720   980 pts/0    R+   11:12   0:00 grep --color=auto rsync

4)원본 호스트 server1에서 sersync 설정 파일 수정

[root@server1 sersync]# vim confxml.xml 
<?xml version="1.0" encoding="ISO-8859-1"?>
<head version="2.5">
    <host hostip="localhost" port="8008"></host>
    <debug start="false"/>
    <fileSystem xfs="false"/>
    <filter start="false">
        <exclude expression="(.*)\.svn"></exclude>
        <exclude expression="(.*)\.gz"></exclude>
        <exclude expression="^info/*"></exclude>
        <exclude expression="^static/*"></exclude>
    </filter>
    <inotify>
        <createFile start="false"/>
        <closeWrite start="true"/>
        <moveFrom start="true"/>
        <moveTo start="true"/>
        <attrib start="false"/>
        <modify start="false"/>
    </inotify>

    <sersync>
        <localpath watch="/data/web">
            <remote ip="192.168.5.102" name="data_backup"/>  // 대상 호스트 IP 주소 및 모듈명 수정
        </localpath>
        <rsync>
            <commonParams params="-artuz"/>
            <auth start="true" users="sync_user" passwordfile="/etc/rsync.secret"/>  // 활성화, 사용자명 및 비밀번호 파일 경로 수정
            <userDefinedPort start="false" port="874"/><!-- port=874 -->
            <timeout start="false" time="100"/><!-- timeout=100 -->
            <ssh start="false"/>
        </rsync>
        <failLog path="/tmp/rsync_fail_log.sh" timeToExecute="60"/><!--default every 60mins execute once-->
        <crontab start="false" schedule="600"><!--600mins-->
            <crontabfilter start="false">
                <exclude expression="*.php"></exclude>
                <exclude expression="info/*"></exclude>
            </crontabfilter>
        </crontab>
        <plugin start="false" name="command"/>
    </sersync>

비밀번호 파일 추가

[root@server1 sersync]# vim /etc/rsync.secret
202202
[root@server1 web]# chmod 600 /etc/rsync.secret

5)원본 호스트 server1에서 sersync 데몬 프로세스 시작

[root@server1 sersync]# /root/sersync/sersync2 -dro /root/sersync/confxml.xml 
시스템 파라미터 설정
실행:echo 50000000 > /proc/sys/fs/inotify/max_user_watches
실행:echo 327679 > /proc/sys/fs/inotify/max_queued_events
명령 파라미터 분석
옵션: -d      데몬으로 실행
옵션: -r      sersync 작업 전 로컬 파일을 원격 서버로 rsync
옵션: -o      설정 xml 파일 이름:  /root/sersync/confxml.xml
데몬 스레드 수: 10
xml 설정 파일 분석
호스트 ip : localhost     호스트 포트: 8008
데몬 시작, sersync 콘솔 뒤에서 실행
rsync 비밀번호 파일 사용:
사용자: sync_user
비밀번호 파일:         /etc/rsync.secret
xml 설정 파일 분석 성공
수동으로 /etc/rsyncd.conf max connections=0 설정해 주세요
sersync 작업 스레드 12  = 1(주 스레드) + 1(실패 재시도 스레드) + 10(데몬 서브 스레드) 
최대 스레드 수: 22 = 12(스레드 풀 수) + 10(서브 스레드)
cpu 사용률 조절을 위해 -n 파라미터 사용 권장
------------------------------------------
디렉토리를 재귀적으로 원격 서버로 rsync
작업 중 잠시 기다려 주세요...
실행 명령: cd /data/web && rsync -artuz -R --delete ./ sync_user@192.168.5.102::data_backup --password-file=/etc/rsync.secret >/dev/null 2>&1 
sersync 실행: 
감시 경로: /data/web

6)테스트

현재 대상 호스트 server2의 상태는 다음과 같습니다

[root@server2 ~]# ls /backup/data/web/
adm    crash  empty  gopher    lib    lock  mail  opt       run    tmp
cache  db     games  kerberos  local  log   nis   preserve  spool  yp

원본 호스트 server1의 /data/web/ 디렉토리에서 파일 조작

[root@server1 sersync]# cd /data/web/
[root@server1 web]# ls
adm    crash  empty  gopher    lib    lock  mail  opt       run    tmp
cache  db     games  kerberos  local  log   nis   preserve  spool  yp
[root@server1 web]# rm -rf adm/
[root@server1 web]# touch test_file.txt
[root@server1 web]# ls
test_file.txt  crash  empty  gopher    lib    lock  mail  opt       run    tmp
cache  db     games  kerberos  local  log   nis   preserve  spool  yp

대상 호스트에서 상태 확인

[root@server2 ~]# ls /backup/data/web/
test_file.txt  crash  empty  gopher    lib    lock  mail  opt       run    tmp
cache  db     games  kerberos  local  log   nis   preserve  spool  yp

태그: sersync rsync 실시간 동기화 리눅스 파일 동기화

7월 12일 01:48에 게시됨