Tuesday, January 03, 2012
Synchronize files by rsync between two Linux hosts
有別於以往先手動交換主機間SSH的金鑰後再透過rsync於兩台主機間同步檔案,今天又學習到了一個新方法,在此稍做筆記。
需求:
將/var/www/html自動從HostA同步到HostB。
HostA: 10.10.2.126 (source)
HostB: 10.10.2.128 (destination)
Step:
1. 設定HostA(Destination):
1.1 確定有安裝rsync:
[root@server1 ~]# rpm -qa | grep -i rsyncrsync-3.0.6-5.el6_0.1.i686
1.2 編輯/etc/xinetd.d/rsync:
service rsync{disable = noflags = IPv6socket_type = streamwait = nouser = rootserver = /usr/bin/rsyncserver_args = --daemonlog_on_failure += USERID}
1.3 建立/etc/rsyncd.conf:
# any name you like[test]# destination directorypath = /home/backup# Hosts you allow to copy (specify source Host)hosts allow = 10.10.2.126hosts deny = *list = trueuid = rootgid = rootread only = false
1.4 重新啟動xinetd
[root@server1 ~]# /etc/init.d/xinetd restart正在停止 xinetd: [ 確定 ]正在啟動 xinetd: [ 確定 ]
2. 設定HostB(Source):
2.1 確定有安裝rsync:
[root@server1 ~]# rpm -qa | grep rsyncrsync-3.0.6-4.el5_7.1
2.2 執行rsync將檔案同步:
[root@server1 ~]# rsync -avz --delete /var/www/html/ 10.10.2.128::testsending incremental file list./proxy.pacproxy.pac.ipv4proxy.pac.ipv6wpad.dat -> proxy.pacssl/ssl/index.hrmlsent 3089 bytes received 174 bytes 6526.00 bytes/sectotal size is 5039 speedup is 1.54
Subscribe to:
Posts (Atom)