데이터를 동기화하는 방법으로는 NFS(Network File System)나 DRBD(Distributed Replicated Block Device)를 구축하는 방법이 있지만, 보다 간단하게 Lsyncd를 사용할 수도 있습니다.
우선 lsync데몬이 설치되어있는지 확인후 안되어있다면 설치해야 합니다.
rpm -qa | grep lsync
sudo yum install -y lsync
/etc/lsyncd.conf
### 로그 설정
settings {
#로그 파일 경로
logfile = "/var/log/lsyncd/lsyncd.log",
statusFile = "/var/log/lsyncd/lsyncd.status",
insist = true, #실패하더라도 재시도
statusInterval = 10 #10초에 한번씩 동기화
}
### 동기화 할 디렉토리 및 옵션 지정
sync {
#기본적으로 rsync 모드
default.rsync,
#동기화 시킬 데이터 위치
source = "/data/",
#동기화 할 타겟
target = "<동기화 대상서버 IP>::<'datasync'>",
#제외할 항목
exclude = { '*****' },
#동기화중 압축
rsync={
archive=true,
compress = true,
acls = true,
verbose = true
}
}
rpm -qa | grep rsync
sudo yum install -y rsync
/etc/rsyncd.conf
[datasync]
# 동기화 디렉토리
path = /data/
comment = data directory sync
uid = root
gid = root
use chroot = yes
read only = no
# 허용할 IP
hosts allow = <원본 데이터 서버 IP>
max connections = 10
timeout 600
리눅스 커널의 inotify로 파일시스템의 변경사항을 체크합니다.
Lsyncd는 내부적으로 inotify와 같은 파일 시스템 이벤트 감시 기능을 사용하여 파일 및 디렉토리 변화를 감지합니다.
inotify의 경우, 리눅스 시스템에서 사용하는 파일 시스템 감시 메커니즘이며, 이때 모니터링할 수 있는 최대 디렉토리 수는 inotify에서 할당된 watch limit에 의해 결정됩니다.
#파일을 편집하여 inotify가 감시할 수 있는 디렉토리 수를 증가
/proc/sys/fs/inotify/max_user_watches
#sysctl 사용해서 inotify가 감시할 수 있는 디렉토리 수를 증가
sudo sysctl fs.inotify.max_user_watches=99999
#변경 사항을 영구적으로 적용하려면 /etc/sysctl.conf 추가
fs.inotify.max_user_watches=99999
운영환경에서 각각의 WAS 및 서버들이 운영 NAS에 마운트되어있고 어떤 서비스를 실행하게 되면 NAS에 해당 데이터를 저장하게 되는구조로 되어있다.
위에 설명대로 NAS에서는 변경감지가 되지 않으니까 각각의 WAS서버에서 Lsyncd를 설치하여 변경감지를 시키고 이걸 하나의 서버에서 DR-NAS에다가 Rsyncd로 쓰는 구조라고 생각하면된다.
settings {
logfile = "/var/log/lsyncd/lsyncd.log",
statusFile = "/var/log/lsyncd/lsyncd.status",
insist = true, statusInterval = 10
}
sync {
default.rsync,
source = "/data/customer/doc/2024",
target = "10.10.10.1::mydata1",
}
sync {
default.rsync,
source = "/data/customer/img/2024",
target = "10.10.10.1::mydata1",
}
log file=/home/bpimanager/rsyncd/rsyncd.log
[mydata1]
path = /data_dr/
comment = pratice sync
uid = kim
gid = kim
use chroot = yes
read only = no
hosts allow = 10.10.10.0/24
max connections = 10
timeout 600
[mydata2]
path = /data_dr/
comment = pratice sync
uid = kim
gid = kim
use chroot = yes
read only = no
hosts allow = 10.10.10.0/24
max connections = 10
timeout 600