centos7 sersync 4台服务器数据互相同步配置
4台服务器安装rsync并配置
#安装 yum install rsync -y #配置 vim /etc/rsyncd.conf uid = root gid = root use chroot = no hosts allow=* max connections = 3 pid file = /var/run/rsyncd.pid lock file = /var/run/rsync.lock [record] path = /record/ comment = record read only = false #密码配置文件 vim /etc/rsync.password root:qwer!@#123 systemctl restart rsyncd systemctl enable rsyncd
4台服务器安装sersync
1 2 3 4 5 6 7 8 9 10 | #安装 wget https: //storage .googleapis.com /google-code-archive-downloads/v2/code .google.com /sersync/sersync2 .5.4_64bit_binary_stable_final. tar .gz tar -zxvf sersync2.5.4_64bit_binary_stable_final. tar .gz mv GNU-Linux-x86 /usr/local/sersync cd /usr/local/sersync cp confxml.xml confxml.xml-bak vim confxml.xml #注意修改有"#"注释的地方修改,修改完去掉#注释xml不是这种注释 |
<?xml version="1.0" encoding="ISO-8859-1"?> <head version="2.5"> <host hostip="pbx-master" port="8008"></host> <debug start="false"/> <fileSystem xfs="true"/> #支持xfs <filter start="false"> <exclude expression="(.*)\.svn"></exclude> <exclude expression="(.*)\.gz"></exclude> <exclude expression="^info/*"></exclude> <exclude expression="^static/*"></exclude> </filter> <inotify> <delete start="false"/> #flase 表示只增加不删除文件 <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="/record/"> #同步路径 <remote ip="pbx-slave" name="record"/> #name="record" 这个表示模块名 <remote ip="pbx2-master" name="record"/> <remote ip="pbx2-slave" name="record"/> <!--<remote ip="192.168.8.39" name="tongbu"/>--> <!--<remote ip="192.168.8.40" name="tongbu"/>--> </localpath> <rsync> <commonParams params="-artuz"/> #这里表示rsync的参数 <auth start="true" users="root" passwordfile="/etc/rsync.passowrd"/> #校验密码配置需要为true <userDefinedPort start="false" port="874"/><!-- 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--> #修改同步失败日志位置,并且每60分钟对失败的log进行重新同步 <crontab start="true" 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="/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>
#手动启动的命令 /usr/local/sersync/sersync2 -dro /usr/local/sersync/confxml.xml -n 2 #-n 2 cpu限制2核
1 2 | #systemctl 管理 vim /usr/lib/systemd/system/sersync .service |
1 2 3 4 5 6 7 8 9 10 11 | [Unit] Description=named start stop After=syslog.target network.target [Service] ExecStart= /usr/local/sersync/sersync2 -ro /usr/local/sersync/confxml .xml -n 2 ExecStop= /bin/kill -s TERM $MAINPID Restart=always #异常关闭尝试启动 [Install] WantedBy=multi-user.target |
1 2 | systemctl restart sersync systemctl enable sersync |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现