
rsync+sersync 安装配置(centos_7)
目前业内比较靠谱的同步解决方案有:
rsync+inotify-tools,Openduckbill+inotify-tools和rsync+sersync
前两者由于是基于脚本语言编写,所以规范程度,执行效率相对rsync+sersync就稍微弱一些。
sersync是使用c++编写,基于boost1.43.0,inotify api,rsync command开发,主要用于服务器同步,web镜像等功能。其对linux系统文件系统产生的临时文件和重复的文件操作能够进行过滤,所以在结合rsync同步的时候,节省了运行时耗和网络资源。因此更快,更适合线上使用。
操作系统 Centos7.2
#安装配置接收端(192.168.6.118)
安装 rsync
编辑rsync配置文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
uid = root gid = root use chroot = no max connections = 10 strict modes = yes port = 873 address = 192.168.20.118 [wuguiyunwei] path = /data comment = wuguiyunwei test ignore errors read only = no list = no hosts allow = 192.168.20.117 pid file = /var/run/rsyncd.pid lock file = /var/run/rsync.lock log file = /var/log/rsyncd.log |
保存退出
废话不多说 直接看命令,rsync进程已成启动
1 |
[root@wuguiyunwei02 ~]# mkdir /data && /usr/bin/rsync --daemon --config=/etc/rsyncd.conf && echo "/usr/bin/rsync --daemon --config=/etc/rsyncd.conf" && ps aux | grep rsync rsyn |
接下来配置 sersync(推送端)192.168.20.117
下载 sersynv(需要用到rsync)
1 2 3 |
[root@wuguiyunwei01 src]# yum -y install rsync wget [root@wuguiyunwei01 src]# wget http://source.goyun.org:8000/source/sersync/sersync_64bit_binary_stable_final.tar.gz |
创建目录结构并且把包解压
1 |
[root@wuguiyunwei01 src]# mkdir /usr/local/sersync /usr/local/sersync/conf /usr/local/sersync/bin /usr/local/sersync/log && tar zxf sersync_64bit_binary_stable_final.tar.gz |
接下来配置 sersync
修改如下截图
创建测试目录
# mkdir /web
启动 sersync
/usr/local/sersync/bin/sersync2 -r -d -o /usr/local/sersync/conf/confxml.xml
杀掉进程重新启动
pkill sersync2 && /usr/local/sersync/bin/sersync2 -r -d -o /usr/local/sersync/conf/confxml.xml
设置开机启动
echo “/usr/local/sersync/bin/sersync2 -r -d -o /usr/local/sersync/conf/confxml.xml” > /etc/rc.local
测试 (注意防火墙和selinux)
到推送端创建文件和目录
到接收端查看
配置文件解释
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 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
<?xml version="1.0" encoding="ISO-8859-1"?> <head version="2.5"> # 设置本地IP和端口 <host hostip="localhost" port="8008"></host> # 开启DUBUG模式 <debug start="false"/> # 开启xfs文件系统 <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="true"/> <closeWrite start="true"/> <moveFrom start="true"/> <moveTo start="true"/> <attrib start="true"/> <modify start="true"/> </inotify> <sersync> # 本地同步的目录路径 <localpath watch="/web"> # 远程IP和rsync模块名 <remote ip="192.168.20.118" name="wuguiyunwei"/> <!--<remote ip="192.168.8.39" name="tongbu"/>--> <!--<remote ip="192.168.8.40" name="tongbu"/>--> </localpath> <rsync> # rsync指令参数 <commonParams params="-auvzP"/> # rsync同步认证 <auth start="true" users="user" passwordfile="/etc/rsync.pas"/> # 设置rsync远程服务端口,远程非默认端口则需打开自定义 <userDefinedPort start="false" port="874"/><!-- port=874 --> # 设置超时时间 <timeout start="true" time="100"/><!-- timeout=100 --> # 设置rsync+ssh加密传输模式,默认关闭,开启需设置SSH加密证书 <ssh start="false"/> </rsync> # sersync传输失败日志脚本路径,每隔60会重新执行该脚本,执行完毕会自动清空。 <failLog path="/usr/local/sersync/log/rsync_fail_log.sh" timeToExecute="60"/><!--default every 60mins execute once--> # 设置rsync+crontab定时传输,默认关闭 <crontab start="false" schedule="600"><!--600mins--> <crontabfilter start="false"> <exclude expression="*.php"></exclude> <exclude expression="info/*"></exclude> </crontabfilter> </crontab> # 设置sersync传输后调用name指定的插件脚本,默认关闭 <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="/opt/tongbu"> <deshost ip="192.168.138.20" 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> |