sersync+rsync做实时同步
(1).实验环境
源主机:youxi1 192.168.5.101
目的主机:youxi2 192.168.5.102
目的:实时同步数据
sersync默认端口874,rsync默认端口873
(2).实验
1)下载sersync
wegt https://sersync.googlecode.com/files/sersync2.5.4_64bit_binary_stable_final.tar.gz
或者Windows下载再上传源主机youxi1。
2)解压
1 2 3 4 5 6 7 8 9 10 11 | [root@youxi1 ~]# ls anaconda-ks.cfg sersync2.5.4_64bit_binary_stable_final.tar.gz [root@youxi1 ~]# tar xvf sersync2.5.4_64bit_binary_stable_final.tar.gz //解压 GNU-Linux-x86/ GNU-Linux-x86/sersync2 GNU-Linux-x86/confxml.xml [root@youxi1 ~]# ls anaconda-ks.cfg GNU-Linux-x86 sersync2.5.4_64bit_binary_stable_final.tar.gz [root@youxi1 ~]# mv GNU-Linux-x86 sersync 改名 [root@youxi1 ~]# ls anaconda-ks.cfg sersync sersync2.5.4_64bit_binary_stable_final.tar.gz |
3)在目标主机youxi2上修改/etc/rsyncd.conf配置文件,以及密码文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | [root@youxi2 ~]# cat /etc/rsyncd.conf uid = root gid = root address = 192.168.5.102 port = 873 hosts allow = 192.168.5.101/24 use chroot = yes max connections = 5 pid file = / var /run/rsyncd.pid lock file = / var /run/rsync. lock log file = / var /log/rsyncd.log motd file = /etc/rsyncd.motd [backupwwwhtml] path = /backup/www/html comment = backup /www/html/ read only = false list = yes auth users = rsync2 secrets file = /etc/rsync.passwd [root@youxi2 ~]# cat /etc/rsync.passwd rsync2:102102 [root@youxi2 ~]# chmod 600 /etc/rsync.passwd |
启动指定配置文件的rsync的守护进程
1 2 3 4 | [root@youxi2 ~]# rsync --daemon --config=/etc/rsyncd.conf [root@youxi2 ~]# ps aux | grep rsync root 1478 0.0 0.0 114740 564 ? Ss 11:10 0:00 rsync --daemon --config=/etc/rsyncd.conf root 1485 0.0 0.0 112720 980 pts/0 R+ 11:12 0:00 grep --color=auto rsync |
4)源主机youxi1上修改sersync的配置文件
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 | [root@youxi1 sersync]# vim confxml.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> <createFile start= "false" /> <closeWrite start= "true" /> <moveFrom start= "true" /> <moveTo start= "true" /> <attrib start= "false" /> <modify start= "false" /> </inotify> <sersync> <localpath watch= "/www/html" > <remote ip= "192.168.5.102" name= "backupwwwhtml" /> //修改为目标主机IP地址和模块名 </localpath> <rsync> <commonParams params = "-artuz" /> <auth start= "true" users= "rsync2" passwordfile= "/etc/rsync.passwd" /> //开启,修改用户名和密码文件地址 <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 e very 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> |
添加密码文件
1 2 3 | [root@youxi1 sersync]# vim /etc/rsync.passwd 102102 [root@youxi1 html]# chmod 600 /etc/rsync.passwd |
5)开启源主机youxi1的sersync的守护进程
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 | [root@youxi1 sersync]# /root/sersync/sersync2 -dro /root/sersync/confxml.xml set the system param execute:echo 50000000 > /proc/sys/fs/inotify/max_user_watches execute:echo 327679 > /proc/sys/fs/inotify/max_queued_events parse the command param option: -d run as a daemon option: -r rsync all the local files to the remote servers before the sersync work option: -o config xml name: /root/sersync/confxml.xml daemon thread num: 10 parse xml config file host ip : localhost host port: 8008 daemon start,sersync run behind the console use rsync password-file : user is rsync2 passwordfile is /etc/rsync.passwd 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 /www/html && rsync -artuz -R --delete ./ rsync2@192.168.5.102::backupwwwhtml --password-file=/etc/rsync.passwd >/dev/ null 2>&1 run the sersync: watch path is : /www/html |
6)测试
现在的目的主机youxi2情况如下
1 2 3 | [root@youxi2 ~]# ls /backup/www/html/ adm crash empty gopher lib lock mail opt run tmp cache db games kerberos local log nis preserve spool yp |
对源主机youxi1的/www/html/目录下文件进行操作
1 2 3 4 5 6 7 8 9 | [root@youxi1 sersync]# cd /www/html/ [root@youxi1 html]# ls adm crash empty gopher lib lock mail opt run tmp cache db games kerberos local log nis preserve spool yp [root@youxi1 html]# rm -rf adm/ [root@youxi1 html]# touch 1.txt [root@youxi1 html]# ls 1.txt crash empty gopher lib lock mail opt run tmp cache db games kerberos local log nis preserve spool yp |
回到目的主机查看情况
1 2 3 | [root@youxi2 ~]# ls /backup/www/html/ 1.txt crash empty gopher lib lock mail opt run tmp cache db games kerberos local log nis preserve spool yp |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· .NET Core 中如何实现缓存的预热?
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 如何调用 DeepSeek 的自然语言处理 API 接口并集成到在线客服系统
· 【译】Visual Studio 中新的强大生产力特性