rsync命令是一個遠程數據同步工具,可經過LAN/WAN快速同步多臺主機間的文件。rsync使用所謂的「rsync算法」來使本地和遠程兩個主機之間的文件達到同步,這個算法只傳送兩個文件的不一樣部分,而不是每次都整份傳送,所以速度至關快。 rsync是一個功能很是強大的工具,其命令也有不少功能特點選項,咱們下面就對它的選項一一進行分析說明。html
服務端:vim /etc/rsyncd.confweb
#This is the rsync daemon configuration #global settings pid file = /var/run/rsyncd.pid port = 873 lock file = /var/run/rsyncd.lock log file = /var/log/rsync.log gid = root uid = root #module settings [share_data] path = /web/rsync/share_data use chroot = no max connections = 15 read only = yes write only = no list = no ignore errors = yes timeout = 120
/usr/bin/rsync --daemon mkdir -p /web/rsync/share_data
客戶端算法
rsync -avz --progress root@192.168.1.98::share_data /home/hadoop/share_data
限制流量同步vim
rsync -avz --bwlimit=50 --progress root@192.168.1.98::share_data /home/hadoop/share_data
服務端 ssh
vim /etc/rsyncd.conf工具
#This is the rsync daemon configuration #global settings pid file = /var/run/rsyncd.pid port = 873 lock file = /var/run/rsyncd.lock log file = /var/log/rsync.log gid = root uid = root #module settings [auth_data] path = /web/rsync/auth_data use chroot = no max connections = 15 read only = yes write only = no list = no ignore errors = yes timeout = 120 auth users = hadoop secrets file = /etc/rsyncd.passwd
echo "hadoop:password123" > /etc/rsyncd.passwd chmod 600 /etc/rsyncd.passwd mkdir -p /web/rsync/auth_data
客戶端oop
echo "password123" > /home/hadoop/rsyncd.passwd chmod 600 /home/hadoop/rsyncd.passwd rsync -avz --progress --password-file=/home/hadoop/rsyncd.passwd hadoop@192.168.1.98::auth_data /home/hadoop/auth_data
或者是ui
export RSYNC_PASSWORD="password123" rsync -avz --progress hadoop@192.168.1.98::auth_data /home/hadoop/auth_data
服務端spa
vim /etc/rsyncd.confcode
#global settings pid file = /var/run/rsyncd.pid port = 873 lock file = /var/run/rsyncd.lock log file = /var/log/rsync.log gid = root uid = root #module settings [write_data] path = /web/rsync/write_data use chroot = no max connections = 15 read only = no list = no ignore errors = yes timeout = 120 auth users = hadoop secrets file = /etc/rsyncd.passwd
mkdir -p /web/rsync/write_data
客戶端
echo "123" > /home/hadoop/write_file export RSYNC_PASSWORD="password123" rsync -avz --progress --delete /home/hadoop/write_file hadoop@192.168.1.98::write_data
限定IP或者網段
#global settings pid file = /var/run/rsyncd.pid port = 873 lock file = /var/run/rsyncd.lock log file = /var/log/rsync.log gid = root uid = root #module settings [write_data] path = /web/rsync/write_data use chroot = no max connections = 15 read only = no list = no ignore errors = yes timeout = 120 auth users = hadoop secrets file = /etc/rsyncd.passwd hosts allow = 192.168.2.32 192.168.1.0/24
常見場景例子
指定端口
rsync -avz --port=8081 --progress /home/hadoop/auth_data hadoop@192.168.1.98::auth_data
限速
rsync --bwlimit=100 -avz --progress /home/hadoop/auth_data hadoop@192.168.1.98::auth_data
限速100kb/s同步數據
Rsync經過SSH傳輸
rsync -e "ssh -p 22" --progress /home/hadoop/auth_data hadoop@192.168.1.98::auth_data
更多命令參考
客戶端 https://download.samba.org/pub/rsync/rsync.html
服務端 https://download.samba.org/pub/rsync/rsyncd.conf.html