- 论坛徽章:
- 6
|
view plainprint?
rsync -rp --bwlimit=3000 --progress --exclude "logs/" /usr/local/push_endsvr/ root@${ip}:/usr/local/spush_endsvr/
理解:从{ip}这台机器上用root用户连接远程rsync服务器和本机需要同步的目录/usr/local/push_endsvr 同步,
并作限定速度为3000KB,不需要同步logs目录!
关键参数解释:
rsync --help|grep bwlimit
--bwlimit=KBPS limit I/O bandwidth; KBytes per second
--progress show progress during transfer
--include=PATTERN don't exclude files matching PATTERN
--port=PORT specify double-colon alternate port number
实际测试情况如下:
view plainprint?
root@10.6.208.188:~/elink# rsync --bwlimit=3000 --progress --port=873 /root/elink/* elink@10.6.208.188:elink
elink's password:
jackxiang.txt
11 100% 0.00kB/s 0:00:00 (xfer#1, to-check=0/1)
sent 105 bytes received 42 bytes 32.67 bytes/sec
total size is 11 speedup is 0.07
里面是配置了从/root/elink这个目录向:/home/elink这个目录推送,后查看目录/home/elink的层次结构发现如下:
root@10.6.208.188:/home/elink# ls
elink
root@10.6.208.188:/home/elink# ls elink
elink
说明/root/elink/jackxiang.txt 中包含目录也给推送到了/home/elink下,形成/home/elink/elink/jackxiang.txt
说下配置:
首先,看下RpM包,你也可以自己安装,
张宴兄弟有两篇文章都是讲这个的:
http://blog.s135.com/post/259/
http://blog.s135.com/post/265/
我是机器本来就有这个RPM,于是,
root@10.6.208.188:~# rpm -ql rsync-2.6.8-36.8
view plainprint?
/etc/init.d/rsyncd
/etc/logrotate.d/rsync
/etc/rsyncd.conf --------------------------------------------------> [配置文件]
/etc/rsyncd.secrets
/etc/xinetd.d/rsync
/usr/bin/rsync --------------------------------------------------->[启动文件]
/usr/bin/rsyncstats
/usr/sbin/rcrsyncd
/usr/sbin/rsyncd
/usr/share/doc/packages/rsync
/usr/share/doc/packages/rsync/COPYING
/usr/share/doc/packages/rsync/README
/usr/share/doc/packages/rsync/tech_report.ps
/usr/share/doc/packages/rsync/tech_report.tex
/usr/share/man/man1/rsync.1.gz
/usr/share/man/man5/rsyncd.conf.5.gz
在安装目录中找到rsync.conf:/etc/rsyncd.conf
vi /etc/rsyncd.conf
view plainprint?
uid=elink
gid=elink
max connections=10
use chroot=no
log file=/var/log/rsyncd.log
pid file=/var/run/rsyncd.pid
lock file=/var/run/rsyncd.lock
hosts allow=172.25.38.31/10.6.208.188
[elink]
path=/home/elink
comment = my htdocs
ignore errors
read only = no
我是自己一台机器上做的测试,所以把这个自己的机器也给加上即可,才能一台机器上实现rsync同步喔。
否则就是:
warning: Connecting to 10.6.208.188 failed: Connection Refused! 这种情况会出现。
添加这个用户的帐号和组:
这个不明白可以看下这个URL:http://www.justwinit.cn/post/2581/
groupadd elink -g 48 useradd elink -u 48 -g 48 chmod +w /home/elink chown elink:elink /home/elink
启动和关闭该服务:
1)启动rsync服务器端
/usr/bin/rsync --daemon
Rsync server会打开一个873 端口,等待客户端去连接。
加入inetd.conf
编辑/etc/services,加入rsync 873/tcp,指定rsync的服务端口是873。
编辑/etc/inetd.conf,加入rsync stream tcp nowait root
启动和判断是否成功,如下:
/bin/rsync rsync --daemon
root@10.6.208.188:/home# netstat -atlunp|grep 873
tcp 0 0 0.0.0.0:873 0.0.0.0:* LISTEN 26885/rsync
2)如何关闭服务,停止:
root@10.6.208.188:/home# ps aux|grep rsync
root 26885 0.0 0.0 3780 940 ? Ss 16:53 0:00 /usr/bin/rsync --daemon
root@10.6.208.188:/home# kill -9 26885
于是:
rsync -rp --bwlimit=3000 --progress --exclude "logs/" /home/elink/ elink@$10.6.208.188:/home/elink/
如需要加上密码,则为elink用户设置一个密码。
passwd elink
重启动这个rsync的服务,
运行命令时会提示输入密码:
实际测试情况如下:
view plainprint?
root@10.6.208.188:~/elink# rsync --bwlimit=3000 --progress --port=873 /root/elink/ elink@10.6.208.188:/home/elink/
elink's password:
skipping directory /root/elink/.
sent 21 bytes received 20 bytes 5.47 bytes/sec
total size is 0 speedup is 0.00
最后,
实际用时可能还会加入Crontab:
每半个小时同步一下
crontab -u root -e
0,30 * * * * 写成一个shell去执行。
可能会出现问题:
view plainprint?
root@darkstar:~# rsync --bwlimit=3000 --progress --port=873 /root/elink/* elink@10.6.208.188:elink
Host key not found from database.
Key fingerprint:
xuror-ledab-buhim-zohok-tanop-cyrig-tysac-gyhyp-refan-semim-pyxex
You can get a public key's fingerprint by running
% ssh-keygen -F publickey.pub
on the keyfile.
warning: tcsetattr failed in ssh_rl_set_tty_modes_for_fd: fd 5: Interrupted system call
加新的参数解决问题:以下参考来自,http://www.justwinit.cn/post/3121/
view plainprint?
root@darkstar:~# strace -o t rsync --bwlimit=3000 --progress --port=873 /root/elink/* elink@10.6.208.188:elink
Host key not found from database.
Key fingerprint:
xuror-ledab-buhim-zohok-tanop-cyrig-tysac-gyhyp-refan-semim-pyxex
You can get a public key's fingerprint by running
% ssh-keygen -F publickey.pub
on the keyfile.
Are you sure you want to continue connecting (yes/no)? yes
Host key saved to /root/.ssh2/hostkeys/key_36000_10.6.208.188.pub
host key for 10.6.208.188, accepted by root Tue Sep 06 2011 20:25:10 +0800
elink's password:
iptables-1.3.1.tar.bz2
180670 100% 10.08MB/s 0:00:00 (1, 100.0% of 1)
sent 180787 bytes received 46 bytes 32878.73 bytes/sec
total size is 180670 speedup is 1.00
http://www.justwinit.cn/post/4604/ |
|