Sersync+rsync实现文件同步Word文档下载推荐.docx

上传人:b****8 文档编号:22454429 上传时间:2023-02-04 格式:DOCX 页数:15 大小:21.87KB
下载 相关 举报
Sersync+rsync实现文件同步Word文档下载推荐.docx_第1页
第1页 / 共15页
Sersync+rsync实现文件同步Word文档下载推荐.docx_第2页
第2页 / 共15页
Sersync+rsync实现文件同步Word文档下载推荐.docx_第3页
第3页 / 共15页
Sersync+rsync实现文件同步Word文档下载推荐.docx_第4页
第4页 / 共15页
Sersync+rsync实现文件同步Word文档下载推荐.docx_第5页
第5页 / 共15页
点击查看更多>>
下载资源
资源描述

Sersync+rsync实现文件同步Word文档下载推荐.docx

《Sersync+rsync实现文件同步Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《Sersync+rsync实现文件同步Word文档下载推荐.docx(15页珍藏版)》请在冰豆网上搜索。

Sersync+rsync实现文件同步Word文档下载推荐.docx

1.#Minimalconfigurationfileforrsyncdaemon

2.#Seersync

(1)andrsyncd.conf(5)manpagesforhelp

3. 

4.#Thislineisrequiredbythe/etc/init.d/rsyncdscript

5.pidfile=/var/run/rsyncd.pid 

 

6.port=873

7.address=192.168.1.171 

8.#uid=nobody

9.#gid=nobody 

10.uid=root 

11.gid=root 

12. 

13.usechroot=yes 

14.readonly=no 

15. 

16. 

17.#limitaccesstoprivateLANs

18.hostsallow=192.168.1.0/255.255.255.010.0.1.0/255.255.255.0 

19.hostsdeny=*

20. 

21.maxconnections=5

22.motdfile=/etc/rsyncd/rsyncd.motd

23. 

24.#Thiswillgiveyouaseparatelogfile

25.logfile=/var/log/rsync.log

26. 

27.#Thiswilllogeveryfiletransferred-upto85,000+peruser,persync

28.#transferlogging=yes

29. 

30.logformat=%t%a%m%f%b

31.timeout=300

32. 

33.[linuxsirhome] 

34.path=/home 

35.list=yes

36.ignoreerrors

37.authusers=linuxsir

38.secretsfile=/etc/rsyncd/rsyncd.secrets 

39.comment=linuxsirhome 

40.exclude= 

beinan/ 

samba/ 

41. 

42.[beinan]

43.path=/opt

44.list=no

45.ignoreerrors

46.comment=optdir 

47.authusers=beinan

48.secretsfile=/etc/rsyncd/rsyncd.secrets

密码文件:

/etc/rsyncd/rsyncd.secrets的内容格式;

1.用户名:

密码

2.linuxsir:

222222

3.beinan:

333333

linuxsir是系统用户,这里的密码值得注意,为了安全,你不能把系统用户的密码写在这里。

比如你的系统用户linuxsir密码是abcdefg,为了安全,你可以让rsync中的linuxsir为222222。

rsyncd.motd文件;

它是定义rysnc服务器信息的,也就是用户登录信息。

比如让用户知道这个服务器是谁提供的等;

类似ftp服务器登录时,我们所看到的linuxsir.orgftp……。

当然这在全局定义变量时,并不是必须的,你可以用#号注掉,或删除;

我在这里写了一个rsyncd.motd的内容为:

1.+++++++++++++++++++++++++++

2.+linuxsir.org 

rsync 

2002-2007+

3.+++++++++++++++++++++++++++

rsyncd.conf文件代码说明

1.pidfile=/var/run/rsyncd.pid

告诉进程写到/var/run/rsyncd.pid文件中;

1.port=873

指定运行端口,默认是873,您可以自己指定;

1.address=192.168.1.171

指定服务器IP地址;

1.uid=nobody

2.gid=nobdoy

服务器端传输文件时,要发哪个用户和用户组来执行,默认是nobody。

如果用nobody用户和用户组,可能遇到权限问题,有些文件从服务器上拉不下来。

所以我就偷懒,为了方便,用了root。

不过您可以在定义要同步的目录时定义的模块中指定用户来解决权限的问题。

1.usechroot=yes

用chroot,在传输文件之前,服务器守护程序在将chroot到文件系统中的目录中,这样做的好处是可能保护系统被安装漏洞侵袭的可能。

缺点是需要超级用户权限。

另外对符号链接文件,将会排除在外。

也就是说,你在rsync服务器上,如果有符号链接,你在备份服务器上运行客户端的同步数据时,只会把符号链接名同步下来,并不会同步符号链接的内容;

这个需要自己来尝试;

1.readonly=yes

readonly是只读选择,也就是说,不让客户端上传文件到服务器上。

还有一个writeonly选项,自己尝试是做什么用的吧;

1.#limitaccesstoprivateLANs

