Rsync的基本用法及搭建~~~~
阿新 • • 發佈:2020-12-26
Rsync的基本用法及搭建
什麼是rsync
sync 是一款開源的、快速的、多功能的、可實現全量及增量的本地或遠端資料同步備份的優秀工具。Rsync軟體適用於unix/linux/windows等多種作業系統平臺。
傳統的 scp 和 cp 工具拷貝每次均為完整拷貝,而rsync除了可以完整拷貝外,還具備增量拷貝功能。因此,從同步資料的效能及效率上,Rsync工具更勝一籌。
一、官網
https://download.samba.org/pub/rsync/rsync.html
或
https://www.samba.org/ftp/rsync/rsync.html
伺服器 | 客戶端 |
---|---|
192.168.131.80 | 192.168.131.81 |
二、簡單的搭建,測試
1.檢測本機有沒有安裝,並安裝
檢視本機有沒有安裝rsync:
rpm -qa | grep rsync
沒有的話安裝rsync:
yum -y install rsync
2.修改配置檔案
vim /etc/rsyncd.conf
uid = root
gid = root
# use chroot = yes 不使用chroot
max connections = 4 最大連線數為4
# pid file = /var/run/rsyncd.pid pid檔案的存放位置
exclude = lost+found/ 排除檔案
transfer logging = yes 使rsync伺服器使用ftp格式的檔案來記錄下載和上載操作在自己單獨的日誌中
timeout = 900 通過該選項可以覆蓋客戶指定的IP超時時間。通過該選項可以確保rsync伺服器不會永遠等待一個崩潰的客戶端。超時單位為秒鐘,0表示沒有超時定義,這也是預設值。對於匿名rsync伺服器來說,一個理想的數字是600
motd file = /etc/rsyncd/rsyncd.motd "motd file"引數用來指定一個訊息檔案,當客戶連線伺服器時該檔案的內容顯示給客戶,預設是沒有motd檔案的。該檔案有無都不影響rsync的正常使用。
log file = /var/log/rsyncd.log 日誌記錄檔案的存放位置
lock file = /var/run/rsyncd.lock 鎖檔案的存放位置
ignore nonreadable = yes 指定rysnc伺服器完全忽略那些使用者沒有訪問許可權的檔案。這對於在需要備份的目錄中有些檔案是不應該被備份者得到的情況是有意義的。
dont compress = *.gz *.tgz *.zip *.z *.Z *.rpm *.deb *.bz2 指定那些不進行壓縮處理再傳輸的檔案
[bing] 這裡是認證的模組名,在client端需要指定
path = /srv 需要做映象的目錄,不可缺少!
comment=bing 這個模組的註釋資訊
ignore errors 可以忽略一些無關的IO錯誤
read only = no 是否可以pull (下載)
write only = no 是否可以push (上傳)
list = no 不允許列檔案
auth users = bing 授權使用者
secrets file = /etc/rsyncd.passwd 使用者密碼的檔案路徑
hosts allow = * 允許所有主機連線
3.配置一個密碼檔案,授權並啟動
echo 'bing:123456'>/etc/rsyncd.passwd
chmod 600 /etc/rsyncd.passwd
啟動rsync
rsync --daemon --config=/etc/rsyncd.conf
4.測試從伺服器拉取檔案
伺服器:
[[email protected] ~]# cd /srv/
[[email protected] srv]# ls
[[email protected] srv]# touch ceshi.txt
客戶端:
[[email protected] mnt]# rsync -avzP [email protected]::bing /mnt
Password:
receiving incremental file list
./
ceshi.txt
0 100% 0.00kB/s 0:00:00 (xfr#1, to-chk=0/2)
sent 50 bytes received 117 bytes 66.80 bytes/sec
total size is 0 speedup is 0.00
[[email protected] mnt]# ls
ceshi.txt
5.從本地向伺服器傳檔案
客戶端
[[email protected] mnt]# touch chuansong
[[email protected] mnt]# rsync -avz /mnt/ [email protected]::bing
Password:
sending incremental file list
./
.updated
chuansong
sent 292 bytes received 65 bytes 142.80 bytes/sec
total size is 163 speedup is 0.46
伺服器
[[email protected] srv]# ll
總用量 0
-rw-r--r--. 1 root root 0 12月 25 14:17 ceshi.txt
-rw-r--r--. 1 root root 0 12月 25 14:19 chuansong