«   2021/03   »
  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      
03-02 03:45
Notice
Today
9
Total
1,406,665
관리 메뉴

변군이글루

[리눅스] lsyncd와 rsync를 이용한 실시간 동기화(백업) 본문

* 리눅스

[리눅스] lsyncd와 rsync를 이용한 실시간 동기화(백업)

변군 변군이글루 2021. 1. 22. 15:28

lsyncd와 rsync를 이용한 실시간 동기화(백업)

 

테스트 환경

$ cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)

lsyncd, rsync 패키지 설치

[root@bvm111 : 원본 서버]

#lsyncd 패키지 설치
$ yum install -y lsyncd

#lsyncd.conf 파일
$ cat /etc/lsyncd.conf
----
-- User configuration file for lsyncd.
--
-- Simple example for default rsync, but executing moves through on the target.
--
-- For more examples, see /usr/share/doc/lsyncd*/examples/
--
sync{default.rsyncssh, source="/var/www/html", host="localhost", targetdir="/tmp/htmlcopy/"}

#lsyncd 서비스 활성화 및 시작
$ systemctl --now enable lsyncd.service

#lsyncd 로그로테이트 설정
$ cat /etc/logrotate.d/lsyncd
/var/log/lsyncd/*log {
	missingok
	notifempty
	sharedscripts
}

[root@bvm222 : 대상 서버]

#rsync 패키지 설치
$ yum install -y rsync

#rsyncd.conf 파일
$ cat /etc/rsyncd.conf
# /etc/rsyncd: configuration file for rsync daemon mode

# See rsyncd.conf man page for more options.

# configuration example:

# uid = nobody
# gid = nobody
# use chroot = yes
# max connections = 4
# pid file = /var/run/rsyncd.pid
# exclude = lost+found/
# transfer logging = yes
# timeout = 900
# ignore nonreadable = yes
# dont compress   = *.gz *.tgz *.zip *.z *.Z *.rpm *.deb *.bz2

# [ftp]
#        path = /home/ftp
#        comment = ftp export area

#rsyncd 서비스 활성화 및 시작
$ systemctl --now enable rsyncd.service

bvm111 서버에 bvm222 서버로 실시간 동기화

- 출발지 : bvm111, /apps/file

- 목적지 : bvm222, /apps/file

- 사용자 계정 : oracle

bvm222 서버 설정(rsyncd 설정)

$ vim /etc/rsyncd.conf
# /etc/rsyncd: configuration file for rsync daemon mode

# See rsyncd.conf man page for more options.

# configuration example:

# uid = nobody
# gid = nobody
# use chroot = yes
# max connections = 4
# pid file = /var/run/rsyncd.pid
# exclude = lost+found/
# transfer logging = yes
# timeout = 900
# ignore nonreadable = yes
# dont compress   = *.gz *.tgz *.zip *.z *.Z *.rpm *.deb *.bz2

# [ftp]
#        path = /home/ftp
#        comment = ftp export area
#

[filesync]
path = /apps/file
comment = filesync
uid = oracle
gid = oracle
use chroot = yes
read only = no
hosts allow = 111.111.111.111
max connections = 10
timeout 600

$ systemctl restart rsyncd.service

$ systemctl status rsyncd.service
● rsyncd.service - fast remote file copy program daemon
   Loaded: loaded (/usr/lib/systemd/system/rsyncd.service; enabled; vendor preset: disabled)
   Active: active (running) since 금 2021-01-22 15:36:37 KST; 3min 43s ago
 Main PID: 15328 (rsync)
   CGroup: /system.slice/rsyncd.service
           └─15328 /usr/bin/rsync --daemon --no-detach

 1월 22 15:36:37 bvm222 systemd[1]: Started fast remote file copy program daemon.
 1월 22 15:36:37 bvm222 rsyncd[15328]: rsyncd version 3.1.2 starting, listening on port 873

bvm111 서버 설정(lsyncd 설정)

$ vim /etc/lsyncd.conf
----
-- User configuration file for lsyncd.
--
-- Simple example for default rsync, but executing moves through on the target.
--
-- For more examples, see /usr/share/doc/lsyncd*/examples/
--
-- sync{default.rsyncssh, source="/var/www/html", host="localhost", targetdir="/tmp/htmlcopy/"}

settings {
        logfile = "/var/log/lsyncd/lsyncd.log",
        statusFile = "/var/log/lsyncd/lsyncd.status",
        insist = true,
        statusInterval = 10
}
sync {
        default.rsync,
        source = "/apps/file/",
        target = "222.222.222.222::filesync",
}

$ systemctl restart lsyncd.service

$ systemctl status lsyncd.service
● lsyncd.service - Live Syncing (Mirror) Daemon
   Loaded: loaded (/usr/lib/systemd/system/lsyncd.service; enabled; vendor preset: disabled)
   Active: active (running) since 금 2021-01-22 16:01:06 KST; 17s ago
 Main PID: 4434 (lsyncd)
    Tasks: 1
   Memory: 456.0K
   CGroup: /system.slice/lsyncd.service
           └─4434 /usr/bin/lsyncd -nodaemon /etc/lsyncd.conf

 1월 22 16:01:06 bvm111 systemd[1]: lsyncd.service failed.
 1월 22 16:01:06 bvm111 systemd[1]: Started Live Syncing (Mirror) Daemon.

*** lsyncd.conf 설정 파일에서 주석은 -- 입니다.

 

 

0 Comments
댓글쓰기 폼