Sersync+Rsync互相实时同步

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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
1、关闭selinux
2、防火墙(iptables、Firewalld)放行873端口(默认)
3、安装Rsync服务
yum install rsync -y
useradd -r -s /sbin/nologin rsync -M
cat > /etc/rsyncd.conf <<EOF
uid = rsync
gid = rsync
use chroot = no
port = 873
address = 192.168.230.10
max connections = 2000
timeout = 200
log file = /var/run/rsyncd.log
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsyncd.lock
log format = %t %a %m %f %b

[rsync]
path = /home/wwwroot/test/
commemt = rsync
list = yes
read only = no
#write only = no
auth users = homeuser
secrets file = /etc/rsyncd.secret
ignore errors = yes
hosts allow = 192.168.250.101
hosts deny =
EOF
read only 指定是否允许客户上传文件。若为 true 则不允许上传;若为 false 并且服务器目录也具有读写权限则允许上传。 true
write only 指定是否允许客户下载文件。若为 true 则不允许下载;若为 false 并且服务器目录也具有读权限则允许下载。 false

read only 默认值true 不允许上传,只能读;false 可写(可上传),是否可读取决于write only
write only 默认值false 可读而且可下载;true 不允许下载,是否可写取决于read only

cat > /etc/rsyncd.secret <<EOF
homeuser:test123
EOF
chmod 600 /etc/rsyncd.secret

cat > /etc/rsyncd.pass <<EOF
test123
EOF
chmod 600 /etc/rsyncd.pass

mkdir -p /home/wwwroot/test
chown rsync.rsync -R /home/wwwroot/test
systemctl enable rsyncd
systemctl start rsyncd

4、安装Sersync服务
wget http://panel.ropon.top/rsync/sersync.zip
unzip sersync.zip -C /usr/local/
tar xf sersync.zip -C /usr/local/
cat //usr/local/sersync/config.xml

<?xml version="1.0" encoding="ISO-8859-1"?>
<head version="2.5">
<host hostip="localhost" port="8008"></host>
<debug start="false"/>
<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/wwwroot/test">
<remote ip="192.168.250.101" name="rsync"/>
<!--<remote ip="192.168.8.39" name="tongbu"/>-->
<!--<remote ip="192.168.8.40" name="tongbu"/>-->
</localpath>
<rsync>
<commonParams params="-artuz"/>
<auth start="true" users="homeuser" passwordfile="/etc/rsyncd.pass"/>
<userDefinedPort start="false" port="873"/><!-- port=874 -->
<timeout start="false" time="100"/><!-- timeout=100 -->
<ssh start="false"/>
</rsync>
<failLog path="/tmp/rsync_fail_log.sh" timeToExecute="60"/><!--default every 60mins execute once-->
<crontab start="false" schedule="600"><!--600mins-->
<crontabfilter start="false">
<exclude expression="*.php"></exclude>
<exclude expression="info/*"></exclude>
</crontabfilter>
</crontab>
<plugin start="false" name="command"/>
</sersync>

<plugin name="command">
<param prefix="/bin/sh" suffix="" ignoreError="true"/> <!--prefix /opt/tongbu/mmm.sh suffix-->
<filter start="false">
<include expression="(.*)\.php"/>
<include expression="(.*)\.sh"/>
</filter>
</plugin>

<plugin name="socket">
<localpath watch="/home/wwwroot/test/">
<deshost ip="192.168.250.101" port="8009"/>
</localpath>
</plugin>
<plugin name="refreshCDN">
<localpath watch="/data0/htdocs/cms.xoyo.com/site/">
<cdninfo domainname="ccms.chinacache.com" port="80" username="xxxx" passwd="xxxx"/>
<sendurl base="http://pic.xoyo.com/cms"/>
<regexurl regex="false" match="cms.xoyo.com/site([/a-zA-Z0-9]*).xoyo.com/images"/>
</localpath>
</plugin>
</head>

cat /etc/rc.local
/usr/local/sersync/sersync2 -d -r -o /usr/local/sersync/confxml.xml

B服务器同理
注意开机启动项
cd /home/wwwroot/test && rsync -artuz -R --delete homeuser@192.168.230.10::rsync ./ --password-file=/etc/rsyncd.pass
/usr/local/sersync/sersync2 -d -r -o /usr/local/sersync/confxml.xml