Rsync安裝與配置


rsync介紹:
rsync是一個提供快速增量文件傳輸的開源工具。其基於GNU General Public License 發佈,目前主要有 Wayne Davison (http://opencoder.net/)維護。
主頁:http://samba.anu.edu.au/rsync/
通過他所提供的功能,rsync是一個用來做備份或者鏡像的理想工具。
2009年的5月8好,rsync 3.0.6版本發佈,
rsync介紹(3.0.6)
rsync是一個Unix系統的的文件傳輸程序,通過使用“rsync 算法”,提供遠程文件同步的快速方法。顧名思義,rsync就是 remote sync。通過過程中,只是發送發生改變的文件,而不是發送全部的內容。現在是邊列表變備份(刪除)
他的特性如下:
1、可以更新整個目錄樹和文件系統;
2、可以保留文件的軟鏈接、硬鏈接、權限信息、屬主信息、設備和時間信息;
3、無須特殊權限即可安裝;
4、內部的流水線提高了多文件傳輸的速度;
5、可以使用ssh、rsh或者socket鏈接進行傳輸;
6、支持匿名傳輸;
環境介紹
Rsync server IP:192.168.81.128
Rsync client IP: 192.168.81.130
操作系統:centos5.3 32位
1、
檢查系統是否裝了rsync 和xinetd包
rpm -q rsync xinetd
如果沒有安裝就用 yum install rsync xinetd 裝上
2、
vi /etc/xinetd.d/rsync
disable         = no  <---------- change to yes
3、
Rsync server端相關配置
(1).在/etc/下創建三個文件
rsyncd.conf     rsyncd.motd     rsyncd.secrets
 
(2).新建配置文件
vi rsyncd.conf
read only = no
list = yes
uid = root                         #可以創建了備份用戶,也可用root,默認是nobody
gid = root
Use chroot =no                    #默認是yes(需root運行rsync)額外的安全保護
hosts allow = 192.168.81.0/24
#hosts deny =192.168.128.0/24
max connections = 10              #設置連接數爲10, 默認連接數不限制
log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsyncd.lock
motd file = /etc/rsyncd.motd      #歡迎文件,裏面的內容可以隨便寫,就是rsync client客戶端連接時顯示的歡迎詞
#define dirctory for rsync
[test]                              #模塊:rsync的客戶端
#comment = opt directory from 192.168.81.128
path =/opt/pub   #欲備份的文檔目錄
secrets file =/etc/rsyncd.secrets                 #密碼存放文件
auth users = test              #連接帳號,和系統帳號沒關係,服務器必須上存在此賬號
read only = no
 
(3).歡迎文件
[root@localhost test]# vi /etc/rsyncd.motd
Welcome to use the test rsync services!
 
(4).密碼文件
[root@localhost test]#vi /etc/rsyncd.secrets #密碼文件權限爲600,此步必須設置
test:test
(5).chmod 600 /etc/rsyncd.*
(6).運行rsync
rsync --daemon /etc/rsyncd.conf
rsync的路徑    rsync配置文件
 
 
4、Rsync client端相關配置
(1)安裝rsync包 ----yum install rsync
(2)創建密碼文件
[root@localhost ~]#vi /etc/rsyncd.secrets 
test#客戶端只需密碼無須用戶
注:此處密碼一定要與rsync服務器端密碼文件中密碼保持一致,並且應爲rsync客戶端密碼。
(3)chmod 600 /etc/rsyncd.secrets ----修改權限
如果沒有這步會報如下:
password file must not be other-accessible
continuing without password file
Password:

5、同步連接測試
[root@mail pub]# rsync -vzrtopg --progress --delete --password-file=/etc/rsyncd.secrets [email protected]::test /opt/pub/
receiving incremental file list
./
test.txt
           0 100%    0.00kB/s    0:00:00 (xfer#1, to-check=0/2)
 
sent 78 bytes  received 150 bytes  152.00 bytes/sec
total size is 0  speedup is 0.00
[root@mail pub]# ls
test.txt

測試成功
6、實現定時同步,假設凌晨2兩同步
vim crond.rsync
00 2 * * * rsync -vzrtopg --progress --delete --password-file=/etc/rsyncd.secrets [email protected]::test /opt/pub
crontab crond.rsync
crontab -e編輯現在有crontab
crontab -l
 
測試結果:
把rsync server端 的文件 同步到 rsync client相應的目錄下面
 
 

 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章