rsync, lsyncd 를 이용한 서버 동기화
https://www.youtube.com/watch?v=S0UTSQsmCc4
SOURCE 서버에 다음과 같이 설치합니다.
# ssh-keygen
# cat /root/.ssh/id_rsa.pub
ssh-rsa AAAAB3Nz..........OGyCkT root@ip-172-31-41-225.ap-northeast-2.compute.internal
위의 내용을 복사하여 타겟 서버의 /root/.ssh/authorized_keys 에 추가합니다.
TARGET 서버에 다음과 같이 복사합니다.
# vi /root/.ssh/authorized_keys
아까 소스 서버에서 복사한 키를 하단에 추가로 붙여넣기 합니다.
(기존에 파일이 있다면 이 코드를 추가합니다.)
ssh-rsa AAAAB3Nz..........OGyCkT root@ip-172-31-41-225.ap-northeast-2.compute.internal
# ssh-keyscan -t rsa 255.1.2.3 > /root/.ssh/known_hosts
(255.1.2.3 은 타겟서버아이피)
# yum install epel-release
# yum install lsyncd
# vi /etc/lsyncd.conf
-- 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.log"
}
sync {
default.rsyncssh,
source="/home/ec2-user", -- 소스 서버 디렉토리
host="255.1.2.3", -- 타겟 서버 아이피 or 도메인
targetdir="/home/ec2-user", -- 타겟 서버 디렉토리
delete=true, -- 삭제시 타겟 서버에 반영하기(동기화 하기)
delay=1, -- 1초
rsync={
archive=true -- 사용자와 퍼미션 동기화 하기
}
}
설정 파일이 이상 있는지 확인하기
# lsyncd /etc/lsyncd.conf
08:05:08 Normal: --- Startup, daemonizing ---
위와 같이 정상 이라면
# systemctl start lsyncd
로그 확인하기
# tail -f /var/log/lsyncd/lsyncd.log
위와 같이 설정한후
소스 서버의 /home/ec2-user 에 파일이나 디렉토리를 생성(삭제)하면
타겟 서버의 /home/ec2-user 에 동기화 됩니다.
댓글 9개
고생이 많으시네요 ㅠㅠ
배우는 재미가 쏠쏠합니다. ㅎ
파일수정도 실시간 반영이 되나요??
아니면 생성 및 삭제만 반영이 되나요?
혹시 테스트 해보실 것이라면 결과 좀 알려주세요.
게시판 목록
개발자팁
질문은 QA에서 해주시기 바랍니다.
| 번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|---|
| 4856 | PHP | 7년 전 | 5730 | ||
| 4855 | jQuery | 7년 전 | 3234 | ||
| 4854 | jQuery | 7년 전 | 2225 | ||
| 4853 | jQuery | 7년 전 | 2825 | ||
| 4852 | MySQL | 7년 전 | 2993 | ||
| 4851 | jQuery | 7년 전 | 2339 | ||
| 4850 | jQuery | 7년 전 | 2569 | ||
| 4849 | jQuery | 7년 전 | 4307 | ||
| 4848 | PHP |
|
7년 전 | 4246 | |
| 4847 | jQuery | 7년 전 | 4019 | ||
| 4846 | jQuery | 7년 전 | 2630 | ||
| 4845 | jQuery | 7년 전 | 2151 | ||
| 4844 | jQuery | 7년 전 | 2298 | ||
| 4843 | jQuery | 7년 전 | 3054 | ||
| 4842 | jQuery | 7년 전 | 2898 | ||
| 4841 | jQuery | 7년 전 | 2228 | ||
| 4840 | jQuery | 7년 전 | 1565 | ||
| 4839 | jQuery | 7년 전 | 2466 | ||
| 4838 | jQuery |
이에스씨코리아
|
7년 전 | 2312 | |
| 4837 | jQuery | 7년 전 | 2161 | ||
| 4836 | jQuery | 7년 전 | 2086 | ||
| 4835 | jQuery | 7년 전 | 1817 | ||
| 4834 | jQuery | 7년 전 | 1865 | ||
| 4833 | jQuery | 7년 전 | 1992 | ||
| 4832 | jQuery | 7년 전 | 2183 | ||
| 4831 | jQuery | 7년 전 | 2362 | ||
| 4830 | jQuery | 7년 전 | 2629 | ||
| 4829 | jQuery | 7년 전 | 1802 | ||
| 4828 | jQuery | 8년 전 | 2743 | ||
| 4827 | jQuery | 8년 전 | 2281 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기