实现功能:当用户在本地客户端某目录内建立、修改、删除目录或文件、修改目录或文件的属性,只要执行相同的shell脚本,rsync就会自动找出有改动或删除的数据,将其传送到服务器上,使服务器端某目录内的数据跟本地客户端某目录内的数据保持一致。

  ★方式一:

  一、服务器端(例:10.0.0.1*):
  1、创建用户和组

groupadd www -g 48
useradd -u 48 -g www www
mkdir -p /opt/htdocs
chmod +w /opt/htdocs
chown www:www /opt/htdocs


  2、编辑rsync的配置文件
vi /etc/rsyncd.conf

  输入以下内容:
引用
uid=www
gid=www
max connections=10
use chroot=no
log file=/var/log/rsyncd.log
pid file=/var/run/rsyncd.pid
lock file=/var/run/rsyncd.lock

[zhangyan]
path=/opt/htdocs
comment = my htdocs
ignore errors
read only = no
hosts allow=10.0.0.21 10.0.0.22


  3、启动rsync服务器端
/usr/bin/rsync --daemon


  二、客户端(例:10.0.0.21和10.0.0.22):
  1、创建一个shell脚本push.sh
vi push.sh

  输入以下内容(10.0.0.1*为要推送到的目标服务器,zhangyan为服务器端rsyncd.conf配置文件中的模块名):
引用
#!/bin/sh
/usr/bin/rsync -vzrtopg --delete $1 10.0.0.10::zhangyan/
/usr/bin/rsync -vzrtopg --delete $1 10.0.0.11::zhangyan/
/usr/bin/rsync -vzrtopg --delete $1 10.0.0.16::zhangyan/
/usr/bin/rsync -vzrtopg --delete $1 10.0.0.19::zhangyan/
  注:因为是内部局域网之间传输,这里没有设置密码。

  2、赋予push.sh执行权限
chmod +x ./push.sh


  3、同步推送客户端某个目录中(例:/home/zhanguan/abc)的文件到服务器端的/opt/htdocs目录:
./push.sh /home/zhanguan/abc/

  注意:不要忘了abc后面的/。如果更改的文件太大,可以在上面语句的末尾加上空格和&号,推到后台执行。例:
./push.sh /home/zhanguan/abc/ &



  ★方式二:

  一、服务器端(例:10.0.0.1*):
  1、创建用户和组
groupadd www -g 48
useradd -u 48 -g www www
mkdir -p /opt/htdocs
chmod +w /opt/htdocs
chown www:www /opt/htdocs
passwd www
  为www用户设置一个密码。

  二、客户端:
  1、同步推送客户端某个目录中(例:/home/zhanguan/abc)的文件到服务器端的/opt/htdocs目录:
/usr/bin/rsync -vzrtopg --delete /home/zhanguan/abc/ -e ssh www@10.0.0.10:/opt/htdocs/
  输入密码,回车即可,无须服务器端启动rsync服务。




技术大类 » 其他Unix技术 | 评论(36) | 引用(0) | 阅读(50848)
coach88888888 Email
2012-8-13 17:30
Coach Factory Outlet offer excellent, elegant coach products in order to generate room for your new collections.They're purchased more quickly that you may at any time imagine.Most significantly, the coach designer purses of Coach Factory Online industry won't deteriorate your individual fashions at all. Rather they would immediately change your overall looks marvelously.I find it all very odd But this is no different than Coach Outlet Online any other company that has an outlet presence and really doesn’Coach Outlet Store t explain it to the customer.By the fashion, novel appearance, sophisticated technology, superior quality, Coach Outlet won domestic and international customers, their products exported to the Middle East, Southeast Asia and other regions.
run Email Homepage
2013-5-30 16:44
不错挺有感触!
Ted Homepage
2014-7-25 10:52
支持楼主 www.vcdiy.com
大胡子的博客 Homepage
2015-1-9 17:29
大胡子的博客学些大牛的分享,强烈谢谢http://www.dahuzhi.com
Mann123 Email
2021-6-13 17:43
This is an awesome post for the user who wants to download free solutions of class 9th Mathematics NCERT book. class 9 ncert solutions maths
shz Email
2022-7-1 15:35
Very interesting blog. Alot of blogs I see these days don't really provide anything that I'm interested in, but I'm most definately interested in this one. Just thought that I would post and let you know.  Lead generation
shz Email
2022-7-1 15:41
Your blog provided us with valuable information to work with. Each & every tips of your post are awesome. Thanks a lot for sharing. Keep blogging,  Lead generation
shz Email
2022-7-1 15:46
Mmm.. good to be here in your article or post, whatever, I think I should also work hard for my own website like I see some good and updated working in your site.  Lead generation
shz Email
2022-7-1 15:53
Cool stuff you have and you keep overhaul every one of us  Lead generation
shz Email
2022-7-1 15:58
Gangaur Realtech is a professionally managed organisation specializing in real estate services where integrated services are provided by professionals to its clients seeking increased value by owning, occupying or investing in real estate.  Lead generation
shz Email
2022-7-1 16:11
With so many books and articles coming up to give gateway to make-money-online field and confusing reader even more on the actual way of earning money,  Lead generation
shz Email
2022-7-1 16:20
I’m excited to uncover this page. I need to to thank you for ones time for this particularly fantastic read !! I definitely really liked every part of it and i also have you saved to fav to look at new information in your site.  Lead generation
mari Email
2023-7-6 16:27
I appreciate you sharing this blog. For individuals who are looking for pertinent information, this is a huge aid. slope
JACK Email
2024-3-29 22:01
Protect your cryp口浏览,tocurrency and securely manage your digital assets with the Metamask wallet extension. Download now for secure and convenient transactions.Metamask wallet extension | Metamask wallet extension
分页: 2/2 第一页 上页 1 2 最后页
发表评论
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   游客无需密码
网址   电邮   [注册]