介紹
rsync命令是一個遠程數據同步工具,可通過LAN/WAN快速同步多臺主機間的文件。rsync使用所謂的“rsync算法”來使本地和遠程兩個主機之間的文件達到同步,這個算法只傳送兩個文件的不同部分,而不是每次都整份傳送,因此速度相當快。 rsync是一個功能非常強大的工具,其命令也有很多功能特色選項,我們下面就對它的選項一一進行分析說明。
常用場景
無密碼同步
服務端:vim /etc/rsyncd.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
#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 |
1
2
|
/usr/bin/rsync --daemon mkdir -p /web/rsync/share_data |
客戶端
1
|
rsync -avz --progress root@192.168.1.98::share_data /home/hadoop/share_data |
限制流量同步
1
|
rsync -avz --bwlimit=50 --progress root@192.168.1.98::share_data /home/hadoop/share_data |
有密碼同步
服務端
vim /etc/rsyncd.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
#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 |
1
2
3
|
echo "hadoop:password123" > /etc/rsyncd . passwd chmod 600 /etc/rsyncd . passwd mkdir -p /web/rsync/auth_data |
客戶端
1
2
3
|
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 |
或者是
1
2
|
export RSYNC_PASSWORD= "password123" rsync -avz --progress hadoop@192.168.1.98::auth_data /home/hadoop/auth_data |
寫入同步
服務端
vim /etc/rsyncd.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
#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 |
1
|
mkdir -p /web/rsync/write_data |
客戶端
1
2
3
|
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或者網段
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
#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 |
客戶端 https://download.samba.org/pub/rsync/rsync.html
服務端 https://download.samba.org/pub/rsync/rsyncd.conf.html
總結
以上就是這篇文章的全部內容了,希望本文的內容對大家的學習或者工作能帶來一定的幫助,如果有疑問大家可以留言交流。謝謝大家對服務器之家的支持。
原文鏈接:http://www.cnblogs.com/ggjucheng/p/5474038.html