2.hostsallow=192.168.1.0/255.255.255.010.0.1.0/255.255.255.0

在您可以指定单个IP,也可以指定整个网段,能提高安全性。

格式是ip与ip之间、ip和网段之间、网段和网段之间要用空格隔开;

1.maxconnections=5

客户端最多连接数;

1.motdfile=/etc/rsyncd/rsyncd.motd

motdfile是定义服务器信息的,要自己写rsyncd.motd文件内容。

当用户登录时会看到这个信息。

1.logfile=/var/log/rsync.log

rsync服务器的日志;

1.transferlogging=yes

这是传输文件的日志;

1.[linuxsirhome]

模块,它为我们提供了一个链接的名字,链接到哪呢,在本模块中,链接到了/home目录;

要用[name]形式;

1.path=/home

指定文件目录所在位置,这是必须指定的;

1.authusers=linuxsir

认证用户是linuxsir,是必须在服务器上存在的用户;

1.list=yes

list意思是把rsync服务器上提供同步数据的目录在服务器上模块是否显示列出来。

默认是yes。

如果你不想列出来,就no;

如果是no是比较安全的,至少别人不知道你的服务器上提供了哪些目录。

你自己知道就行了;

1.ignoreerrors

忽略IO错误,详细的请查文档;

1.secretsfile=/etc/rsyncd/rsyncd.secrets

密码存在哪个文件;

1.comment=linuxsirhome 

data

注释可以自己定义,写什么都行,写点相关的内容就行;

1.exclude= 

samba/

exclude是排除的意思,也就是说,要把/home目录下的beinan和samba排除在外;

beinan/和samba/目录之间有空格分开;

启动rsync服务器及防火墙的设置

启动rsync服务器

启动rsync服务器相当简单,–daemon是让rsync以服务器模式运行;

1./usr/bin/rsync--daemon 

--config=/etc/rsyncd/rsyncd.conf

rsync服务器和防火墙

Linux防火墙是用iptables,所以我们至少在服务器端要让你所定义的rsync服务器端口通过,客户端上也应该让通过。

1.iptables-AINPUT-ptcp-mstate--stateNEW 

-mtcp--dport873-jACCEPT

查看一下防火墙是不是打开了873端口;

1.iptables-L

通过rsync客户端来同步数据

1.rsync-avzPlinuxsir@linuxsir.org:

:

linuxsirhome 

linuxsirhome

Password:

这里要输入linuxsir的密码,是服务器端提供的,在前面的例子中,我们用的是222222,输入的密码并不显示出来;

输好后就回车;

这个命令的意思就是说,用linuxsir用户登录到服务器上,把linuxsirhome数据,同步到本地目录linuxsirhome上。

当然本地的目录是可以你自己定义的,比如linuxsir也是可以的;

当你在客户端上,当前操作的目录下没有linuxsirhome这个目录时,系统会自动为你创建一个;

当存在linuxsirhome这个目录中,你要注意它的写权限。

说明:

-a参数,归档模式,表示以递归方式传输文件,并保持所有文件属性,相当于-rlptgoD,-r是递归-l是链接文件,意思是拷贝链接文件;

-p表示保持文件原有权限;

-t保持文件原有时间;

-g保持文件原有用户组;

-o保持文件原有属主;

-D相当于块设备文件;

-z传输时压缩;

-P传输进度;

-v传输时的进度等信息,和-P有点关系,自己试试。

可以看文档;

1.rsync-avzP 

--deletelinuxsir@linuxsir.org:

这回我们引入一个–delete选项,表示客户端上的数据要与服务器端完全一致,如果linuxsirhome目录中有服务器上不存在的文件,则删除。

最终目的是让linuxsirhome目录上的数据完全与服务器上保持一致;

用的时候要小心点,最好不要把已经有重要数据的目录,当做本地更新目录,否则会把你的数据全部删除;

--delete 

--password-file=rsync.password 

linuxsir@linuxsir.org:

这次我们加了一个选项–password-file=rsync.password,这是当我们以linuxsir用户登录rsync服务器同步数据时,密码将读取rsync.password这个文件。

这个文件内容只是linuxsir用户的密码。

我们要如下做;

1.touchrsync.password

2.chmod600rsync.password

3.echo"

222222"

>

rsync.password

4.rsync-avzP 

这样就不需要密码了;

其实这是比较重要的,因为服务器通过crond计划任务还是有必要的;

让rsync客户端自动与服务器同步数据

编辑crontab

crontab-e

加入如下代码:

1.100***rsync-avzP 

 

sersync的介绍

sersync主要用于服务器同步,web镜像等功能。

基于boost1.43.0,inotifyapi,rsynccommand.开发。

目前使用的比较多的同步解决方案是inotify-tools+rsync,另外一个是google开源项目Openduckbill(依赖于inotify-tools),这两个都是基于脚本语言编写的。

相比较上面两个项目,本项目优点是:

