Linux 文件同步

场景

为了适应更发规模流量的爆发,需要将服务器托管在云台上,也方便日后做物理托管分割,需要将服务器文件做同步

方案

采用Linux下常见的resync做文件同步

实施

演示环境centos 6.3 64bit

源服务器地址:192.168.1.238,目标服务器地址:192.168.1.239

在239上部署resync

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
[root@localhost ~]# rpm -qa | grep rsync
rsync-3.0.6-9.el6.x86_64
已经默认安装了,那么我们来做一下配置
vi /etc/rsyncd.conf
uid=root
gid=root
max connections=36000
use chroot=no
log file=/var/log/rsyncd.log
pid file=/var/run/rsyncd.pid
lock file=/var/run/rsyncd.lock
 
[tongbu]
path=/home/data
comment  = media video files
ignore errors = yes
read only = no
hosts allow =  192.168.1.238
hosts deny = *
 
配置完成,启动 
rsync --daemon
ps -ef | grep rsync
root      1304     1  0 14:36 ?        00:00:00 rsync --daemon
root      1307  1286  0 14:36 pts/0    00:00:00 grep rsync

简要说明 :

path为你要同步的文件目录,host allow为允许连接的IP,host deny 为拒绝的IP

这时候我们开始着手238的配置,选取工具 sersync (自行Google补脑)

文件:sersync2  和  confxml.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
 
<?xml version="1.0" encoding="ISO-8859-1"?>
<head version="2.5">
    <host hostip="localhost" port="8008"></host>
    <debug start="true"/>
    <fileSystem xfs="false"/>
    <filter start="false">
	<exclude expression="(.*)\.svn"></exclude>
	<exclude expression="(.*)\.gz"></exclude>
	<exclude expression="^info/*"></exclude>
	<exclude expression="^static/*"></exclude>
    </filter>
    <inotify>
	<delete start="true"/>
	<createFolder start="true"/>
	<createFile start="false"/>
	<closeWrite start="true"/>
	<moveFrom start="true"/>
	<moveTo start="true"/>
	<attrib start="false"/>
	<modify start="false"/>
    </inotify>
 
    <sersync>
	<localpath watch="/home/data">
	    <remote ip="192.168.1.239" name="tongbu"/>
	</localpath>
	<rsync>
	    <commonParams params="-artuz"/>
	    <auth start="false" users="root" passwordfile="/etc/rsync.pas"/>
	    <userDefinedPort start="false" port="874"/>
	    <timeout start="false" time="100"/>
	    <ssh start="false"/>
	</rsync>
	<failLog path="/tmp/rsync_fail_log.sh" timeToExecute="60"/>
	<crontab start="false" schedule="600">
	    <crontabfilter start="false">
		<exclude expression="*.php"></exclude>
		<exclude expression="info/*"></exclude>
	    </crontabfilter>
	</crontab>
	<plugin start="false" name=""/>
    </sersync>
</head>
 
./sersync2 -r -d
set the system param
execute:echo 50000000 &gt; /proc/sys/fs/inotify/max_user_watches
execute:echo 327679 &gt; /proc/sys/fs/inotify/max_queued_events
parse the command param
option: -r rsync all the local files to the remote servers before the sersync work
option: -d run as a daemon
daemon thread num: 10
parse xml config file
host ip : localhost host port: 8008
Open debug, you will see debug infomation
daemon start,sersync run behind the console
config xml parse success
please set /etc/rsyncd.conf max connections=0 Manually
sersync working thread 12 = 1(primary thread) + 1(fail retry thread) + 10(daemon sub threads)
Max threads numbers is: 22 = 12(Thread pool nums) + 10(Sub threads)
please according your cpu ,use -n param to adjust the cpu rate
------------------------------------------
rsync the directory recursivly to the remote servers once
working please wait...
execute command: cd /home/data &amp;&amp; rsync -artuz -R --delete ./ 192.168.1.239::tongbu
crontab command:cd /home/data &amp;&amp; rsync -artuz -R --delete ./ 192.168.1.239::tongbu
run the sersync:
watch path is: /home/data
add watch: /home/data return wd is: 1

发表评论

电子邮件地址不会被公开。 必填项已用*标注