一環境
源伺服器:
10.0.1.232
同步到目标的伺服器
10.0.1.254
useradd rsync -s /sbin/nologin -M
[root@localhost pic]# yuminstall rsync xinetd –y
[root@localhost pic]# yum install rsync xinetd –y #安裝
vi /etc/xinetd.d/rsync #編輯配置檔案,設定開機啟動rsync
disable = no #修改為no
:wq! #儲存退出
/etc/init.d/xinetd start #啟動(CentOS中是以xinetd來管理Rsync服務的)
[root@localhost pic]# cat/etc/xinetd.d/rsync
# default: off
# description: The rsyncserver is a good addition to an ftp server, as it \
# allows crc checksumming etc.
service rsync
{
disable = no
flags =IPv6
socket_type =stream
wait = no
user = root
server =/usr/bin/rsync
server_args =--daemon
log_on_failure +=USERID
}
[root@localhost pic]# cat /etc/rsyncd.conf
#rsync_config_______________start
#created by wujianwnei
#QQ 604480554
##rsyncd.conf start##
uid = root
gid = root
port=873
use chroot = no
read only = no
list = no
max connections = 200
timeout = 300
auth users = tongbu_user
hosts allow = 10.0.1.232
#hosts deny =
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
secrets file = /etc/rsync.pass
motd file = /etc/rsyncd.Motd
[mhttongbu1]
path = /data/matula/pic/cover/
comment = mhttongbu1
[mhttongbu2]
path = /data1/pic/cov/
comment = mhttongbu2
在目标伺服器上開啟兩個同步子產品,指定同步源資料到目标伺服器上的兩個不同的目錄
建立使用者認證檔案
[root@localhost pic]# cat /etc/rsync.pass
tongbu_user:zy@test01@user
chmod 600 /etc/rsyncd.conf
chmod 600 /etc/rsync.pass
/etc/init.d/xinetd start #啟動
service xinetd stop #停止
service xinetd restart #重新啟動
在伺服器10.0.1.232上操作
vi /etc/sysconfig/iptables #編輯防火牆配置檔案
-A INPUT -m state --state NEW -m tcp -p tcp --dport873 -j ACCEPT
:wq! #儲存退出
/etc/init.d/iptables restart #最後重新開機防火牆使配置生效
whereis rsync #檢視系統是否已安裝rsync,出現下面的提示,說明已經安裝
rsync: /usr/bin/rsync/usr/share/man/man1/rsync.1.gz
yum install xinetd #隻安裝xinetd即可,CentOS中是以xinetd來管理rsync服務的
yum install rsync xinetd #如果預設沒有rsync,運作此指令進行安裝rsync和xinetd
vi /etc/xinetd.d/rsync #編輯配置檔案,設定開機啟動rsync
disable = no #修改為no
/etc/init.d/xinetd start #啟動(CentOS中是以xinetd來管理rsync服務的)
[root@mantu_hw data]# cat /etc/passwd.txt
zy@test01@user
[root@mantu_hw data]#chmod 600/etc/passwd.txt
在源伺服器上操作:
[root@mantu_hw test02]# ll /tmp/test01/
總用量 32
drwxr-xr-x 2 root root 4096 2月 13 15:08 2
drwxr-xr-x 2 root root 4096 2月 13 15:43 234
drwxr-xr-x 2 root root 4096 2月 13 15:08 3
drwxr-xr-x 2 root root 4096 2月 13 15:15 45
drwxr-xr-x 2 root root 4096 2月 13 15:43 4567
-rw-r--r-- 1 root root 4 2月 13 15:42 test03
-rw-r--r-- 1 root root 5 2月 13 16:05 test05
-rw-r--r-- 1 root root 3 2月 13 15:08 txt01
[root@mantu_hw test02]# rsync -avH --port=873--progress /tmp/test01 [email protected]::mhttongbu1--password-file=/etc/passwd.txt
此ip為目标伺服器的ip
sending incremental file list
test01/
test01/test03
4100% 0.00kB/s 0:00:00 (xfer#1, to-check=7/9)
test01/test05
5100% 0.41kB/s 0:00:00 (xfer#2, to-check=6/9)
test01/txt01
3100% 0.17kB/s 0:00:00 (xfer#3, to-check=5/9)
test01/2/
test01/234/
test01/3/
test01/45/
test01/4567/
sent 350 bytes received 89 bytes 67.54 bytes/sec
total size is 12 speedup is 0.03
在目标伺服器上檢視:
test01目錄以及下面的内容全部同步到目标伺服器的/data/matula/pic/cover/下
[root@localhost cover]# ll/data/matula/pic/cover/test01/
-rw-r--r-- 1 root root 3 2月 13 15:08 txt
]
本文轉自 wjw555 51CTO部落格,原文連結:http://blog.51cto.com/wujianwei/1962471