linux
리눅스 파일 시스템 동기화 lsync
fendys
2021. 11. 5. 18:42
반응형
패키지 설치
### install pkg
yum install lsyncd lua rsync
로컬 서버 2개 패스 동기화 및 벤드위스 제한 및 오너쉽 변경
settings {
logfile="/var/log/lsyncd/lsyncd.log",
statusFile="/var/log/lsyncd/lsyncd-status.log"
}
sync {
default.rsync,
source="/lsync-data",
target="/lsync-backup",
rsync = {
owner = true,
group = true,
chown = "nike:nike",
_extra = {"--bwlimit=102400"}
}
}
sync {
default.rsync,
source="/lsync-backup",
target="/lsync-data",
rsync = {
owner = true,
group = true,
chown = "rebook:rebook",
_extra = {"--bwlimit=102400"}
}
}
내부 디렉토리 양방향 동기화
#/etc/lsync.conf
settings {
logfile="/var/log/lsyncd/lsyncd.log",
statusFile="/var/log/lsyncd/lsyncd-status.log"
}
sync {
default.rsync,
source="/reni-test",
target="/reni-test01"
}
sync {
default.rsync,
source="/reni-test01",
target="/reni-test"
}
두 서버간의 동기화 방법
reni-glusterfs01 /lsync-data -> reni-glusterfs02 /lsync-data로 동기화
마스터와 슬레이브 서버 간의 키 기반 인증을 활성화합니다.
1 키생성
[root@reni-glusterfs01 etc]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:ldIWAvWzqfFxOio7h1aZ8/qzcGHq0C+cdTT71+kM11k root@reni-glusterfs01
The key's randomart image is:
+---[RSA 2048]----+
| .oo . |
| + o |
| . B |
| + +o |
| So*..o E|
| .=*.=o +|
| .+===. o o+|
| =o==o. =.o|
| ..=+++o .+ |
+----[SHA256]-----+
2. 키 전달
[root@reni-glusterfs01 .ssh]# ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.0.20
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '192.168.0.20 (192.168.0.20)' can't be established.
ECDSA key fingerprint is SHA256:CC+96EMSVm//rIvMXuvcttuWpbQJlLqIA/vriJH2EK8.
ECDSA key fingerprint is MD5:55:0c:05:20:1f:94:12:9b:eb:10:86:7c:05:69:22:72.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@192.168.0.20's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'root@192.168.0.20'"
and check to make sure that only the key(s) you wanted were added.
[root@reni-glusterfs01 .ssh]# ssh 192.168.0.20
Last login: Mon Nov 8 19:47:11 2021 from 192.168.0.18
[root@reni-glusterfs02 ~]# exit
3. lsync.conf
[root@reni-glusterfs01 lsync-data]# cat /etc/lsyncd.conf
settings {
logfile="/var/log/lsyncd/lsyncd.log",
statusFile="/var/log/lsyncd/lsyncd-status.log"
}
sync {
default.rsync,
source="/lsync-data",
target="192.168.0.20:/lsync-data"
}
[root@reni-glusterfs01 lsync-data]#
4. USER 권한으로 설정
settings {
logfile = "/var/log/lsyncd/lsyncd.log",
statusFile = "/var/log/lsyncd/lsyncd-status.log"
}
sync {
default.rsyncssh,
source="/lsync-data",
host="fendys@192.168.0.20",
targetdir="/lsync-data"
}
추가 옵션 참고
sync { } 안쪽에 작성
###디렉토리 제외
exclude = {
‘/directory01’,
‘/directory02’
},
###포트를 변경
ssh = {
port = xxxx
},
###archive 소유권까지 동일하게 동기화
###compress는 압축 실행 여부
###verbose 로그 상세 기록
###extra = {"--bwlimit=51200"} 네트워크 벤드위스 설정
rsync = {
archive = true,
compress = false,
delete = false,
verbose = false,
_extra = {"--bwlimit=51200"}
}
반응형