場景:
經過rsync將某教學平臺的課程文件同步到存儲上,實現備份和同步。
操做:
ssh登錄到待備份的服務器,查看rsync安裝狀況。
#rpm -qa|grep -i rsync
rsync-2.6.3-1
說明有安裝,再查看還有哪些rsync被安裝在此服務器:
# which rsync
/usr/bin/rsync
就這一個,如今刪除系統自帶的rsync,安裝新版本。
#rpm -e rsync-2.6.3-1
完成後再次測試rpm -qa|grep -i rsync,發現已經沒有rsync在了。
安裝:
進入目錄/usr/local/tools,經過wget下載:
#wget http://www.samba.org/ftp/rsync/src/rsync-3.0.9.tar.gz
http://www.samba.org/ftp/rsync/src/rsync-3.0.9.tar.gz
=> `rsync-3.0.9.tar.gz'
Resolving www.samba.org... 216.83.154.106, 2001:470:1f05:1a07::1
Connecting to www.samba.org|216.83.154.106|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 792,725 (774K) [application/x-gzip]
100%[====================================>] 792,725 52.49K/s ETA 00:00
08:28:26 (58.54 KB/s) - `rsync-3.0.9.tar.gz' saved [792725/792725]
下載完畢,開始解壓編譯安裝:
#tar zxvf rsync-3.0.9.tar.gz
#cd rsync-3.0.9
#./configure && make && make install
安裝完成後,rsync被安裝在
#/usr/local/bin
而後查看安裝的狀況:
#rsync -version
rsync version 3.0.9 protocol version 30
Copyright (C) 1996-2011 by Andrew Tridgell, Wayne Davison, and others.....
這樣表示正常安裝了。
開始配置,在/etc/下創建文件:
#vi /etc/rsyncd.conf
shell
#運行RSYNC守護進程的用戶 uid = root #運行RSYNC守護進程的組 gid = root #不使用chroot use chroot = no #最大鏈接數不限制 max connections = 0 #pid文件存放位置 pid file = /var/run/rsyncd.pid #鎖文件存放位置 lock file = /var/run/rsync.lock #日誌文件存放位置 log file = /var/log/rsyncd.log [logs] #要同步的目錄 path = /usr/local/tools #忽略無關的IO錯誤 ignore errors #只讀,不能上傳 read only = true #禁止查看文件列表 list = false #容許訪問服務的ip #hosts allow = 202.200.*.* #禁止訪問服務的ip #hosts deny = 0.0.0.0/32 #認證的用戶名,系統必須存在的用戶,可是密碼須要在secrets file 配置,不是系統的密碼。 auth users = root #認證用戶密碼文件,配置auth users的密碼 secrets file = /etc/backserver.pas
配置完成後,創建兩邊的shh互信連接:
#ssh-keygen -t rsa
服務器
Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa):回車 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: xxx:3b root@xxxxxx#cd /root/.ssh
The authenticity of host '202.200.*.* (202.200.*.*)' can't be established. RSA key fingerprint is ###############################:bb:91:63:5c:13. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '202.200.*.*' (RSA) to the list of known hosts. root@202.200.*.*'s password: id_rsa.pub 100% 223 0.2KB/s 00:00
完成後來到目標主機,修改vi /etc/ssh/sshd_config,找到下面內容修改: app
AuthorizedKeysFile .ssh/authorized_keys2 (這裏寫剛纔傳送過來的文件名)最後重啓目標主機的ssh:
#service sshd restart而後測試原主機和目標主機的連通狀況,看是否不須要密碼就能夠連接。
打開防火牆 iptables -i INPUT -p tcp --dport 873 -j ACCEPT iptables -L 結果以下: Chain INPUT (policy ACCEPT) target prot opt source destination ACCEPT tcp -- anywhere anywhere tcp dpt:rsync開始備份: