rsync同步備份服務器架設

系統:centos5.4

軟件:rsync 
環境:server1: apache服務器  IP:192.168.1.10
      server2:  備份服務器    IP:192.168.3.140
目的:通過rsync自動同步server1的web文件(路徑/usr/local/apache/htdocs)到server2的/tmp/rsync_bak下
 
一 安裝配置rsync
1.1首先在在server2上通過yum安裝及配置rsync服務端
 
  1. [root@centos5 ~]# yum install rsync -y 
1.2 創建rsync配置文件
 
  1. [root@centos5 ~]# mkdir /etc/rsyncd 
  2. [root@centos5 ~]# cd /etc/rsyncd 
  3. [root@centos5 rsyncd]# touch rsyncd.conf rsyncd.motd  rsyncd.secrets 
上面3個文件分別是rsyncd.conf主配置文件,rsyncd提示文件,rsyncd用戶密碼配置文件
1.3 配置rsync相關的3個配置文件
 
  1. [root@centos5 rsyncd]# vi /etc/rsyncd.conf 
  2. motd file = /etc/rsyncd.motd 
  3. read only = no 
  4. list = yes 
  5. uid = root 
  6. gid = root 
  7. Use chroot =no 
  8. #hosts allow = 192.168.0.61 
  9. #hosts deny =192.168.128.0/24 
  10. max connections = 5 
  11. log file = /var/log/rsyncd.log 
  12. pid file = /var/run/rsyncd.pid 
  13. lock file = /var/run/rsyncd.lock 
  14. #define dirctory for rsync 
  15. [test] 
  16. path =/tmp/rsync_bak/ 
  17. #此路徑爲本機(rsync服務器端)存放同步過來文件的目錄 
  18. secrets file =/etc/rsyncd.secrets 
  19. auth users = test 
  20. read only = no 
  21. #如果有多臺服務器要同步備份可以設置多個,例如 
  22. #[test1] 
  23. #path =/tmp/rsync_bak1/ 
  24. #secrets file =/etc/rsyncd1.secrets 
  25. #auth users = test1 
  26. #read only = no 
  27.  
  28. [root@centos5 rsyncd]# vi /etc/rsyncd.motd 
  29. Welcome to use the test rsync services! 
  30.  
  31. [root@centos5 rsyncd]#vi /etc/rsyncd.secrets  
  32. #密碼文件權限爲600,此步必須設置 
  33. #用戶名和密碼格式:用戶名:密碼 
  34. test:test 
  35. [root@centos5 rsyncd]#chmod 600 /etc/rsyncd/rsyncd.* 
1.4 運行rsync
 
  1. [root@centos5 rsyncd]#rsync --daemon /etc/rsyncd/rsyncd.conf 
  2. [root@centos5 rsyncd]# ps -ef |grep rsyncd|grep -v grep 
  3. root     10396     1  0 14:30 ?        00:00:00 /usr/bin/rsync --daemon /etc/rsyncd/rsyncd.conf 
2.1 在server1上安裝rsyncd客戶端
 
  1. [root@centos5 ~]# yum install rsync -y 
 
2.2 客戶端上只需要配置密碼文件
 
  1. [root@centos5 ~]# mkdir /etc/ 
  2. [root@centos5 ~]# vi /etc/rsyncd/rsyncd.secrets 
  3. test 
  4. #此處的密碼必須匹配服務器端設置的密碼,並且此文件權限也需要修改成600 
  5. [root@centos5 ~]#chmod 600 /etc/rsyncd/rsyncd.secrets 
 
二 測試rsync同步
在server1上執行下面命令
 
  1. [root@test1 htdocs]# /usr/bin/rsync  -vzrtopg --progress --delete /usr/local/apache2/htdocs/ --password-file=/etc/rsyncd.secrets [email protected]::test 
  2. Welcome to use the test rsync services! 
  3.  
  4. sending incremental file list 
  5. ./ 
  6.            0 100%    0.00kB/s    0:00:00 (xfer#1, to-check=1041/1043) 
  7.            0 100%    0.00kB/s    0:00:00 (xfer#2, to-check=1040/1043) 
  8.  
  9. sent 311129 bytes  received 2154 bytes  626566.00 bytes/sec 
  10. total size is 145816024  speedup is 465.45 
 
三 設置定時同步
在server1上做如下操作
 
  1. [root@test1 ~]# vi rsyncd_crond 
  2. 0 0 5 * * /usr/bin/rsync  -vzrtopg --progress --delete /usr/local/apache2/htdocs/ --password-file=/etc/rsyncd.secrets [email protected]::test 
  3. [root@test1 ~]# crontab rsyncd_crond 
  4. [root@test1 ~]# crontab -l 
  5. 0 0 5 * *  /usr/bin/rsync -vzrtopg --progress --delete /usr/local/apache2/htdocs/ --password-file=/etc/rsyncd.secrets [email protected]::test 
如果要修改同步時間也可以修改
 
  1. [root@test1 ~]# crontab -e 進入後修改 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章