sersync是使用c++编写,而且对linux系统文件系统产生的临时文件和重复的文件操作进行过滤(详细见附录,这个过滤脚本程序没有实现),所以在结合rsync同步的时候,节省了运行时耗和网络资源。

因此更快。

摘自:

sersync原理

使用Linux2.6内核的inotify监控Linux文件系统事件,被监听目录下如果有文件发生修改,sersync将通过内核自动捕获到事件,并将该文件利用rsync同步到多台远程服务器。

sersync仅仅同步发生增、删、改事件的单个文件或目录,不像rsync镜像同步那样需要比对双方服务器整个目录下数千万的文件,并且支持多线程同步,因此效率非常高。

安装sersync

到这里HatLinux为例讲解。

1.wget

2.mkdir/usr/sersync

3.tarxzfsersync2.5_32bit_binary_stable_final.tar.gz-C/usr/sersync/

就这样,sersync安装完成,下面介绍如何配置及使用。

配置sersync

sersync的配置文件在/usr/sersync/confxml.xml。

首先创建连接rsyncd的密码文件:

1.echo"

123456"

>

/usr/sersync/rsync.pas

2.chmod600/usr/sersync/rsync.pas

下面是confxml.xml文件的一些配置解释:

1.<

?

xmlversion=”1.0″encoding=”ISO-8859-1″?

2.<

headversion=”2.5″>

3.<

hosthostip=”localhost”port=”8008″>

<

/host>

4.<

debugstart=”false”/>

5.<

fileSystemxfs=”false”/>

6.<

filterstart=”true”>

7.<

excludeexpression=”(.*)\.php”>

/exclude>

8.<

excludeexpression=”(.*)\.html”>

9.<

excludeexpression=”(.*)\.htm”>

10.<

excludeexpression=”^tmp/*”>

11.<

!

—监控事件的过程中过滤特定文件,和特定文件夹的文件–>

12.<

/filter>

13.<

inotify>

14.<

deletestart=”true”/>

15.<

createFolderstart=”true”/>

16.<

createFilestart=”true”/>

17.<

closeWritestart=”true”/>

18.<

moveFromstart=”true”/>

19.<

moveTostart=”true”/>

20.<

attribstart=”false”/>

21.<

modifystart=”true”/>

22.<

—设置要监控的事件–>

23.<

/inotify>

24. 

25.<

sersync>

26.<

localpathwatch=”/var/www”>

27.<

—设置要监控的目录–>

28.<

remoteip=”xx.xx.xx.xx”name=”pppei”/>

29.<

—指定远端rsync服务器的地址和模块名–>

30.<

/localpath>

31.<

rsync>

32.<

commonParamsparams=”-artuz”/>

33.<

authstart=”true”users=”pppei”passwordfile=”/usr/sersync/rsync.pas”/>

34.<

—是否启用验证,并指定密码存放文件–>

35.<

userDefinedPortstart=”false”port=”874″/>

–port=874–>

36.<

timeoutstart=”false”time=”100″/>

–timeout=100–>

37.<

sshstart=”false”/>

38.<

/rsync>

39.<

failLogpath=”/tmp/rsync_fail_log.sh”timeToExecute=”60″/>

–defaultevery60minsexecuteonce–>

40.<

crontabstart=”true”schedule=”1440″>

–600mins–>

41.<

—是否启用执行完整rsync,并指定执行周期–>

42.<

crontabfilterstart=”true”>

43.<

—设置完整执行rsync时的过滤条件–>

44.<

excludeexpression=”*.php”>

45.<

excludeexpression=”*.html”>

46.<

excludeexpression=”*.htm”>

47.<

excludeexpression=”tmp/*”>

48.<

/crontabfilter>

49.<

/crontab>

50.<

pluginstart=”false”name=”command”/>

51.<

/sersync>

52. 

53.<

pluginname=”command”>

54.<

paramprefix=”/bin/sh”suffix=”"

ignoreError=”true”/>

<

–prefix/opt/tongbu/mmm.shsuffix–>

55.<

filterstart=”false”>

56.<

includeexpression=”(.*)\.php”/>

57.<

includeexpression=”(.*)\.sh”/>

58.<

59.<

/plugin>

60. 

61.<

pluginname=”socket”>

62.<

localpathwatch=”/opt/tongbu”>

63.<

deshostip=”192.168.138.20″port=”8009″/>

64.<

65.<

66.<

pluginname=”refreshCDN”>

67.<

localpathwatch=”/data0/htdocs/

68.<

cdninfodomainname=””port=”80″username=”xxxx”passwd=”xxxx”/>

69.<

sendurlbase=”

70.<

regexurlregex=”false”match=”

71.<

72.<

73.<

/head>

请根据自己的具体情况修改。

sersync2命令使用说明

1.在主服务器上开启sersync守护进程,使sersync在后台运行,开启实时同步。

./sersync-d

过程如下:

1.[root@localhostGNU-Linux-x86

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 自然科学 > 数学

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1